mirror of
https://github.com/storytold/designcraft.git
synced 2026-10-26 03:06:56 -06:00
Found while testing crates/doc/src/build.rs:377 (Document::insert_pages), called from crates/engine/src/cmd/layout.rs:91 Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
17 lines
796 B
Rust
17 lines
796 B
Rust
//! `layout.pages.insert` clamps an out-of-range `after` to the end instead of overflowing.
|
|
use designcraft_engine::Session;
|
|
use serde_json::json;
|
|
|
|
#[test]
|
|
fn insert_after_u64_max_appends_at_the_end() {
|
|
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 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)));
|
|
}
|