M14: cover PDF suffix case in web downloads

Assert exact delivered filenames and PDF bytes for lowercase, uppercase, mixed-case Unicode and missing suffixes.
This commit is contained in:
Mex authored and GitHub committed 2026-11-15 20:27:16 +01:00
1 parent a9a1aa36a2
commit 3e776e4c7d
1 file changed
+20
+20
View File
@@ -465,6 +465,26 @@ fn export_pdf_without_a_path_asks_where_to_save() {
let _ = std::fs::remove_dir_all(&dir);
}
/// An explicit web PDF export keeps an existing PDF suffix regardless of ASCII case.
#[test]
fn web_pdf_export_keeps_an_existing_suffix_in_any_case() {
let downloaded = Rc::new(RefCell::new(Vec::new()));
let captured = downloaded.clone();
let services = Services {
download: Some(Box::new(move |name, bytes| {
captured.borrow_mut().push((name.to_string(), bytes.starts_with(b"%PDF")));
Ok(())
})),
..Default::default()
};
let mut a = WordApp::new(Session::new(wordcraft_doc::Document::new()), services);
for (name, expected) in [("Report.pdf", "Report.pdf"), ("Report.PDF", "Report.PDF"), ("Résumé.PdF", "Résumé.PdF"), ("Report", "Report.pdf")] {
let result = a.execute("file.exportPdf", json!({"path": name})).unwrap();
assert_eq!(result["downloaded"], expected, "{name}");
assert_eq!(downloaded.borrow().last().cloned(), Some((expected.to_string(), true)), "{name}");
}
}
/// Open, Save As and Export PNG from the command search (no path) ask for a file the same way.
#[test]
fn file_commands_without_a_path_ask_for_one() {