chiark / gitweb /
wdt: Provide ActionChainExt::move_pc for convenience
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 30 Jan 2021 01:25:32 +0000 (01:25 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 30 Jan 2021 01:25:52 +0000 (01:25 +0000)
And use it in one place.  NFC.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
wdriver.rs
wdriver/wdt-simple.rs

index ee83233598386eac112fca509fd4ec2fde4f92fc..ba36e26e487fbf8811d52029fa8d5f2ed9c138ce 100644 (file)
@@ -1201,6 +1201,8 @@ pub trait ActionChainExt: Sized {
               P: TryInto<WebPos, Error=E>>
     (self, pos: P) -> Result<Self,AE>
     where Result<WebPos,E>: anyhow::Context<WebPos,E>;
+
+  fn move_pc<'g>(self, w: &'g WindowGuard, pc: &str) -> Result<Self, AE>;
 }
 
 impl<'a> ActionChainExt for t4::action_chain::ActionChain<'a> {
@@ -1225,6 +1227,16 @@ impl<'a> ActionChainExt for t4::action_chain::ActionChain<'a> {
       .context("find coordinate")?;
     self.move_pos(pos)?
   }
+
+  #[throws(AE)]
+  fn move_pc<'g>(self, w: &'g WindowGuard, pc: &str) -> Self {
+    (||{
+      let p = w.find_piece(pc).context("find")?;
+      let pos = p.posw().context("get pos")?;
+      let r = self.move_pos(pos).context("move")?;
+      Ok::<_,AE>(r)
+    })().with_context(|| format!("piece {}", pc))?
+  }
 }
 
 impl Drop for Setup {
index a3d1e533f3de713d6570d86f9f242164d070c6f5..d500409beed5284f5fbfee9e3b3abf5777e284aa 100644 (file)
@@ -167,7 +167,7 @@ impl Ctx {
       let pc = "4.1";
       let w = su.w(&self.alice)?;
       w.action_chain()
-        .move_w(&w, w.find_piece(pc)?.posg()?)?
+        .move_pc(&w, pc)?
         .click();
     }