⎇ 568f643327ec6b4879df0087def7f4e66b6acafb
tests/generated/block_margin_y_sibling_collapse_positive.rs
History
Who touched what
raw
Implement CSS Block layout (`Display::Block`) (#474)
1#[test]
2fn block_margin_y_sibling_collapse_positive() {
3 #[allow(unused_imports)]
4 use taffy::{prelude::*, tree::Layout};
5 let mut taffy = taffy::Taffy::new();
6 let node0 = taffy
7 .new_leaf(taffy::style::Style {
8 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
9 margin: taffy::geometry::Rect {
10 left: zero(),
11 right: zero(),
12 top: taffy::style::LengthPercentageAuto::Length(10f32),
13 bottom: taffy::style::LengthPercentageAuto::Length(10f32),
14 },
15 ..Default::default()
16 })
17 .unwrap();
18 let node1 = taffy
19 .new_leaf(taffy::style::Style {
20 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
21 margin: taffy::geometry::Rect {
22 left: zero(),
23 right: zero(),
24 top: taffy::style::LengthPercentageAuto::Length(10f32),
25 bottom: taffy::style::LengthPercentageAuto::Length(10f32),
26 },
27 ..Default::default()
28 })
29 .unwrap();
30 let node2 = taffy
31 .new_leaf(taffy::style::Style {
32 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
33 margin: taffy::geometry::Rect {
34 left: zero(),
35 right: zero(),
36 top: taffy::style::LengthPercentageAuto::Length(5f32),
37 bottom: taffy::style::LengthPercentageAuto::Length(5f32),
38 },
39 ..Default::default()
40 })
41 .unwrap();
42 let node3 = taffy
43 .new_leaf(taffy::style::Style {
44 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
45 margin: taffy::geometry::Rect {
46 left: zero(),
47 right: zero(),
48 top: taffy::style::LengthPercentageAuto::Length(10f32),
49 bottom: taffy::style::LengthPercentageAuto::Length(10f32),
50 },
51 ..Default::default()
52 })
53 .unwrap();
54 let node = taffy
55 .new_with_children(
56 taffy::style::Style {
57 display: taffy::style::Display::Block,
58 size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
59 ..Default::default()
60 },
61 &[node0, node1, node2, node3],
62 )
63 .unwrap();
64 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
65 println!("\nComputed tree:");
66 taffy::util::print_tree(&taffy, node);
67 println!();
68 let Layout { size, location, .. } = taffy.layout(node).unwrap();
69 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
70 assert_eq!(size.height, 90f32, "height of node {:?}. Expected {}. Actual {}", node, 90f32, size.height);
71 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
72 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
73 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
74 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
75 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
76 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
77 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node0, 10f32, location.y);
78 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
79 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
80 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
81 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
82 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node1, 30f32, location.y);
83 let Layout { size, location, .. } = taffy.layout(node2).unwrap();
84 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
85 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height);
86 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
87 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node2, 50f32, location.y);
88 let Layout { size, location, .. } = taffy.layout(node3).unwrap();
89 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
90 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height);
91 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
92 assert_eq!(location.y, 70f32, "y of node {:?}. Expected {}. Actual {}", node3, 70f32, location.y);
93}