⎇ float-layout
tests/generated/grid/grid_span_6_all_non_flex_indefinite.rs
Historia
Quién tocó qué
crudo
Add `taffy_test_helpers` crate (#755)
1#[test]
2#[allow(non_snake_case)]
3fn grid_span_6_all_non_flex_indefinite__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_with_context(
9 taffy::style::Style {
10 grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Span(6u16) },
11 ..Default::default()
12 },
13 crate::TestNodeContext::ahem_text("HHHHHHHH\u{200b}HHHHHHHH", crate::WritingMode::Horizontal),
14 )
15 .unwrap();
16 let node1 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
17 let node2 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
18 let node3 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
19 let node4 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
20 let node5 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
21 let node6 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
22 let node = taffy
23 .new_with_children(
24 taffy::style::Style {
25 display: taffy::style::Display::Grid,
26 grid_template_rows: vec![length(40f32), length(40f32)],
27 grid_template_columns: vec![
28 min_content(),
29 max_content(),
30 fit_content(length(20f32)),
31 auto(),
32 length(10f32),
33 percent(0.2f32),
34 ],
35 ..Default::default()
36 },
37 &[node0, node1, node2, node3, node4, node5, node6],
38 )
39 .unwrap();
40 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
41 println!("\nComputed tree:");
42 taffy.print_tree(node);
43 println!();
44 let layout = taffy.layout(node).unwrap();
45 let Layout { size, location, .. } = layout;
46 assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node, 160f32, size.width);
47 assert_eq!(size.height, 80f32, "height of node {:?}. Expected {}. Actual {}", node, 80f32, size.height);
48 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
49 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
50 let layout = taffy.layout(node0).unwrap();
51 let Layout { size, location, .. } = layout;
52 assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node0, 160f32, size.width);
53 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
54 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
55 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
56 let layout = taffy.layout(node1).unwrap();
57 let Layout { size, location, .. } = layout;
58 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node1, 10f32, size.width);
59 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1, 40f32, size.height);
60 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
61 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1, 40f32, location.y);
62 let layout = taffy.layout(node2).unwrap();
63 let Layout { size, location, .. } = layout;
64 assert_eq!(size.width, 89f32, "width of node {:?}. Expected {}. Actual {}", node2, 89f32, size.width);
65 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node2, 40f32, size.height);
66 assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node2, 10f32, location.x);
67 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node2, 40f32, location.y);
68 let layout = taffy.layout(node3).unwrap();
69 let Layout { size, location, .. } = layout;
70 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node3, 10f32, size.width);
71 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node3, 40f32, size.height);
72 assert_eq!(location.x, 99f32, "x of node {:?}. Expected {}. Actual {}", node3, 99f32, location.x);
73 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node3, 40f32, location.y);
74 let layout = taffy.layout(node4).unwrap();
75 let Layout { size, location, .. } = layout;
76 assert_eq!(size.width, 9f32, "width of node {:?}. Expected {}. Actual {}", node4, 9f32, size.width);
77 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node4, 40f32, size.height);
78 assert_eq!(location.x, 109f32, "x of node {:?}. Expected {}. Actual {}", node4, 109f32, location.x);
79 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node4, 40f32, location.y);
80 let layout = taffy.layout(node5).unwrap();
81 let Layout { size, location, .. } = layout;
82 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node5, 10f32, size.width);
83 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node5, 40f32, size.height);
84 assert_eq!(location.x, 118f32, "x of node {:?}. Expected {}. Actual {}", node5, 118f32, location.x);
85 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node5, 40f32, location.y);
86 let layout = taffy.layout(node6).unwrap();
87 let Layout { size, location, .. } = layout;
88 assert_eq!(size.width, 32f32, "width of node {:?}. Expected {}. Actual {}", node6, 32f32, size.width);
89 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node6, 40f32, size.height);
90 assert_eq!(location.x, 128f32, "x of node {:?}. Expected {}. Actual {}", node6, 128f32, location.x);
91 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node6, 40f32, location.y);
92}
93
94#[test]
95#[allow(non_snake_case)]
96fn grid_span_6_all_non_flex_indefinite__content_box() {
97 #[allow(unused_imports)]
98 use taffy::{prelude::*, Layout};
99 let mut taffy = crate::new_test_tree();
100 let node0 = taffy
101 .new_leaf_with_context(
102 taffy::style::Style {
103 box_sizing: taffy::style::BoxSizing::ContentBox,
104 grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Span(6u16) },
105 ..Default::default()
106 },
107 crate::TestNodeContext::ahem_text("HHHHHHHH\u{200b}HHHHHHHH", crate::WritingMode::Horizontal),
108 )
109 .unwrap();
110 let node1 = taffy
111 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
112 .unwrap();
113 let node2 = taffy
114 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
115 .unwrap();
116 let node3 = taffy
117 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
118 .unwrap();
119 let node4 = taffy
120 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
121 .unwrap();
122 let node5 = taffy
123 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
124 .unwrap();
125 let node6 = taffy
126 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
127 .unwrap();
128 let node = taffy
129 .new_with_children(
130 taffy::style::Style {
131 display: taffy::style::Display::Grid,
132 box_sizing: taffy::style::BoxSizing::ContentBox,
133 grid_template_rows: vec![length(40f32), length(40f32)],
134 grid_template_columns: vec![
135 min_content(),
136 max_content(),
137 fit_content(length(20f32)),
138 auto(),
139 length(10f32),
140 percent(0.2f32),
141 ],
142 ..Default::default()
143 },
144 &[node0, node1, node2, node3, node4, node5, node6],
145 )
146 .unwrap();
147 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
148 println!("\nComputed tree:");
149 taffy.print_tree(node);
150 println!();
151 let layout = taffy.layout(node).unwrap();
152 let Layout { size, location, .. } = layout;
153 assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node, 160f32, size.width);
154 assert_eq!(size.height, 80f32, "height of node {:?}. Expected {}. Actual {}", node, 80f32, size.height);
155 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
156 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
157 let layout = taffy.layout(node0).unwrap();
158 let Layout { size, location, .. } = layout;
159 assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node0, 160f32, size.width);
160 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
161 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
162 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
163 let layout = taffy.layout(node1).unwrap();
164 let Layout { size, location, .. } = layout;
165 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node1, 10f32, size.width);
166 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1, 40f32, size.height);
167 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
168 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1, 40f32, location.y);
169 let layout = taffy.layout(node2).unwrap();
170 let Layout { size, location, .. } = layout;
171 assert_eq!(size.width, 89f32, "width of node {:?}. Expected {}. Actual {}", node2, 89f32, size.width);
172 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node2, 40f32, size.height);
173 assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node2, 10f32, location.x);
174 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node2, 40f32, location.y);
175 let layout = taffy.layout(node3).unwrap();
176 let Layout { size, location, .. } = layout;
177 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node3, 10f32, size.width);
178 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node3, 40f32, size.height);
179 assert_eq!(location.x, 99f32, "x of node {:?}. Expected {}. Actual {}", node3, 99f32, location.x);
180 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node3, 40f32, location.y);
181 let layout = taffy.layout(node4).unwrap();
182 let Layout { size, location, .. } = layout;
183 assert_eq!(size.width, 9f32, "width of node {:?}. Expected {}. Actual {}", node4, 9f32, size.width);
184 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node4, 40f32, size.height);
185 assert_eq!(location.x, 109f32, "x of node {:?}. Expected {}. Actual {}", node4, 109f32, location.x);
186 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node4, 40f32, location.y);
187 let layout = taffy.layout(node5).unwrap();
188 let Layout { size, location, .. } = layout;
189 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node5, 10f32, size.width);
190 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node5, 40f32, size.height);
191 assert_eq!(location.x, 118f32, "x of node {:?}. Expected {}. Actual {}", node5, 118f32, location.x);
192 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node5, 40f32, location.y);
193 let layout = taffy.layout(node6).unwrap();
194 let Layout { size, location, .. } = layout;
195 assert_eq!(size.width, 32f32, "width of node {:?}. Expected {}. Actual {}", node6, 32f32, size.width);
196 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node6, 40f32, size.height);
197 assert_eq!(location.x, 128f32, "x of node {:?}. Expected {}. Actual {}", node6, 128f32, location.x);
198 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node6, 40f32, location.y);
199}