chiark / gitweb /
apitest: Introduce JsV type
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 13 Mar 2021 15:54:44 +0000 (15:54 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 13 Mar 2021 15:58:13 +0000 (15:58 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
apitest.rs
apitest/at-otter.rs
wdriver.rs

index 0138efc23a21ac9718efe890d99b5d571766abc3..2765c86a684e15e413c5ba6c8b84aedfe8d62213 100644 (file)
@@ -18,6 +18,7 @@ pub use num_traits::NumCast;
 pub use serde_json::json;
 pub use structopt::StructOpt;
 
+pub type JsV = serde_json::Value;
 pub type MC = MgmtCommand;
 
 // -------------------- private imports ----------
index 4c2aefb04ce47f86136c62e61570af341ccc2675..5dad940a363936ebca7c7201b88ed18d375d8579 100644 (file)
@@ -104,7 +104,7 @@ mod scraper_ext {
 
 use scraper_ext::{HtmlExt, RequestBuilderExt};
 
-type Update = serde_json::Value;
+type Update = JsV;
 
 #[throws(AE)]
 fn updates_parser<R:Read>(input: R, out: &mut mpsc::Sender<Update>) {
@@ -207,7 +207,7 @@ struct PieceInfo<I> {
 
 impl Session {
   #[throws(AE)]
-  fn pieces(&self) -> Vec<PieceInfo<serde_json::Value>> {
+  fn pieces(&self) -> Vec<PieceInfo<JsV>> {
     self.dom
       .element("#pieces_marker")
       .unwrap().next_siblings()
@@ -230,7 +230,7 @@ impl Session {
 
   #[throws(AE)]
   fn api_piece_op(&mut self, piece: &str, opname: &str,
-                  op: serde_json::Value) {
+                  op: JsV) {
     self.cseq += 1;
     let cseq = self.cseq;
 
@@ -250,7 +250,7 @@ impl Session {
 
   #[throws(AE)]
   fn api_with_piece_op(&mut self, piece: &str,
-                       pathfrag: &str, op: serde_json::Value) {
+                       pathfrag: &str, op: JsV) {
     self.api_piece_op(piece, "grab", json!({}))?;
     self.api_piece_op(piece, pathfrag, op)?;
     self.api_piece_op(piece, "ungrab", json!({}))?;
@@ -258,7 +258,7 @@ impl Session {
 
   #[throws(AE)]
   fn api_with_piece_op_synch(&mut self, piece: &str,
-                             pathfrag: &str, op: serde_json::Value) {
+                             pathfrag: &str, op: JsV) {
     self.api_piece_op(piece, "grab", json!({}))?;
     self.api_piece_op(piece, pathfrag, op)?;
     self.synch()?;
@@ -268,9 +268,9 @@ impl Session {
   #[throws(AE)]
   fn await_update<
     R,
-    F: FnMut(&mut Session, Generation, &str, &serde_json::Value) -> Option<R>,
+    F: FnMut(&mut Session, Generation, &str, &JsV) -> Option<R>,
     G: FnMut(&mut Session, Generation) -> Option<R>,
-    E: FnMut(&mut Session, Generation, &serde_json::Value)
+    E: FnMut(&mut Session, Generation, &JsV)
              -> Result<Option<R>, AE>
    > (&mut self, mut g: G, mut f: F, mut ef: Option<E>) -> R {
     'overall: loop {
@@ -300,9 +300,9 @@ impl Session {
 
   #[throws(AE)]
   fn synchx<
-    F: FnMut(&mut Session, Generation, &str, &serde_json::Value),
+    F: FnMut(&mut Session, Generation, &str, &JsV),
   > (&mut self,
-     ef: Option<&mut dyn FnMut(&mut Session, Generation, &serde_json::Value)
+     ef: Option<&mut dyn FnMut(&mut Session, Generation, &JsV)
                                -> Result<(), AE>>,
      mut f: F)
   {
index bc838470a975a398d1d6eb2749bc018b1d6a908f..46ea76c0077dac9c067f584db7e15ac1af0bcece 100644 (file)
@@ -162,7 +162,7 @@ fn fetch_log(driver: &T4d, name: &str) {
       .ok_or(anyhow!("saved isn't an array?"))?
     {
       #[derive(Deserialize)]
-      struct LogEnt(String, Vec<serde_json::Value>);
+      struct LogEnt(String, Vec<JsV>);
       impl fmt::Display for LogEnt {
         #[throws(fmt::Error)]
         fn fmt(&self, f: &mut fmt::Formatter) {
@@ -233,8 +233,8 @@ impl<'g> WindowGuard<'g> {
     let held = held.value();
     dbg!(held);
     match held {
-      serde_json::Value::Null => None,
-      serde_json::Value::String(s) => Some(s.to_owned()),
+      JsV::Null => None,
+      JsV::String(s) => Some(s.to_owned()),
       _ => Err(anyhow!("held check script gave {:?}", held))?,
     }
   }