From 63e794716bc536ae4d52169eb4c35c6a0dbaf87b Mon Sep 17 00:00:00 2001 From: Mat Strange Date: Wed, 21 Oct 2026 16:15:46 +0100 Subject: [PATCH] Pin the parts of the package too The body of the document part is pinned, so the writer's output is compared byte for byte; the parts of the package are pinned as well, so a part that is added or lost shows up here too. Co-Authored-By: opencode --- .../docx/tests/content_control_save_cost.rs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/crates/docx/tests/content_control_save_cost.rs b/crates/docx/tests/content_control_save_cost.rs index cbb59584c..9e3b96e47 100644 --- a/crates/docx/tests/content_control_save_cost.rs +++ b/crates/docx/tests/content_control_save_cost.rs @@ -134,6 +134,12 @@ fn the_controls_are_written_where_they_were() { } } +/// The names of the parts of a package, in the order they are in it. +fn part_names(bytes: &[u8]) -> Vec { + let z = zip::ZipArchive::new(std::io::Cursor::new(bytes)).expect("zip"); + z.file_names().map(str::to_string).collect() +} + /// The body of the document part of a package. fn document_body(bytes: &[u8]) -> String { let mut z = zip::ZipArchive::new(std::io::Cursor::new(bytes)).expect("zip"); @@ -201,8 +207,22 @@ fn pinned_doc() -> Document { fn the_document_body_is_written_as_it_was() { let bytes = write(&pinned_doc()).expect("write"); assert_eq!(document_body(&bytes), PINNED_BODY); + // The parts are the same ones, so nothing is added to the package and nothing is lost. + assert_eq!(part_names(&bytes), PINNED_PARTS); } /// The body of the document part of [`pinned_doc`], as the writer wrote it before it was made /// faster. +const PINNED_PARTS: &[&str] = &[ + "[Content_Types].xml", + "_rels/.rels", + "word/document.xml", + "word/_rels/document.xml.rels", + "word/styles.xml", + "word/settings.xml", + "word/theme/theme1.xml", + "docProps/core.xml", + "docProps/app.xml", +]; + const PINNED_BODY: &str = r#"before inside a between inside b afterin the block"#;