use f_office_units::Length;
use crate::layout::testing::{on_base_with, p, pass_with, table};
use crate::numbering::Numbering;
use crate::quirks::FloatingTableTop;
fn first_cell_top(anchor: &str, rule: FloatingTableTop) -> Option<Length> {
let properties = format!(
r#"<w:tblpPr w:vertAnchor="{anchor}" w:horzAnchor="margin" w:tblpY="2000"/><w:tblW w:w="3000" w:type="dxa"/>"#
);
let body = table(&properties, &[3000], &[("", &[&p("a")])]) + &p("z");
let target = on_base_with(|p| p.with_variant(rule));
let pass = pass_with(&body, ("", None), None, Numbering::default(), target);
pass.lines
.iter()
.find(|line| line.cell.is_some())
.map(|line| line.top)
}
#[test]
fn raises_a_table_that_floats_from_the_page_or_the_margin_by_one_twip() {
let twip = Length::from_units(Length::UNITS_PER_TWIP);
for anchor in ["page", "margin"] {
let at = first_cell_top(anchor, FloatingTableTop::AtOffset);
let higher = first_cell_top(anchor, FloatingTableTop::TwipHigher);
assert_eq!(
at.zip(higher).map(|(at, higher)| at - higher),
Some(twip),
"{anchor}"
);
}
}
#[test]
fn keeps_a_table_that_floats_from_the_text_at_its_offset() {
let at = first_cell_top("text", FloatingTableTop::AtOffset);
assert!(at.is_some());
assert_eq!(at, first_cell_top("text", FloatingTableTop::TwipHigher));
}