use crate::*;
use float_pigment_forest::{convert_node_ref_to_ptr, ChildOperation, Node, StyleSetter};
use float_pigment_layout::{DefLength, OptionNum, OptionSize, Size};
unsafe fn as_ref<'a>(node: *mut Node) -> &'a Node {
&*node
}
#[test]
fn entry_node_margin_does_not_collapse_with_child() {
unsafe {
let entry = as_ref(Node::new_ptr());
entry.set_margin_top(DefLength::Points(Len::from_f32(30.)));
let child = as_ref(Node::new_ptr());
child.set_height(DefLength::Points(Len::from_f32(50.)));
child.set_margin_top(DefLength::Points(Len::from_f32(20.)));
entry.append_child(convert_node_ref_to_ptr(child));
entry.layout(
OptionSize::new(OptionNum::some(Len::from_f32(375.)), OptionNum::none()),
Size::new(Len::from_f32(0.), Len::from_f32(0.)),
);
assert_eq!(entry.layout_position().top, 30.);
assert_eq!(child.layout_position().top, 20.);
}
}
#[test]
fn non_entry_parent_collapses_with_first_child() {
unsafe {
let container = as_ref(Node::new_ptr());
let parent = as_ref(Node::new_ptr());
parent.set_margin_top(DefLength::Points(Len::from_f32(30.)));
let child = as_ref(Node::new_ptr());
child.set_height(DefLength::Points(Len::from_f32(50.)));
child.set_margin_top(DefLength::Points(Len::from_f32(20.)));
parent.append_child(convert_node_ref_to_ptr(child));
container.append_child(convert_node_ref_to_ptr(parent));
container.layout(
OptionSize::new(OptionNum::some(Len::from_f32(375.)), OptionNum::none()),
Size::new(Len::from_f32(0.), Len::from_f32(0.)),
);
assert_eq!(child.layout_position().top, 0.);
}
}
#[test]
fn block_bfc_block_sequence_no_propagation() {
assert_xml!(
r#"
<div>
<div>
<div style="height: 10px; margin-bottom: 20px;" expect_top="0"></div>
<div style="display: flex; margin-top: 30px; height: 40px;" expect_top="60"></div>
<div style="margin-top: 50px; height: 60px;" expect_top="150"></div>
</div>
</div>
"#
)
}
#[test]
fn flow_root_as_parent_no_collapse() {
assert_xml!(
r#"
<div>
<div style="display: flow-root; margin-top: 30px;">
<div style="margin-top: 20px; height: 50px;" expect_top="20"></div>
</div>
</div>
"#
)
}
#[test]
fn flow_root_as_child_no_collapse() {
assert_xml!(
r#"
<div>
<div style="margin-top: 30px;">
<div style="display: flow-root; margin-top: 20px; height: 50px;" expect_top="20"></div>
</div>
</div>
"#
)
}
#[test]
fn flow_root_as_sibling_no_collapse() {
assert_xml!(
r#"
<div>
<div style="margin-bottom: 40px; height: 10px;"></div>
<div style="display: flow-root; margin-top: 30px; height: 50px;" expect_top="80"></div>
</div>
"#
)
}