>()
);
}
#[test]
fn inset_absolute_uses_nearest_positioned_ancestor() {
let html = r##"
"##;
let tree = parse_html(html);
let layout = layout_dom(&tree, (900.0, 700.0));
let cb = layout.rects[&tree.get_element_by_id("cb").expect("containing block")];
let abs = layout.rects[&tree.get_element_by_id("abs").expect("absolute child")];
let abs_end = layout.rects[&tree.get_element_by_id("abs-end").expect("end-inset child")];
let abs_percent = layout.rects[&tree.get_element_by_id("abs-percent").expect("percent-inset child")];
let fixed = layout.rects[&tree.get_element_by_id("fixed").expect("fixed child")];
// Absolute insets are measured from the positioned ancestor's padding
// edge, not from the intervening static wrapper.
assert!((abs.x - cb.x - 25.0).abs() < 1.0, "wrong absolute x: cb={cb:?} abs={abs:?}");
assert!((abs.y - cb.y - 35.0).abs() < 1.0, "wrong absolute y: cb={cb:?} abs={abs:?}");
assert_eq!(
layout.styles[&tree.get_element_by_id("abs").unwrap()].display,
obscura_render::Display::Block,
"positioned inline should be blockified"
);
assert!((abs_end.x - 350.0).abs() < 1.0, "wrong right-inset x: {abs_end:?}");
assert!((abs_end.y - 200.0).abs() < 1.0, "wrong bottom-inset y: {abs_end:?}");
assert!((abs_percent.x - 260.0).abs() < 1.0, "wrong percent-inset x: {abs_percent:?}");
assert!((abs_percent.y - 160.0).abs() < 1.0, "wrong percent-inset y: {abs_percent:?}");
assert!((fixed.x - 520.0).abs() < 1.0, "fixed box did not use viewport x: {fixed:?}");
assert!((fixed.y - 40.0).abs() < 1.0, "fixed box did not use viewport y: {fixed:?}");
}
#[test]
fn long_text_run_wraps_across_multiple_lines() {
// A long single text node with no inline elements breaking it up must
// wrap within a narrow container instead of overflowing on one line. The
// container's height is the mode-independent proof: several wrapped lines
// make it much taller than one line, whether text is shaped by cosmic-text
// (paint) or split into word boxes (layout-only).
let html = r##"This sentence has plenty of words to wrap across several lines
"##;
let tree = parse_html(html);
let layout = layout_dom(&tree, (1000.0, 1000.0));
// Tightest element enclosing the text: the 100px div itself.
let mut div_rect: Option = None;
for (id, rect) in &layout.rects {
if tree.text_content(*id).contains("several lines") {
if div_rect.as_ref().map(|d| rect.width * rect.height < d.width * d.height).unwrap_or(true) {
div_rect = Some(*rect);
}
}
}
let div_rect = div_rect.expect("text container laid out");
assert!(div_rect.width <= 101.0, "container should hold its 100px width, got {}", div_rect.width);
assert!(
div_rect.height > 60.0,
"text should wrap onto several lines in a 100px-wide box (tall container), got height {}",
div_rect.height
);
}