From 20a9ac7433864d066e7acae69074874a5c7fe290 Mon Sep 17 00:00:00 2001 From: 2ez4gcx <108074836+2ez4gcx@users.noreply.github.com> Date: Wed, 4 Nov 2026 22:08:20 +0700 Subject: [PATCH 1/2] MINSERT: JSON rows and columns are whole numbers The JSON form read rows and columns as numbers with no fraction, so 2.0 and 1e2 were counts. They must now be JSON whole numbers from 1 to 32767, as the array commands' JSON counts already are; missing or null is still 1. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/blocks.rs | 7 ++++--- crates/engine/tests/it/minsert.rs | 13 +++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/cmd/blocks.rs b/crates/engine/src/cmd/blocks.rs index 8189e37c1..3a635e470 100644 --- a/crates/engine/src/cmd/blocks.rs +++ b/crates/engine/src/cmd/blocks.rs @@ -349,13 +349,14 @@ fn run_insert(s: &mut Session, p: &Value) -> Result { /// MINSERT's JSON form: INSERT's parameters and the grid. fn run_minsert(s: &mut Session, p: &Value) -> Result { + // A whole number, as the array commands' JSON counts are: 2.0 and 1e2 are refused too. let count = |key: &str| -> Result { match p.get(key) { None | Some(Value::Null) => Ok(1), Some(v) => v - .as_f64() - .filter(|n| n.fract() == 0.0 && *n >= 1.0 && *n <= f64::from(Grid::MAX)) - .map(|n| n as u32) + .as_u64() + .and_then(|n| u32::try_from(n).ok()) + .filter(|n| (1..=Grid::MAX).contains(n)) .ok_or_else(|| bad("minsert", format!("`{key}` must be an integer between 1 and {}", Grid::MAX))), } }; diff --git a/crates/engine/tests/it/minsert.rs b/crates/engine/tests/it/minsert.rs index e123876df..cee66c14d 100644 --- a/crates/engine/tests/it/minsert.rs +++ b/crates/engine/tests/it/minsert.rs @@ -205,14 +205,23 @@ fn the_json_form_makes_the_same_grid() { json!({"name": "B", "at": [0, 0], "rows": 0}), json!({"name": "B", "at": [0, 0], "columns": 32768}), json!({"name": "B", "at": [0, 0], "rows": 2.5}), + // A whole number written as a float is refused, as by the array commands' JSON forms. + json!({"name": "B", "at": [0, 0], "rows": 2.0}), + json!({"name": "B", "at": [0, 0], "columns": 1e2}), + json!({"name": "B", "at": [0, 0], "rows": "2"}), + json!({"name": "B", "at": [0, 0], "rows": -2}), // A distance that is not a number is refused, not taken as 0. json!({"name": "B", "at": [0, 0], "rows": 2, "rowSpacing": "15"}), json!({"name": "B", "at": [0, 0], "columns": 2, "columnSpacing": true}), ] { assert!(s.execute("minsert", &bad).is_err(), "{bad}"); } - // A whole number written as 2.0 is a count; `explode` is INSERT's and leaves the grid made. - let r = s.execute("minsert", &json!({"name": "B", "at": [0, 200], "rows": 2.0, "rowSpacing": 15, "explode": true})).unwrap(); + // Nothing was made by the refused calls. + assert_eq!(inserts(&s).len(), 2); + // `explode` is INSERT's and leaves the grid made; 32767 is the largest count. + let r = s.execute("minsert", &json!({"name": "B", "at": [0, 200], "rows": 2, "rowSpacing": 15, "explode": true})).unwrap(); assert!(r["handle"].is_string(), "{r}"); assert_eq!(inserts(&s).last().map(grid), Some((1, 2, 0.0, 15.0))); + s.execute("minsert", &json!({"name": "B", "at": [0, 300], "columns": 32767, "columnSpacing": 1})).unwrap(); + assert_eq!(inserts(&s).last().map(grid), Some((32767, 1, 1.0, 0.0))); } From 8b1adcd8d5088aaa60d9f5f541bd2ffbf680e42d Mon Sep 17 00:00:00 2001 From: 2ez4gcx <108074836+2ez4gcx@users.noreply.github.com> Date: Wed, 4 Nov 2026 23:39:33 +0700 Subject: [PATCH 2/2] MINSERT: test that JSON null counts and distances are taken as missing A null rows or columns is 1 and a null rowSpacing or columnSpacing is 0, as when the key is missing. Each count is tested null on its own; the distances on a 2 x 2 grid, since one row or column drops its distance anyway. Co-Authored-By: Claude Opus 5.5 --- crates/engine/tests/it/minsert.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/engine/tests/it/minsert.rs b/crates/engine/tests/it/minsert.rs index cee66c14d..9bb0f1137 100644 --- a/crates/engine/tests/it/minsert.rs +++ b/crates/engine/tests/it/minsert.rs @@ -222,6 +222,14 @@ fn the_json_form_makes_the_same_grid() { let r = s.execute("minsert", &json!({"name": "B", "at": [0, 200], "rows": 2, "rowSpacing": 15, "explode": true})).unwrap(); assert!(r["handle"].is_string(), "{r}"); assert_eq!(inserts(&s).last().map(grid), Some((1, 2, 0.0, 15.0))); + // A null count is 1 and a null distance 0, as missing ones are: each count on its own, then + // both distances with two rows and two columns (one row or column keeps no distance anyway). + s.execute("minsert", &json!({"name": "B", "at": [0, 250], "rows": null, "columns": 2, "columnSpacing": 20})).unwrap(); + assert_eq!(inserts(&s).last().map(grid), Some((2, 1, 20.0, 0.0))); + s.execute("minsert", &json!({"name": "B", "at": [0, 270], "rows": 2, "columns": null, "rowSpacing": 15})).unwrap(); + assert_eq!(inserts(&s).last().map(grid), Some((1, 2, 0.0, 15.0))); + s.execute("minsert", &json!({"name": "B", "at": [0, 290], "rows": 2, "columns": 2, "rowSpacing": null, "columnSpacing": null})).unwrap(); + assert_eq!(inserts(&s).last().map(grid), Some((2, 2, 0.0, 0.0))); s.execute("minsert", &json!({"name": "B", "at": [0, 300], "columns": 32767, "columnSpacing": 1})).unwrap(); assert_eq!(inserts(&s).last().map(grid), Some((32767, 1, 1.0, 0.0))); }