⎇ 25571b5d07206880207e451af69dd3b49b113628
tests/generated/flex/multiline_min_max_5.rs
Historia
Quién tocó qué
crudo
Fix resolving flexible lengths (WPT css/flexbox-multiline-min-max test) (#692)
1#[test]
2#[allow(non_snake_case)]
3fn multiline_min_max_5__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, tree::Layout, TaffyTree};
6 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
7 let node0 = taffy
8 .new_leaf(taffy::style::Style {
9 box_sizing: taffy::style::BoxSizing::ContentBox,
10 flex_grow: 1f32,
11 flex_shrink: 1f32,
12 flex_basis: taffy::style::Dimension::Length(600f32),
13 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
14 max_size: taffy::geometry::Size { width: taffy::style::Dimension::Length(300f32), height: auto() },
15 ..Default::default()
16 })
17 .unwrap();
18 let node1 = taffy
19 .new_leaf(taffy::style::Style {
20 box_sizing: taffy::style::BoxSizing::ContentBox,
21 flex_grow: 1f32,
22 flex_shrink: 1f32,
23 flex_basis: taffy::style::Dimension::Auto,
24 size: taffy::geometry::Size {
25 width: taffy::style::Dimension::Length(100f32),
26 height: taffy::style::Dimension::Length(10f32),
27 },
28 ..Default::default()
29 })
30 .unwrap();
31 let node2 = taffy
32 .new_leaf(taffy::style::Style {
33 box_sizing: taffy::style::BoxSizing::ContentBox,
34 flex_grow: 1f32,
35 flex_shrink: 1f32,
36 flex_basis: taffy::style::Dimension::Auto,
37 size: taffy::geometry::Size {
38 width: taffy::style::Dimension::Length(100f32),
39 height: taffy::style::Dimension::Length(10f32),
40 },
41 ..Default::default()
42 })
43 .unwrap();
44 let node3 = taffy
45 .new_leaf(taffy::style::Style {
46 box_sizing: taffy::style::BoxSizing::ContentBox,
47 flex_grow: 1f32,
48 flex_shrink: 1f32,
49 flex_basis: taffy::style::Dimension::Auto,
50 size: taffy::geometry::Size {
51 width: taffy::style::Dimension::Length(100f32),
52 height: taffy::style::Dimension::Length(10f32),
53 },
54 ..Default::default()
55 })
56 .unwrap();
57 let node = taffy
58 .new_with_children(
59 taffy::style::Style {
60 display: taffy::style::Display::Flex,
61 box_sizing: taffy::style::BoxSizing::ContentBox,
62 flex_wrap: taffy::style::FlexWrap::Wrap,
63 size: taffy::geometry::Size {
64 width: taffy::style::Dimension::Length(600f32),
65 height: taffy::style::Dimension::Length(20f32),
66 },
67 border: taffy::geometry::Rect {
68 left: taffy::style::LengthPercentage::Length(5f32),
69 right: taffy::style::LengthPercentage::Length(5f32),
70 top: taffy::style::LengthPercentage::Length(5f32),
71 bottom: taffy::style::LengthPercentage::Length(5f32),
72 },
73 ..Default::default()
74 },
75 &[node0, node1, node2, node3],
76 )
77 .unwrap();
78 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
79 println!("\nComputed tree:");
80 taffy.print_tree(node);
81 println!();
82 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
83 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
84 assert_eq!(size.width, 610f32, "width of node {:?}. Expected {}. Actual {}", node, 610f32, size.width);
85 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node, 30f32, size.height);
86 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
87 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
88 #[cfg(feature = "content_size")]
89 assert_eq!(
90 layout.scroll_width(),
91 0f32,
92 "scroll_width of node {:?}. Expected {}. Actual {}",
93 node,
94 0f32,
95 layout.scroll_width()
96 );
97 #[cfg(feature = "content_size")]
98 assert_eq!(
99 layout.scroll_height(),
100 0f32,
101 "scroll_height of node {:?}. Expected {}. Actual {}",
102 node,
103 0f32,
104 layout.scroll_height()
105 );
106 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
107 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
108 assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node0, 300f32, size.width);
109 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
110 assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x);
111 assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y);
112 #[cfg(feature = "content_size")]
113 assert_eq!(
114 layout.scroll_width(),
115 0f32,
116 "scroll_width of node {:?}. Expected {}. Actual {}",
117 node0,
118 0f32,
119 layout.scroll_width()
120 );
121 #[cfg(feature = "content_size")]
122 assert_eq!(
123 layout.scroll_height(),
124 0f32,
125 "scroll_height of node {:?}. Expected {}. Actual {}",
126 node0,
127 0f32,
128 layout.scroll_height()
129 );
130 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
131 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
132 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width);
133 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
134 assert_eq!(location.x, 305f32, "x of node {:?}. Expected {}. Actual {}", node1, 305f32, location.x);
135 assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node1, 5f32, location.y);
136 #[cfg(feature = "content_size")]
137 assert_eq!(
138 layout.scroll_width(),
139 0f32,
140 "scroll_width of node {:?}. Expected {}. Actual {}",
141 node1,
142 0f32,
143 layout.scroll_width()
144 );
145 #[cfg(feature = "content_size")]
146 assert_eq!(
147 layout.scroll_height(),
148 0f32,
149 "scroll_height of node {:?}. Expected {}. Actual {}",
150 node1,
151 0f32,
152 layout.scroll_height()
153 );
154 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
155 let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
156 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node2, 100f32, size.width);
157 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height);
158 assert_eq!(location.x, 405f32, "x of node {:?}. Expected {}. Actual {}", node2, 405f32, location.x);
159 assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node2, 5f32, location.y);
160 #[cfg(feature = "content_size")]
161 assert_eq!(
162 layout.scroll_width(),
163 0f32,
164 "scroll_width of node {:?}. Expected {}. Actual {}",
165 node2,
166 0f32,
167 layout.scroll_width()
168 );
169 #[cfg(feature = "content_size")]
170 assert_eq!(
171 layout.scroll_height(),
172 0f32,
173 "scroll_height of node {:?}. Expected {}. Actual {}",
174 node2,
175 0f32,
176 layout.scroll_height()
177 );
178 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
179 let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap();
180 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node3, 100f32, size.width);
181 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height);
182 assert_eq!(location.x, 505f32, "x of node {:?}. Expected {}. Actual {}", node3, 505f32, location.x);
183 assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node3, 5f32, location.y);
184 #[cfg(feature = "content_size")]
185 assert_eq!(
186 layout.scroll_width(),
187 0f32,
188 "scroll_width of node {:?}. Expected {}. Actual {}",
189 node3,
190 0f32,
191 layout.scroll_width()
192 );
193 #[cfg(feature = "content_size")]
194 assert_eq!(
195 layout.scroll_height(),
196 0f32,
197 "scroll_height of node {:?}. Expected {}. Actual {}",
198 node3,
199 0f32,
200 layout.scroll_height()
201 );
202}
203
204#[test]
205#[allow(non_snake_case)]
206fn multiline_min_max_5__content_box() {
207 #[allow(unused_imports)]
208 use taffy::{prelude::*, tree::Layout, TaffyTree};
209 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
210 let node0 = taffy
211 .new_leaf(taffy::style::Style {
212 box_sizing: taffy::style::BoxSizing::ContentBox,
213 flex_grow: 1f32,
214 flex_shrink: 1f32,
215 flex_basis: taffy::style::Dimension::Length(600f32),
216 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
217 max_size: taffy::geometry::Size { width: taffy::style::Dimension::Length(300f32), height: auto() },
218 ..Default::default()
219 })
220 .unwrap();
221 let node1 = taffy
222 .new_leaf(taffy::style::Style {
223 box_sizing: taffy::style::BoxSizing::ContentBox,
224 flex_grow: 1f32,
225 flex_shrink: 1f32,
226 flex_basis: taffy::style::Dimension::Auto,
227 size: taffy::geometry::Size {
228 width: taffy::style::Dimension::Length(100f32),
229 height: taffy::style::Dimension::Length(10f32),
230 },
231 ..Default::default()
232 })
233 .unwrap();
234 let node2 = taffy
235 .new_leaf(taffy::style::Style {
236 box_sizing: taffy::style::BoxSizing::ContentBox,
237 flex_grow: 1f32,
238 flex_shrink: 1f32,
239 flex_basis: taffy::style::Dimension::Auto,
240 size: taffy::geometry::Size {
241 width: taffy::style::Dimension::Length(100f32),
242 height: taffy::style::Dimension::Length(10f32),
243 },
244 ..Default::default()
245 })
246 .unwrap();
247 let node3 = taffy
248 .new_leaf(taffy::style::Style {
249 box_sizing: taffy::style::BoxSizing::ContentBox,
250 flex_grow: 1f32,
251 flex_shrink: 1f32,
252 flex_basis: taffy::style::Dimension::Auto,
253 size: taffy::geometry::Size {
254 width: taffy::style::Dimension::Length(100f32),
255 height: taffy::style::Dimension::Length(10f32),
256 },
257 ..Default::default()
258 })
259 .unwrap();
260 let node = taffy
261 .new_with_children(
262 taffy::style::Style {
263 display: taffy::style::Display::Flex,
264 box_sizing: taffy::style::BoxSizing::ContentBox,
265 flex_wrap: taffy::style::FlexWrap::Wrap,
266 size: taffy::geometry::Size {
267 width: taffy::style::Dimension::Length(600f32),
268 height: taffy::style::Dimension::Length(20f32),
269 },
270 border: taffy::geometry::Rect {
271 left: taffy::style::LengthPercentage::Length(5f32),
272 right: taffy::style::LengthPercentage::Length(5f32),
273 top: taffy::style::LengthPercentage::Length(5f32),
274 bottom: taffy::style::LengthPercentage::Length(5f32),
275 },
276 ..Default::default()
277 },
278 &[node0, node1, node2, node3],
279 )
280 .unwrap();
281 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
282 println!("\nComputed tree:");
283 taffy.print_tree(node);
284 println!();
285 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
286 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
287 assert_eq!(size.width, 610f32, "width of node {:?}. Expected {}. Actual {}", node, 610f32, size.width);
288 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node, 30f32, size.height);
289 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
290 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
291 #[cfg(feature = "content_size")]
292 assert_eq!(
293 layout.scroll_width(),
294 0f32,
295 "scroll_width of node {:?}. Expected {}. Actual {}",
296 node,
297 0f32,
298 layout.scroll_width()
299 );
300 #[cfg(feature = "content_size")]
301 assert_eq!(
302 layout.scroll_height(),
303 0f32,
304 "scroll_height of node {:?}. Expected {}. Actual {}",
305 node,
306 0f32,
307 layout.scroll_height()
308 );
309 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
310 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
311 assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node0, 300f32, size.width);
312 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
313 assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x);
314 assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y);
315 #[cfg(feature = "content_size")]
316 assert_eq!(
317 layout.scroll_width(),
318 0f32,
319 "scroll_width of node {:?}. Expected {}. Actual {}",
320 node0,
321 0f32,
322 layout.scroll_width()
323 );
324 #[cfg(feature = "content_size")]
325 assert_eq!(
326 layout.scroll_height(),
327 0f32,
328 "scroll_height of node {:?}. Expected {}. Actual {}",
329 node0,
330 0f32,
331 layout.scroll_height()
332 );
333 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
334 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
335 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width);
336 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
337 assert_eq!(location.x, 305f32, "x of node {:?}. Expected {}. Actual {}", node1, 305f32, location.x);
338 assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node1, 5f32, location.y);
339 #[cfg(feature = "content_size")]
340 assert_eq!(
341 layout.scroll_width(),
342 0f32,
343 "scroll_width of node {:?}. Expected {}. Actual {}",
344 node1,
345 0f32,
346 layout.scroll_width()
347 );
348 #[cfg(feature = "content_size")]
349 assert_eq!(
350 layout.scroll_height(),
351 0f32,
352 "scroll_height of node {:?}. Expected {}. Actual {}",
353 node1,
354 0f32,
355 layout.scroll_height()
356 );
357 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
358 let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
359 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node2, 100f32, size.width);
360 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height);
361 assert_eq!(location.x, 405f32, "x of node {:?}. Expected {}. Actual {}", node2, 405f32, location.x);
362 assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node2, 5f32, location.y);
363 #[cfg(feature = "content_size")]
364 assert_eq!(
365 layout.scroll_width(),
366 0f32,
367 "scroll_width of node {:?}. Expected {}. Actual {}",
368 node2,
369 0f32,
370 layout.scroll_width()
371 );
372 #[cfg(feature = "content_size")]
373 assert_eq!(
374 layout.scroll_height(),
375 0f32,
376 "scroll_height of node {:?}. Expected {}. Actual {}",
377 node2,
378 0f32,
379 layout.scroll_height()
380 );
381 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
382 let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap();
383 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node3, 100f32, size.width);
384 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height);
385 assert_eq!(location.x, 505f32, "x of node {:?}. Expected {}. Actual {}", node3, 505f32, location.x);
386 assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node3, 5f32, location.y);
387 #[cfg(feature = "content_size")]
388 assert_eq!(
389 layout.scroll_width(),
390 0f32,
391 "scroll_width of node {:?}. Expected {}. Actual {}",
392 node3,
393 0f32,
394 layout.scroll_width()
395 );
396 #[cfg(feature = "content_size")]
397 assert_eq!(
398 layout.scroll_height(),
399 0f32,
400 "scroll_height of node {:?}. Expected {}. Actual {}",
401 node3,
402 0f32,
403 layout.scroll_height()
404 );
405}