⎇ float-layout
tests/generated/block/block_margin_y_sibling_collapse_positive.rs
History
Who touched what
raw
Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn block_margin_y_sibling_collapse_positive__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, Layout};
6 let mut taffy = crate::new_test_tree();
7 let node0 = taffy
8 .new_leaf(taffy::style::Style {
9 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
10 margin: taffy::geometry::Rect { left: zero(), right: zero(), top: length(10f32), bottom: length(10f32) },
11 ..Default::default()
12 })
13 .unwrap();
14 let node1 = taffy
15 .new_leaf(taffy::style::Style {
16 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
17 margin: taffy::geometry::Rect { left: zero(), right: zero(), top: length(10f32), bottom: length(10f32) },
18 ..Default::default()
19 })
20 .unwrap();
21 let node2 = taffy
22 .new_leaf(taffy::style::Style {
23 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
24 margin: taffy::geometry::Rect { left: zero(), right: zero(), top: length(5f32), bottom: length(5f32) },
25 ..Default::default()
26 })
27 .unwrap();
28 let node3 = taffy
29 .new_leaf(taffy::style::Style {
30 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
31 margin: taffy::geometry::Rect { left: zero(), right: zero(), top: length(10f32), bottom: length(10f32) },
32 ..Default::default()
33 })
34 .unwrap();
35 let node = taffy
36 .new_with_children(
37 taffy::style::Style {
38 display: taffy::style::Display::Block,
39 size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
40 ..Default::default()
41 },
42 &[node0, node1, node2, node3],
43 )
44 .unwrap();
45 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
46 println!("\nComputed tree:");
47 taffy.print_tree(node);
48 println!();
49 let layout = taffy.layout(node).unwrap();
50 let Layout { size, location, .. } = layout;
51 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
52 assert_eq!(size.height, 90f32, "height of node {:?}. Expected {}. Actual {}", node, 90f32, size.height);
53 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
54 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
55 let layout = taffy.layout(node0).unwrap();
56 let Layout { size, location, .. } = layout;
57 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
58 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
59 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
60 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node0, 10f32, location.y);
61 let layout = taffy.layout(node1).unwrap();
62 let Layout { size, location, .. } = layout;
63 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
64 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
65 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
66 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node1, 30f32, location.y);
67 let layout = taffy.layout(node2).unwrap();
68 let Layout { size, location, .. } = layout;
69 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
70 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height);
71 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
72 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node2, 50f32, location.y);
73 let layout = taffy.layout(node3).unwrap();
74 let Layout { size, location, .. } = layout;
75 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
76 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height);
77 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
78 assert_eq!(location.y, 70f32, "y of node {:?}. Expected {}. Actual {}", node3, 70f32, location.y);
79}
80
81#[test]
82#[allow(non_snake_case)]
83fn block_margin_y_sibling_collapse_positive__content_box() {
84 #[allow(unused_imports)]
85 use taffy::{prelude::*, Layout};
86 let mut taffy = crate::new_test_tree();
87 let node0 = taffy
88 .new_leaf(taffy::style::Style {
89 box_sizing: taffy::style::BoxSizing::ContentBox,
90 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
91 margin: taffy::geometry::Rect { left: zero(), right: zero(), top: length(10f32), bottom: length(10f32) },
92 ..Default::default()
93 })
94 .unwrap();
95 let node1 = taffy
96 .new_leaf(taffy::style::Style {
97 box_sizing: taffy::style::BoxSizing::ContentBox,
98 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
99 margin: taffy::geometry::Rect { left: zero(), right: zero(), top: length(10f32), bottom: length(10f32) },
100 ..Default::default()
101 })
102 .unwrap();
103 let node2 = taffy
104 .new_leaf(taffy::style::Style {
105 box_sizing: taffy::style::BoxSizing::ContentBox,
106 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
107 margin: taffy::geometry::Rect { left: zero(), right: zero(), top: length(5f32), bottom: length(5f32) },
108 ..Default::default()
109 })
110 .unwrap();
111 let node3 = taffy
112 .new_leaf(taffy::style::Style {
113 box_sizing: taffy::style::BoxSizing::ContentBox,
114 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
115 margin: taffy::geometry::Rect { left: zero(), right: zero(), top: length(10f32), bottom: length(10f32) },
116 ..Default::default()
117 })
118 .unwrap();
119 let node = taffy
120 .new_with_children(
121 taffy::style::Style {
122 display: taffy::style::Display::Block,
123 box_sizing: taffy::style::BoxSizing::ContentBox,
124 size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
125 ..Default::default()
126 },
127 &[node0, node1, node2, node3],
128 )
129 .unwrap();
130 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
131 println!("\nComputed tree:");
132 taffy.print_tree(node);
133 println!();
134 let layout = taffy.layout(node).unwrap();
135 let Layout { size, location, .. } = layout;
136 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
137 assert_eq!(size.height, 90f32, "height of node {:?}. Expected {}. Actual {}", node, 90f32, size.height);
138 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
139 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
140 let layout = taffy.layout(node0).unwrap();
141 let Layout { size, location, .. } = layout;
142 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
143 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
144 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
145 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node0, 10f32, location.y);
146 let layout = taffy.layout(node1).unwrap();
147 let Layout { size, location, .. } = layout;
148 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
149 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
150 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
151 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node1, 30f32, location.y);
152 let layout = taffy.layout(node2).unwrap();
153 let Layout { size, location, .. } = layout;
154 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
155 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height);
156 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
157 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node2, 50f32, location.y);
158 let layout = taffy.layout(node3).unwrap();
159 let Layout { size, location, .. } = layout;
160 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
161 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height);
162 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
163 assert_eq!(location.y, 70f32, "y of node {:?}. Expected {}. Actual {}", node3, 70f32, location.y);
164}