mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 21:52:32 +00:00
DOCX: make the gutter-at-top tests check the order and False/FALSE
The merge unit test compared Options, and its generated part had no w:mirrorMargins, so the order check proved nothing; put the element in and look the positions up. Add the False and FALSE spellings to the value test. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
fc808abd49
commit
1ea162df26
@@ -390,16 +390,18 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn gutter_at_top_comes_from_the_generated_part() {
|
||||
let orig = r#"<w:settings xmlns:w="w" xmlns:m="m" xmlns:r="r"><w:mirrorMargins/><w:gutterAtTop/><w:proofState w:spelling="clean"/></w:settings>"#;
|
||||
let orig =
|
||||
r#"<w:settings xmlns:w="w" xmlns:m="m" xmlns:r="r"><w:mirrorMargins/><w:gutterAtTop/><w:proofState w:spelling="clean"/></w:settings>"#;
|
||||
assert!(has_unowned(orig.as_bytes()));
|
||||
// Turned off in the model: the original element goes, the foreign one stays.
|
||||
let out = String::from_utf8(merge(orig.as_bytes(), GEN.as_bytes()).unwrap()).unwrap();
|
||||
assert!(!out.contains("gutterAtTop") && out.contains("<w:proofState"), "{out}");
|
||||
// On in the model: written once, in place.
|
||||
let gen_on = GEN.replace("<w:defaultTabStop", "<w:gutterAtTop/><w:defaultTabStop");
|
||||
let gen_on = GEN.replace("<w:defaultTabStop", "<w:mirrorMargins/><w:gutterAtTop/><w:defaultTabStop");
|
||||
let out = String::from_utf8(merge(orig.as_bytes(), gen_on.as_bytes()).unwrap()).unwrap();
|
||||
assert_eq!(out.matches("<w:gutterAtTop/>").count(), 1, "{out}");
|
||||
assert!(out.find("<w:mirrorMargins/>") < out.find("<w:gutterAtTop/>") && out.find("<w:gutterAtTop/>") < out.find("<w:proofState"), "{out}");
|
||||
let at = |tag: &str| out.find(tag).unwrap_or_else(|| panic!("{tag} missing: {out}"));
|
||||
assert!(at("<w:mirrorMargins/>") < at("<w:gutterAtTop/>") && at("<w:gutterAtTop/>") < at("<w:proofState"), "{out}");
|
||||
// A file whose only extra setting is this one has nothing foreign to keep.
|
||||
assert!(!has_unowned(br#"<w:settings xmlns:w="w"><w:zoom w:percent="100"/><w:gutterAtTop/></w:settings>"#));
|
||||
}
|
||||
|
||||
@@ -2981,6 +2981,8 @@ fn gutter_at_top_reads_every_value_spelling() {
|
||||
(r#"<w:gutterAtTop w:val="0"/>"#, false),
|
||||
(r#"<w:gutterAtTop w:val="false"/>"#, false),
|
||||
(r#"<w:gutterAtTop w:val="off"/>"#, false),
|
||||
(r#"<w:gutterAtTop w:val="False"/>"#, false),
|
||||
(r#"<w:gutterAtTop w:val="FALSE"/>"#, false),
|
||||
] {
|
||||
let file = replace_part(&plain, "word/settings.xml", xml.replace(zoom, &format!("{zoom}{element}")).as_bytes());
|
||||
assert_eq!(craft_docx::read(&file).unwrap().settings.gutter_at_top, expected, "{element:?}");
|
||||
@@ -2997,9 +2999,8 @@ fn gutter_at_top_is_merged_into_a_foreign_settings_part() {
|
||||
let xml = settings_part(&plain);
|
||||
let zoom = r#"<w:zoom w:percent="100"/>"#;
|
||||
let foreign = |element: &str| {
|
||||
let extra = format!(
|
||||
r#"{zoom}<w:mirrorMargins/>{element}<w:proofState w:spelling="clean"/><w:rsids><w:rsidRoot w:val="00A1B2C3"/></w:rsids>"#
|
||||
);
|
||||
let extra =
|
||||
format!(r#"{zoom}<w:mirrorMargins/>{element}<w:proofState w:spelling="clean"/><w:rsids><w:rsidRoot w:val="00A1B2C3"/></w:rsids>"#);
|
||||
replace_part(&plain, "word/settings.xml", xml.replace(zoom, &extra).as_bytes())
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user