From d00e1468824f5fce3dd720446e2752a3e67277ed Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 9 Jul 2021 12:12:51 +0100 Subject: [PATCH] jstest: lower: Make Test::pieces be an IndexMap Signed-off-by: Ian Jackson --- Cargo.lock | 1 + jstest/Cargo.toml | 2 +- jstest/jst-lower.rs | 17 +++++++++-------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index be9cdf3d..7d267388 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1720,6 +1720,7 @@ checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" dependencies = [ "autocfg 1.0.1", "hashbrown", + "serde", ] [[package]] diff --git a/jstest/Cargo.toml b/jstest/Cargo.toml index d2ea7271..3167a88a 100644 --- a/jstest/Cargo.toml +++ b/jstest/Cargo.toml @@ -32,7 +32,7 @@ otter.version="=0.7.1" otter-api-tests.path="../apitest" otter-api-tests.version="=0.7.1" -indexmap = "1.6" +indexmap = { version = "1.6", features=["serde"] } fehler="1" structopt="0.3" diff --git a/jstest/jst-lower.rs b/jstest/jst-lower.rs index a48a6a0f..46fc8e9d 100644 --- a/jstest/jst-lower.rs +++ b/jstest/jst-lower.rs @@ -44,7 +44,8 @@ pub struct Tests { #[derive(Serialize)] pub struct Test { name: String, - pieces: Vec, + #[serde(with = "indexmap::serde_seq")] + pieces: IndexMap, targets: Vec, } @@ -88,10 +89,10 @@ jstest_did = fs.openSync('{{ name }}.did', 'w'); pieces = { {% for p in pieces -%} - '{{ p.id }}': { - pinned: {{ p.pinned }}, - moveable: '{{ p.moveable }}', - z: '{{ p.z }}', + '{{ p.0 }}': { + pinned: {{ p.1.pinned }}, + moveable: '{{ p.1.moveable }}', + z: '{{ p.1.z }}', }, {% endfor -%} } @@ -99,7 +100,7 @@ pieces = { fake_dom = [ { special: "pieces_marker", dataset: { } }, {% for p in pieces -%} - { dataset: { piece: "{{ p.id }}" } }, + { dataset: { piece: "{{ p.0 }}" } }, {% endfor -%} { special: "defs_marker", dataset: { } }, ]; @@ -161,9 +162,9 @@ impl TestsAccumulator { |StartPieceSpec { id, pinned, moveable }| { let id = id.try_into().unwrap(); let z = zm.increment().unwrap(); - StartPiece { id, pinned, moveable, z } + (id, StartPiece { id, pinned, moveable, z }) } - ).collect_vec(); + ).collect(); let targets = targets.into_iter().map( |s| s.try_into().unwrap() -- 2.30.2