From: Ian Jackson Date: Thu, 8 Jul 2021 20:03:34 +0000 (+0100) Subject: jat-lower: wip X-Git-Tag: otter-0.7.2~224 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=cfbf46d3dfebabc62971e186fe07368e9ce52613;p=otter.git jat-lower: wip Signed-off-by: Ian Jackson --- diff --git a/Cargo.lock b/Cargo.lock index 8797f75a..a22ed55a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2565,6 +2565,7 @@ name = "otter-nodejs-tests" version = "0.7.1" dependencies = [ "fehler", + "indexmap", "otter", "structopt", ] diff --git a/jstest/Cargo.toml b/jstest/Cargo.toml index b5108850..ef376d6b 100644 --- a/jstest/Cargo.toml +++ b/jstest/Cargo.toml @@ -29,6 +29,8 @@ path="jst-lower.rs" otter.path=".." otter.version="=0.7.1" +indexmap = "1.6" + fehler="1" structopt="0.3" diff --git a/jstest/jst-lower.rs b/jstest/jst-lower.rs index 0a688acf..a75b594a 100644 --- a/jstest/jst-lower.rs +++ b/jstest/jst-lower.rs @@ -4,15 +4,66 @@ use otter_nodejs_tests::*; -#[derive(StructOpt)] -struct Opts { +#[derive(StructOpt,Debug,Clone)] +pub struct Opts { pub nodejs: String, pub script: String, } +#[derive(Debug,Clone)] +pub struct StartPieceSpec { + id: &'static str, + pinned: bool, + moveable: PieceMoveable, +} + +#[macro_export] +macro_rules! sp { + { $id:expr, $pinned:expr, $moveable:ident } => { + StartPieceSpec { id: $id, pinned: $pinned, + moveable: PieceMoveable::$moveable } + }; +} + +#[derive(Debug,Clone)] +#[derive(Eq,PartialEq,Ord,PartialOrd)] +pub struct StartPiece { + id: String, + pinned: bool, + moveable: PieceMoveable, + z: ZCoord, +} + +#[derive(Debug,Clone,Default)] +pub struct Tests { + tests: IndexMap>, +} + +impl Tests { + pub fn add_test(&mut self, name: &'static str, pieces: Vec) { + let mut zm = ZCoord::default().clone_mut(); + let pieces = pieces.into_iter().map( + |StartPieceSpec { id, pinned, moveable }| { + let id = id.into(); + let z = zm.increment().unwrap(); + StartPiece { id, pinned, moveable, z } + } + ).collect_vec(); + let already = self.tests.insert(name.to_owned(), pieces); + assert_eq!(already, None); + } +} + #[throws(AE)] fn main() { let opts = Opts::from_args(); + + let mut tests = Tests::default(); + tests.add_test("simple", vec![ + sp!("1.1", false, Yes), + sp!("2.1", false, Yes), + ]); + let mut cmd = Command::new(opts.nodejs); cmd.arg(opts.script); let status = cmd.status()?; diff --git a/jstest/jstest.rs b/jstest/jstest.rs index d1493843..a077b6a1 100644 --- a/jstest/jstest.rs +++ b/jstest/jstest.rs @@ -4,4 +4,5 @@ pub use otter::prelude::*; +pub use indexmap::IndexMap; pub use structopt::StructOpt; diff --git a/jstest/lower.nodejs b/jstest/lower.nodejs index f941330a..1bc56a49 100644 --- a/jstest/lower.nodejs +++ b/jstest/lower.nodejs @@ -19,7 +19,7 @@ function api_piece(op, piece, p, args) { } -jstest_did = fs.openSync("simple.did", 'w'); +jstest_did = fs.openSync("byhand.did", 'w'); pieces = { "1.1": {