Files
craft-libs/crates/docx/tests/application_name.rs
T
StDenis1980andClaude Opus 5.5 0b0e5accd5 docx: set_application_name for apps that embed the writer
An app that ships the writer under its own name names itself in docProps/app.xml
(<Application>); "WordCraft" until set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 14:37:37 +01:00

20 lines
967 B
Rust

//! An app that embeds the writer names itself in `docProps/app.xml` (its own test binary: the
//! name is set once per process).
use std::io::Read;
#[test]
fn the_embedding_app_names_itself_in_app_xml() {
assert_eq!(craft_docx::application_name(), "WordCraft", "the default");
craft_docx::set_application_name("Example Writer");
craft_docx::set_application_name("Other");
assert_eq!(craft_docx::application_name(), "Example Writer", "only the first call counts");
let mut d = craft_wordmodel::Document::new();
d.body = vec![craft_wordmodel::para_block(craft_wordmodel::Paragraph::with_text("Text", Default::default()))];
let bytes = craft_docx::write(&d).unwrap();
let mut z = zip::ZipArchive::new(std::io::Cursor::new(&bytes)).unwrap();
let mut app = String::new();
z.by_name("docProps/app.xml").unwrap().read_to_string(&mut app).unwrap();
assert!(app.contains("<Application>Example Writer</Application>"), "{app}");
}