Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

Test that a batch deleting pages also saves in full

srt8hellcat2-ui12d89c551c98
diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs
index e94cdc1da..3ad72285f 100644
--- a/crates/engine/src/tests.rs
+++ b/crates/engine/src/tests.rs
@@ -538,6 +538,20 @@ fn saving_after_deleting_pages_from_a_signed_file_stays_incremental() {
assert!(s.get(id).unwrap().is_signed());
}
+#[test]
+fn saving_after_a_batch_that_deletes_pages_rewrites_the_file() {
+ let (mut s, id) = session_with(6);
+ let original = s.save_bytes(id).unwrap();
+ let batch = Edit::Batch {
+ label: "Delete and rotate".into(),
+ edits: vec![Edit::DeletePages { pages: vec![1, 2, 3, 4] }, Edit::RotatePages { pages: vec![0], degrees: 90 }],
+ };
+ s.apply(id, batch).unwrap();
+ let saved = s.save_bytes(id).unwrap();
+ assert!(!saved.starts_with(original.as_slice()), "a full rewrite, not an update appended to the old file");
+ assert!(!contains(&saved, b"Page 3"), "a deleted page's text is not left in an earlier revision");
+}
+
#[test]
fn saving_without_deleting_pages_stays_incremental() {
let (mut s, id) = session_with(3);