//! Section vertical alignment (`w:vAlign` in `w:sectPr`, ECMA-376 Part 1 ยง17.6.23, values from //! ST_VerticalJc). Fixtures are hand-written from the spec. use wordcraft_doc::section::PageVAlign; fn docx(body: &str) -> Vec { let root = r#""#; let doc = format!( r#"{body}"# ); let mut zw = craft_zip::Writer::new(); for (name, bytes) in [("_rels/.rels", root.as_bytes()), ("word/document.xml", doc.as_bytes())] { zw.add(name, bytes, craft_zip::Compression::Deflated).unwrap(); } zw.finish().unwrap() } fn document_xml(bytes: &[u8]) -> String { let mut z = craft_zip::Archive::open(bytes, craft_zip::Limits { max_entries: 10_000, max_total_bytes: 64 << 20 }).unwrap(); String::from_utf8(z.read("word/document.xml", 16 << 20).unwrap().unwrap()).unwrap() } /// #1320: "both" (Justified) reads as Justify and writes back as "both"; the others keep theirs. #[test] fn section_vertical_alignment_round_trips_with_justified() { let sect = |v: &str| format!(r#""#); let body = format!( r#"{}A{}B{}C{}DE{}"#, sect("both"), sect("center"), sect("bottom"), sect("top"), sect("sideways") ); let d = wordcraft_docx::read(&docx(&body)).unwrap(); let got: Vec = d.sections().iter().map(|(_, s)| s.valign).collect(); let want = vec![PageVAlign::Justify, PageVAlign::Center, PageVAlign::Bottom, PageVAlign::Top, PageVAlign::Top]; assert_eq!(got, want); let out = wordcraft_docx::write(&d).unwrap(); let xml = document_xml(&out); assert_eq!(xml.matches(r#""#).count(), 1, "{xml}"); assert_eq!(xml.matches(r#""#).count(), 1, "{xml}"); assert_eq!(xml.matches(r#""#).count(), 1, "{xml}"); assert_eq!(xml.matches("w:vAlign").count(), 3, "top writes nothing: {xml}"); let back = wordcraft_docx::read(&out).unwrap(); assert_eq!(back.sections().iter().map(|(_, s)| s.valign).collect::>(), want); }