DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Insert Pages bounds test: an out-of-range placement is refused
moppeeerebb428619a6b
diff --git a/crates/engine/tests/insert_pages_bounds.rs b/crates/engine/tests/insert_pages_bounds.rsindex e96a6cc4b..340e2fc81 100644--- a/crates/engine/tests/insert_pages_bounds.rs+++ b/crates/engine/tests/insert_pages_bounds.rs@@ -1,16 +1,21 @@-//! `layout.pages.insert` clamps an out-of-range `after` to the end instead of overflowing.+//! `layout.pages.insert` refuses an out-of-range `after` or `before` (they must name a page)+//! instead of overflowing, and changes nothing.use designcraft_engine::Session;use serde_json::json;#[test]-fn insert_after_u64_max_appends_at_the_end() {+fn insert_after_u64_max_is_refused_without_overflow() {let mut s = Session::new();s.execute("file.new", &json!({"pages":2})).unwrap();let before: Vec<_> = s.doc().unwrap().doc.pages().map(|(_, _, p)| p.id).collect();- let out = s.execute("layout.pages.insert", &json!({"after": u64::MAX, "count": 2})).unwrap();- assert_eq!(out["total"], 4);+ let undo = s.doc().unwrap().history.undo.len();+ for p in [json!({"after": u64::MAX, "count": 2}), json!({"before": u64::MAX, "count": 2})] {+ assert!(s.execute("layout.pages.insert", &p).is_err(), "{p}");+ }let after: Vec<_> = s.doc().unwrap().doc.pages().map(|(_, _, p)| p.id).collect();- assert_eq!(after.len(), 4);- assert_eq!(after[..2], before[..], "the original pages must stay first; new pages go at the end");- assert!(after[2..].iter().all(|id| !before.contains(id)));+ assert_eq!(after, before, "no pages added");+ assert_eq!(s.doc().unwrap().history.undo.len(), undo, "no undo step");+ // The last page is still a valid place: the new pages go at the end.+ let out = s.execute("layout.pages.insert", &json!({"after": 1, "count": 2})).unwrap();+ assert_eq!(out["total"], 4);}