mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-10 14:41:51 +00:00
M6: stamp_custom's line test uses a template the schema accepts (#1741)
The test sent a 500-character line, past the schema's maxLength of 200, and only checked an upper bound on the page text, which also passes when the line is missing. It now sends a 198-character template whose filled-in line runs to 264 characters, and checks the saved /PCByLine holds exactly 200. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Pq7HyCfwzyRXj4VfQAVVdv
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
22d0e4cc4e
commit
a26f8db0bc
@@ -9441,10 +9441,20 @@ fn a_custom_stamp_line_is_filled_in_when_placed() {
|
||||
// The stamp stays within the natural 200 pt. Its line, at its usual size, is wider than the
|
||||
// picture, so the stamp is wider than the picture's shape with the band added.
|
||||
assert!(lw / lh > pw / ph * (1.0 - 0.22) + 0.01, "widened for the line: {pw}x{ph} vs {lw}x{lh}");
|
||||
// A line past the limit is cut, not refused.
|
||||
let long = "x".repeat(500);
|
||||
// A template within the schema's 200 characters whose filled-in line runs past the limit
|
||||
// (33 times of 8 characters) is cut to exactly 200, not refused.
|
||||
let long = "{time}".repeat(33);
|
||||
assert!(long.chars().count() <= 200);
|
||||
ok(&mut a, "stamp_custom", json!({ "doc": doc, "page": 3, "path": "b.pdf", "file_page": 2, "at": [100, 150], "line": long }));
|
||||
assert!(page_text(&mut a, doc)[2].matches('x').count() <= 200);
|
||||
ok(&mut a, "doc_save", json!({ "doc": doc, "path": "stamped.pdf" }));
|
||||
let saved = pdfcraft_cos::Document::open(std::sync::Arc::new(std::fs::read(dir.join("stamped.pdf")).unwrap())).unwrap();
|
||||
let lines: Vec<String> = saved
|
||||
.scan_objects()
|
||||
.filter_map(|(_, o)| o.as_dict()?.get(b"PCByLine")?.as_string().map(pdfcraft_cos::PdfString::to_text))
|
||||
.filter(|l| l.starts_with("10:13 pm"))
|
||||
.collect();
|
||||
assert_eq!(lines.len(), 1, "{lines:?}");
|
||||
assert_eq!(lines[0].chars().count(), 200, "{:?}", lines[0]);
|
||||
}
|
||||
|
||||
/// Three paragraphs: Alpha (two rows), Bravo (one row) and Charlie (two rows), at the leading
|
||||
|
||||
Reference in New Issue
Block a user