Files
cadcraft/crates/engine/tests/it/copy_count.rs
T
NetterSilverandClaude Haiku 5.5 b9b7b3d439 Refuse invalid count in JSON copy instead of clamping it (#2294)
Found while testing crates/engine/src/cmd/modify/transform.rs:69 (run_copy)

Co-authored-by: Claude Haiku 5.5 <noreply@anthropic.com>
2026-10-29 21:21:58 -04:00

25 lines
975 B
Rust

//! JSON COPY refuses a `count` that is not an integer from 1 to 10000 instead of clamping it.
use cadcraft_engine::Session;
use serde_json::{Value, json};
fn entities(s: &Session) -> usize {
s.doc().map(|d| d.model.iter().count()).unwrap_or(0)
}
#[test]
fn invalid_copy_count_is_refused() {
let mut s = Session::new();
let r = s.execute("line", &json!({"points": [[0, 0], [10, 0]]})).unwrap();
let h = r["handles"][0].clone();
let before = entities(&s);
let bad: [Value; 7] = [json!(0), json!(-3), json!(2.5), json!("abc"), json!(null), json!(10001), json!(50000)];
for c in bad {
let r = s.execute("copy", &json!({"handles": [h], "delta": [0, 5], "count": c}));
assert!(r.is_err(), "count {c} should be refused");
assert_eq!(entities(&s), before, "count {c} changed the drawing");
}
s.execute("copy", &json!({"handles": [h], "delta": [0, 5], "count": 3})).unwrap();
assert_eq!(entities(&s), before + 3);
}