tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 9TOML 3CSS 1345 Sutichaykuna

⎇ ba1f724e14c7014b087175289197f83a1dbf52e8 tests/generated.rs Rust · 7885 siq'ikuna · 305.2 KB Ñawpa willay Pi imata llamkarqan ch'uya

Migrate tests from yoga ba1f724e1 · Emil Sjölander ·

1#[cfg(test)]
2mod generated {
3    #[test]
4    fn justify_content_row_space_around() {
5        let layout = stretch::compute(&stretch::style::Node {
6            justify_content: stretch::style::JustifyContent::SpaceAround,
7            width: stretch::style::Dimension::Points(100.0),
8            height: stretch::style::Dimension::Points(100.0),
9            children: vec![
10                stretch::style::Node {
11                    width: stretch::style::Dimension::Points(10.0),
12                    ..Default::default()
13                },
14                stretch::style::Node {
15                    width: stretch::style::Dimension::Points(10.0),
16                    ..Default::default()
17                },
18                stretch::style::Node {
19                    width: stretch::style::Dimension::Points(10.0),
20                    ..Default::default()
21                },
22            ],
23            ..Default::default()
24        });
25
26        assert_eq!(layout.width, 100.0);
27        assert_eq!(layout.height, 100.0);
28        assert_eq!(layout.x, 0.0);
29        assert_eq!(layout.y, 0.0);
30
31        assert_eq!(layout.children[0].width, 10.0);
32        assert_eq!(layout.children[0].height, 100.0);
33        assert_eq!(layout.children[0].x, 12.0);
34        assert_eq!(layout.children[0].y, 0.0);
35
36        assert_eq!(layout.children[1].width, 10.0);
37        assert_eq!(layout.children[1].height, 100.0);
38        assert_eq!(layout.children[1].x, 45.0);
39        assert_eq!(layout.children[1].y, 0.0);
40
41        assert_eq!(layout.children[2].width, 10.0);
42        assert_eq!(layout.children[2].height, 100.0);
43        assert_eq!(layout.children[2].x, 78.0);
44        assert_eq!(layout.children[2].y, 0.0);
45    }
46
47    #[test]
48    fn align_items_center() {
49        let layout = stretch::compute(&stretch::style::Node {
50            align_items: stretch::style::AlignItems::Center,
51            width: stretch::style::Dimension::Points(100.0),
52            height: stretch::style::Dimension::Points(100.0),
53            children: vec![stretch::style::Node {
54                width: stretch::style::Dimension::Points(10.0),
55                height: stretch::style::Dimension::Points(10.0),
56                ..Default::default()
57            }],
58            ..Default::default()
59        });
60
61        assert_eq!(layout.width, 100.0);
62        assert_eq!(layout.height, 100.0);
63        assert_eq!(layout.x, 0.0);
64        assert_eq!(layout.y, 0.0);
65
66        assert_eq!(layout.children[0].width, 10.0);
67        assert_eq!(layout.children[0].height, 10.0);
68        assert_eq!(layout.children[0].x, 0.0);
69        assert_eq!(layout.children[0].y, 45.0);
70    }
71
72    #[test]
73    fn absolute_layout_justify_content_center() {
74        let layout = stretch::compute(&stretch::style::Node {
75            justify_content: stretch::style::JustifyContent::Center,
76            width: stretch::style::Dimension::Points(110.0),
77            height: stretch::style::Dimension::Points(100.0),
78            children: vec![stretch::style::Node {
79                position: stretch::style::Position::Absolute,
80                width: stretch::style::Dimension::Points(60.0),
81                height: stretch::style::Dimension::Points(40.0),
82                ..Default::default()
83            }],
84            ..Default::default()
85        });
86
87        assert_eq!(layout.width, 110.0);
88        assert_eq!(layout.height, 100.0);
89        assert_eq!(layout.x, 0.0);
90        assert_eq!(layout.y, 0.0);
91
92        assert_eq!(layout.children[0].width, 60.0);
93        assert_eq!(layout.children[0].height, 40.0);
94        assert_eq!(layout.children[0].x, 25.0);
95        assert_eq!(layout.children[0].y, 0.0);
96    }
97
98    #[test]
99    fn margin_auto_bottom_and_top() {
100        let layout = stretch::compute(&stretch::style::Node {
101            align_items: stretch::style::AlignItems::Center,
102            width: stretch::style::Dimension::Points(200.0),
103            height: stretch::style::Dimension::Points(200.0),
104            children: vec![
105                stretch::style::Node {
106                    width: stretch::style::Dimension::Points(50.0),
107                    height: stretch::style::Dimension::Points(50.0),
108                    margin: stretch::style::Edges {
109                        top: stretch::style::Dimension::Auto,
110                        bottom: stretch::style::Dimension::Auto,
111                        ..Default::default()
112                    },
113                    ..Default::default()
114                },
115                stretch::style::Node {
116                    width: stretch::style::Dimension::Points(50.0),
117                    height: stretch::style::Dimension::Points(50.0),
118                    ..Default::default()
119                },
120            ],
121            ..Default::default()
122        });
123
124        assert_eq!(layout.width, 200.0);
125        assert_eq!(layout.height, 200.0);
126        assert_eq!(layout.x, 0.0);
127        assert_eq!(layout.y, 0.0);
128
129        assert_eq!(layout.children[0].width, 50.0);
130        assert_eq!(layout.children[0].height, 50.0);
131        assert_eq!(layout.children[0].x, 0.0);
132        assert_eq!(layout.children[0].y, 75.0);
133
134        assert_eq!(layout.children[1].width, 50.0);
135        assert_eq!(layout.children[1].height, 50.0);
136        assert_eq!(layout.children[1].x, 50.0);
137        assert_eq!(layout.children[1].y, 75.0);
138    }
139
140    #[test]
141    fn margin_auto_left_and_right_strech() {
142        let layout = stretch::compute(&stretch::style::Node {
143            width: stretch::style::Dimension::Points(200.0),
144            height: stretch::style::Dimension::Points(200.0),
145            children: vec![
146                stretch::style::Node {
147                    width: stretch::style::Dimension::Points(50.0),
148                    height: stretch::style::Dimension::Points(50.0),
149                    margin: stretch::style::Edges {
150                        start: stretch::style::Dimension::Auto,
151                        end: stretch::style::Dimension::Auto,
152                        ..Default::default()
153                    },
154                    ..Default::default()
155                },
156                stretch::style::Node {
157                    width: stretch::style::Dimension::Points(50.0),
158                    height: stretch::style::Dimension::Points(50.0),
159                    ..Default::default()
160                },
161            ],
162            ..Default::default()
163        });
164
165        assert_eq!(layout.width, 200.0);
166        assert_eq!(layout.height, 200.0);
167        assert_eq!(layout.x, 0.0);
168        assert_eq!(layout.y, 0.0);
169
170        assert_eq!(layout.children[0].width, 50.0);
171        assert_eq!(layout.children[0].height, 50.0);
172        assert_eq!(layout.children[0].x, 50.0);
173        assert_eq!(layout.children[0].y, 0.0);
174
175        assert_eq!(layout.children[1].width, 50.0);
176        assert_eq!(layout.children[1].height, 50.0);
177        assert_eq!(layout.children[1].x, 150.0);
178        assert_eq!(layout.children[1].y, 0.0);
179    }
180
181    #[test]
182    fn rounding_flex_basis_overrides_main_size() {
183        let layout = stretch::compute(&stretch::style::Node {
184            flex_direction: stretch::style::FlexDirection::Column,
185            width: stretch::style::Dimension::Points(100.0),
186            height: stretch::style::Dimension::Points(113.0),
187            children: vec![
188                stretch::style::Node {
189                    flex_grow: 1.0,
190                    flex_basis: stretch::style::Dimension::Points(50.0),
191                    height: stretch::style::Dimension::Points(20.0),
192                    ..Default::default()
193                },
194                stretch::style::Node {
195                    flex_grow: 1.0,
196                    height: stretch::style::Dimension::Points(10.0),
197                    ..Default::default()
198                },
199                stretch::style::Node {
200                    flex_grow: 1.0,
201                    height: stretch::style::Dimension::Points(10.0),
202                    ..Default::default()
203                },
204            ],
205            ..Default::default()
206        });
207
208        assert_eq!(layout.width, 100.0);
209        assert_eq!(layout.height, 113.0);
210        assert_eq!(layout.x, 0.0);
211        assert_eq!(layout.y, 0.0);
212
213        assert_eq!(layout.children[0].width, 100.0);
214        assert_eq!(layout.children[0].height, 64.0);
215        assert_eq!(layout.children[0].x, 0.0);
216        assert_eq!(layout.children[0].y, 0.0);
217
218        assert_eq!(layout.children[1].width, 100.0);
219        assert_eq!(layout.children[1].height, 25.0);
220        assert_eq!(layout.children[1].x, 0.0);
221        assert_eq!(layout.children[1].y, 64.0);
222
223        assert_eq!(layout.children[2].width, 100.0);
224        assert_eq!(layout.children[2].height, 24.0);
225        assert_eq!(layout.children[2].x, 0.0);
226        assert_eq!(layout.children[2].y, 89.0);
227    }
228
229    #[test]
230    fn percentage_flex_basis() {
231        let layout = stretch::compute(&stretch::style::Node {
232            width: stretch::style::Dimension::Points(200.0),
233            height: stretch::style::Dimension::Points(200.0),
234            children: vec![
235                stretch::style::Node {
236                    flex_grow: 1.0,
237                    flex_basis: stretch::style::Dimension::Percent(0.5),
238                    ..Default::default()
239                },
240                stretch::style::Node {
241                    flex_grow: 1.0,
242                    flex_basis: stretch::style::Dimension::Percent(0.2),
243                    ..Default::default()
244                },
245            ],
246            ..Default::default()
247        });
248
249        assert_eq!(layout.width, 200.0);
250        assert_eq!(layout.height, 200.0);
251        assert_eq!(layout.x, 0.0);
252        assert_eq!(layout.y, 0.0);
253
254        assert_eq!(layout.children[0].width, 125.0);
255        assert_eq!(layout.children[0].height, 200.0);
256        assert_eq!(layout.children[0].x, 0.0);
257        assert_eq!(layout.children[0].y, 0.0);
258
259        assert_eq!(layout.children[1].width, 75.0);
260        assert_eq!(layout.children[1].height, 200.0);
261        assert_eq!(layout.children[1].x, 125.0);
262        assert_eq!(layout.children[1].y, 0.0);
263    }
264
265    #[test]
266    fn rounding_fractial_input_3() {
267        let layout = stretch::compute(&stretch::style::Node {
268            flex_direction: stretch::style::FlexDirection::Column,
269            width: stretch::style::Dimension::Points(100.0),
270            height: stretch::style::Dimension::Points(113.4),
271            children: vec![
272                stretch::style::Node {
273                    flex_grow: 1.0,
274                    flex_basis: stretch::style::Dimension::Points(50.0),
275                    height: stretch::style::Dimension::Points(20.0),
276                    ..Default::default()
277                },
278                stretch::style::Node {
279                    flex_grow: 1.0,
280                    height: stretch::style::Dimension::Points(10.0),
281                    ..Default::default()
282                },
283                stretch::style::Node {
284                    flex_grow: 1.0,
285                    height: stretch::style::Dimension::Points(10.0),
286                    ..Default::default()
287                },
288            ],
289            ..Default::default()
290        });
291
292        assert_eq!(layout.width, 100.0);
293        assert_eq!(layout.height, 113.0);
294        assert_eq!(layout.x, 0.0);
295        assert_eq!(layout.y, 0.0);
296
297        assert_eq!(layout.children[0].width, 100.0);
298        assert_eq!(layout.children[0].height, 64.0);
299        assert_eq!(layout.children[0].x, 0.0);
300        assert_eq!(layout.children[0].y, 0.0);
301
302        assert_eq!(layout.children[1].width, 100.0);
303        assert_eq!(layout.children[1].height, 25.0);
304        assert_eq!(layout.children[1].x, 0.0);
305        assert_eq!(layout.children[1].y, 64.0);
306
307        assert_eq!(layout.children[2].width, 100.0);
308        assert_eq!(layout.children[2].height, 24.0);
309        assert_eq!(layout.children[2].x, 0.0);
310        assert_eq!(layout.children[2].y, 89.0);
311    }
312
313    #[test]
314    fn margin_and_stretch_column() {
315        let layout = stretch::compute(&stretch::style::Node {
316            flex_direction: stretch::style::FlexDirection::Column,
317            width: stretch::style::Dimension::Points(100.0),
318            height: stretch::style::Dimension::Points(100.0),
319            children: vec![stretch::style::Node {
320                flex_grow: 1.0,
321                margin: stretch::style::Edges {
322                    start: stretch::style::Dimension::Points(10.0),
323                    end: stretch::style::Dimension::Points(10.0),
324                    ..Default::default()
325                },
326                ..Default::default()
327            }],
328            ..Default::default()
329        });
330
331        assert_eq!(layout.width, 100.0);
332        assert_eq!(layout.height, 100.0);
333        assert_eq!(layout.x, 0.0);
334        assert_eq!(layout.y, 0.0);
335
336        assert_eq!(layout.children[0].width, 80.0);
337        assert_eq!(layout.children[0].height, 100.0);
338        assert_eq!(layout.children[0].x, 10.0);
339        assert_eq!(layout.children[0].y, 0.0);
340    }
341
342    #[test]
343    fn wrapped_column_max_height_flex() {
344        let layout = stretch::compute(&stretch::style::Node {
345            flex_direction: stretch::style::FlexDirection::Column,
346            align_items: stretch::style::AlignItems::Center,
347            align_content: stretch::style::AlignContent::Center,
348            justify_content: stretch::style::JustifyContent::Center,
349            width: stretch::style::Dimension::Points(700.0),
350            height: stretch::style::Dimension::Points(500.0),
351            children: vec![
352                stretch::style::Node {
353                    flex_grow: 1.0,
354                    flex_shrink: 1.0,
355                    flex_basis: stretch::style::Dimension::Percent(0.0),
356                    width: stretch::style::Dimension::Points(100.0),
357                    height: stretch::style::Dimension::Points(500.0),
358                    max_height: stretch::style::Dimension::Points(200.0),
359                    ..Default::default()
360                },
361                stretch::style::Node {
362                    flex_grow: 1.0,
363                    flex_shrink: 1.0,
364                    flex_basis: stretch::style::Dimension::Percent(0.0),
365                    width: stretch::style::Dimension::Points(200.0),
366                    height: stretch::style::Dimension::Points(200.0),
367                    margin: stretch::style::Edges {
368                        start: stretch::style::Dimension::Points(20.0),
369                        end: stretch::style::Dimension::Points(20.0),
370                        top: stretch::style::Dimension::Points(20.0),
371                        bottom: stretch::style::Dimension::Points(20.0),
372                        ..Default::default()
373                    },
374                    ..Default::default()
375                },
376                stretch::style::Node {
377                    width: stretch::style::Dimension::Points(100.0),
378                    height: stretch::style::Dimension::Points(100.0),
379                    ..Default::default()
380                },
381            ],
382            ..Default::default()
383        });
384
385        assert_eq!(layout.width, 700.0);
386        assert_eq!(layout.height, 500.0);
387        assert_eq!(layout.x, 0.0);
388        assert_eq!(layout.y, 0.0);
389
390        assert_eq!(layout.children[0].width, 100.0);
391        assert_eq!(layout.children[0].height, 180.0);
392        assert_eq!(layout.children[0].x, 300.0);
393        assert_eq!(layout.children[0].y, 0.0);
394
395        assert_eq!(layout.children[1].width, 200.0);
396        assert_eq!(layout.children[1].height, 180.0);
397        assert_eq!(layout.children[1].x, 250.0);
398        assert_eq!(layout.children[1].y, 200.0);
399
400        assert_eq!(layout.children[2].width, 100.0);
401        assert_eq!(layout.children[2].height, 100.0);
402        assert_eq!(layout.children[2].x, 300.0);
403        assert_eq!(layout.children[2].y, 400.0);
404    }
405
406    #[test]
407    fn align_baseline_nested_child() {
408        let layout = stretch::compute(&stretch::style::Node {
409            align_items: stretch::style::AlignItems::Baseline,
410            width: stretch::style::Dimension::Points(100.0),
411            height: stretch::style::Dimension::Points(100.0),
412            children: vec![
413                stretch::style::Node {
414                    width: stretch::style::Dimension::Points(50.0),
415                    height: stretch::style::Dimension::Points(50.0),
416                    ..Default::default()
417                },
418                stretch::style::Node {
419                    flex_direction: stretch::style::FlexDirection::Column,
420                    width: stretch::style::Dimension::Points(50.0),
421                    height: stretch::style::Dimension::Points(20.0),
422                    children: vec![stretch::style::Node {
423                        width: stretch::style::Dimension::Points(50.0),
424                        height: stretch::style::Dimension::Points(10.0),
425                        ..Default::default()
426                    }],
427                    ..Default::default()
428                },
429            ],
430            ..Default::default()
431        });
432
433        assert_eq!(layout.width, 100.0);
434        assert_eq!(layout.height, 100.0);
435        assert_eq!(layout.x, 0.0);
436        assert_eq!(layout.y, 0.0);
437
438        assert_eq!(layout.children[0].width, 50.0);
439        assert_eq!(layout.children[0].height, 50.0);
440        assert_eq!(layout.children[0].x, 0.0);
441        assert_eq!(layout.children[0].y, 0.0);
442
443        assert_eq!(layout.children[1].width, 50.0);
444        assert_eq!(layout.children[1].height, 20.0);
445        assert_eq!(layout.children[1].x, 50.0);
446        assert_eq!(layout.children[1].y, 40.0);
447
448        assert_eq!(layout.children[1].children[0].width, 50.0);
449        assert_eq!(layout.children[1].children[0].height, 10.0);
450        assert_eq!(layout.children[1].children[0].x, 0.0);
451        assert_eq!(layout.children[1].children[0].y, 0.0);
452    }
453
454    #[test]
455    fn max_height_overrides_height_on_root() {
456        let layout = stretch::compute(&stretch::style::Node {
457            height: stretch::style::Dimension::Points(200.0),
458            max_height: stretch::style::Dimension::Points(100.0),
459            ..Default::default()
460        });
461
462        assert_eq!(layout.width, 0.0);
463        assert_eq!(layout.height, 100.0);
464        assert_eq!(layout.x, 0.0);
465        assert_eq!(layout.y, 0.0);
466    }
467
468    #[test]
469    fn padding_center_child() {
470        let layout = stretch::compute(&stretch::style::Node {
471            align_items: stretch::style::AlignItems::Center,
472            justify_content: stretch::style::JustifyContent::Center,
473            width: stretch::style::Dimension::Points(100.0),
474            height: stretch::style::Dimension::Points(100.0),
475            padding: stretch::style::Edges {
476                start: stretch::style::Dimension::Points(10.0),
477                end: stretch::style::Dimension::Points(20.0),
478                top: stretch::style::Dimension::Points(10.0),
479                bottom: stretch::style::Dimension::Points(20.0),
480                ..Default::default()
481            },
482            children: vec![stretch::style::Node {
483                width: stretch::style::Dimension::Points(10.0),
484                height: stretch::style::Dimension::Points(10.0),
485                ..Default::default()
486            }],
487            ..Default::default()
488        });
489
490        assert_eq!(layout.width, 100.0);
491        assert_eq!(layout.height, 100.0);
492        assert_eq!(layout.x, 0.0);
493        assert_eq!(layout.y, 0.0);
494
495        assert_eq!(layout.children[0].width, 10.0);
496        assert_eq!(layout.children[0].height, 10.0);
497        assert_eq!(layout.children[0].x, 40.0);
498        assert_eq!(layout.children[0].y, 40.0);
499    }
500
501    #[test]
502    fn align_flex_start_with_stretching_children() {
503        let layout = stretch::compute(&stretch::style::Node {
504            width: stretch::style::Dimension::Points(500.0),
505            height: stretch::style::Dimension::Points(500.0),
506            children: vec![stretch::style::Node {
507                children: vec![stretch::style::Node {
508                    flex_grow: 1.0,
509                    flex_shrink: 1.0,
510                    children: vec![stretch::style::Node {
511                        flex_grow: 1.0,
512                        flex_shrink: 1.0,
513                        ..Default::default()
514                    }],
515                    ..Default::default()
516                }],
517                ..Default::default()
518            }],
519            ..Default::default()
520        });
521
522        assert_eq!(layout.width, 500.0);
523        assert_eq!(layout.height, 500.0);
524        assert_eq!(layout.x, 0.0);
525        assert_eq!(layout.y, 0.0);
526
527        assert_eq!(layout.children[0].width, 0.0);
528        assert_eq!(layout.children[0].height, 500.0);
529        assert_eq!(layout.children[0].x, 0.0);
530        assert_eq!(layout.children[0].y, 0.0);
531
532        assert_eq!(layout.children[0].children[0].width, 0.0);
533        assert_eq!(layout.children[0].children[0].height, 500.0);
534        assert_eq!(layout.children[0].children[0].x, 0.0);
535        assert_eq!(layout.children[0].children[0].y, 0.0);
536
537        assert_eq!(layout.children[0].children[0].children[0].width, 0.0);
538        assert_eq!(layout.children[0].children[0].children[0].height, 500.0);
539        assert_eq!(layout.children[0].children[0].children[0].x, 0.0);
540        assert_eq!(layout.children[0].children[0].children[0].y, 0.0);
541    }
542
543    #[test]
544    fn min_width_overrides_width() {
545        let layout = stretch::compute(&stretch::style::Node {
546            children: vec![stretch::style::Node {
547                width: stretch::style::Dimension::Points(50.0),
548                min_width: stretch::style::Dimension::Points(100.0),
549                ..Default::default()
550            }],
551            ..Default::default()
552        });
553
554        assert_eq!(layout.width, 100.0);
555        assert_eq!(layout.height, 0.0);
556        assert_eq!(layout.x, 0.0);
557        assert_eq!(layout.y, 0.0);
558
559        assert_eq!(layout.children[0].width, 100.0);
560        assert_eq!(layout.children[0].height, 0.0);
561        assert_eq!(layout.children[0].x, 0.0);
562        assert_eq!(layout.children[0].y, 0.0);
563    }
564
565    #[test]
566    fn flex_wrap_align_stretch_fits_one_row() {
567        let layout = stretch::compute(&stretch::style::Node {
568            width: stretch::style::Dimension::Points(150.0),
569            height: stretch::style::Dimension::Points(100.0),
570            children: vec![
571                stretch::style::Node {
572                    width: stretch::style::Dimension::Points(50.0),
573                    ..Default::default()
574                },
575                stretch::style::Node {
576                    width: stretch::style::Dimension::Points(50.0),
577                    ..Default::default()
578                },
579            ],
580            ..Default::default()
581        });
582
583        assert_eq!(layout.width, 150.0);
584        assert_eq!(layout.height, 100.0);
585        assert_eq!(layout.x, 0.0);
586        assert_eq!(layout.y, 0.0);
587
588        assert_eq!(layout.children[0].width, 50.0);
589        assert_eq!(layout.children[0].height, 100.0);
590        assert_eq!(layout.children[0].x, 0.0);
591        assert_eq!(layout.children[0].y, 0.0);
592
593        assert_eq!(layout.children[1].width, 50.0);
594        assert_eq!(layout.children[1].height, 100.0);
595        assert_eq!(layout.children[1].x, 50.0);
596        assert_eq!(layout.children[1].y, 0.0);
597    }
598
599    #[test]
600    fn justify_content_row_space_evenly() {
601        let layout = stretch::compute(&stretch::style::Node {
602            justify_content: stretch::style::JustifyContent::SpaceEvenly,
603            width: stretch::style::Dimension::Points(100.0),
604            height: stretch::style::Dimension::Points(100.0),
605            children: vec![
606                stretch::style::Node {
607                    height: stretch::style::Dimension::Points(10.0),
608                    ..Default::default()
609                },
610                stretch::style::Node {
611                    height: stretch::style::Dimension::Points(10.0),
612                    ..Default::default()
613                },
614                stretch::style::Node {
615                    height: stretch::style::Dimension::Points(10.0),
616                    ..Default::default()
617                },
618            ],
619            ..Default::default()
620        });
621
622        assert_eq!(layout.width, 100.0);
623        assert_eq!(layout.height, 100.0);
624        assert_eq!(layout.x, 0.0);
625        assert_eq!(layout.y, 0.0);
626
627        assert_eq!(layout.children[0].width, 0.0);
628        assert_eq!(layout.children[0].height, 10.0);
629        assert_eq!(layout.children[0].x, 25.0);
630        assert_eq!(layout.children[0].y, 0.0);
631
632        assert_eq!(layout.children[1].width, 0.0);
633        assert_eq!(layout.children[1].height, 10.0);
634        assert_eq!(layout.children[1].x, 50.0);
635        assert_eq!(layout.children[1].y, 0.0);
636
637        assert_eq!(layout.children[2].width, 0.0);
638        assert_eq!(layout.children[2].height, 10.0);
639        assert_eq!(layout.children[2].x, 75.0);
640        assert_eq!(layout.children[2].y, 0.0);
641    }
642
643    #[test]
644    fn absolute_layout_percentage_bottom_based_on_parent_height() {
645        let layout = stretch::compute(&stretch::style::Node {
646            width: stretch::style::Dimension::Points(100.0),
647            height: stretch::style::Dimension::Points(200.0),
648            children: vec![
649                stretch::style::Node {
650                    position: stretch::style::Position::Absolute,
651                    width: stretch::style::Dimension::Points(10.0),
652                    height: stretch::style::Dimension::Points(10.0),
653                    top: stretch::style::Dimension::Percent(0.5),
654                    ..Default::default()
655                },
656                stretch::style::Node {
657                    position: stretch::style::Position::Absolute,
658                    width: stretch::style::Dimension::Points(10.0),
659                    height: stretch::style::Dimension::Points(10.0),
660                    bottom: stretch::style::Dimension::Percent(0.5),
661                    ..Default::default()
662                },
663                stretch::style::Node {
664                    position: stretch::style::Position::Absolute,
665                    width: stretch::style::Dimension::Points(10.0),
666                    top: stretch::style::Dimension::Percent(0.1),
667                    bottom: stretch::style::Dimension::Percent(0.1),
668                    ..Default::default()
669                },
670            ],
671            ..Default::default()
672        });
673
674        assert_eq!(layout.width, 100.0);
675        assert_eq!(layout.height, 200.0);
676        assert_eq!(layout.x, 0.0);
677        assert_eq!(layout.y, 0.0);
678
679        assert_eq!(layout.children[0].width, 10.0);
680        assert_eq!(layout.children[0].height, 10.0);
681        assert_eq!(layout.children[0].x, 0.0);
682        assert_eq!(layout.children[0].y, 100.0);
683
684        assert_eq!(layout.children[1].width, 10.0);
685        assert_eq!(layout.children[1].height, 10.0);
686        assert_eq!(layout.children[1].x, 0.0);
687        assert_eq!(layout.children[1].y, 90.0);
688
689        assert_eq!(layout.children[2].width, 10.0);
690        assert_eq!(layout.children[2].height, 160.0);
691        assert_eq!(layout.children[2].x, 0.0);
692        assert_eq!(layout.children[2].y, 20.0);
693    }
694
695    #[test]
696    fn absolute_layout_align_items_and_justify_content_flex_end() {
697        let layout = stretch::compute(&stretch::style::Node {
698            align_items: stretch::style::AlignItems::FlexEnd,
699            justify_content: stretch::style::JustifyContent::FlexEnd,
700            width: stretch::style::Dimension::Points(110.0),
701            height: stretch::style::Dimension::Points(100.0),
702            children: vec![stretch::style::Node {
703                position: stretch::style::Position::Absolute,
704                width: stretch::style::Dimension::Points(60.0),
705                height: stretch::style::Dimension::Points(40.0),
706                ..Default::default()
707            }],
708            ..Default::default()
709        });
710
711        assert_eq!(layout.width, 110.0);
712        assert_eq!(layout.height, 100.0);
713        assert_eq!(layout.x, 0.0);
714        assert_eq!(layout.y, 0.0);
715
716        assert_eq!(layout.children[0].width, 60.0);
717        assert_eq!(layout.children[0].height, 40.0);
718        assert_eq!(layout.children[0].x, 50.0);
719        assert_eq!(layout.children[0].y, 60.0);
720    }
721
722    #[test]
723    fn nested_overflowing_child() {
724        let layout = stretch::compute(&stretch::style::Node {
725            width: stretch::style::Dimension::Points(100.0),
726            height: stretch::style::Dimension::Points(100.0),
727            children: vec![stretch::style::Node {
728                children: vec![stretch::style::Node {
729                    width: stretch::style::Dimension::Points(200.0),
730                    height: stretch::style::Dimension::Points(200.0),
731                    ..Default::default()
732                }],
733                ..Default::default()
734            }],
735            ..Default::default()
736        });
737
738        assert_eq!(layout.width, 100.0);
739        assert_eq!(layout.height, 100.0);
740        assert_eq!(layout.x, 0.0);
741        assert_eq!(layout.y, 0.0);
742
743        assert_eq!(layout.children[0].width, 200.0);
744        assert_eq!(layout.children[0].height, 100.0);
745        assert_eq!(layout.children[0].x, 0.0);
746        assert_eq!(layout.children[0].y, 0.0);
747
748        assert_eq!(layout.children[0].children[0].width, 200.0);
749        assert_eq!(layout.children[0].children[0].height, 200.0);
750        assert_eq!(layout.children[0].children[0].x, 0.0);
751        assert_eq!(layout.children[0].children[0].y, 0.0);
752    }
753
754    #[test]
755    fn flex_direction_row() {
756        let layout = stretch::compute(&stretch::style::Node {
757            width: stretch::style::Dimension::Points(100.0),
758            height: stretch::style::Dimension::Points(100.0),
759            children: vec![
760                stretch::style::Node {
761                    width: stretch::style::Dimension::Points(10.0),
762                    ..Default::default()
763                },
764                stretch::style::Node {
765                    width: stretch::style::Dimension::Points(10.0),
766                    ..Default::default()
767                },
768                stretch::style::Node {
769                    width: stretch::style::Dimension::Points(10.0),
770                    ..Default::default()
771                },
772            ],
773            ..Default::default()
774        });
775
776        assert_eq!(layout.width, 100.0);
777        assert_eq!(layout.height, 100.0);
778        assert_eq!(layout.x, 0.0);
779        assert_eq!(layout.y, 0.0);
780
781        assert_eq!(layout.children[0].width, 10.0);
782        assert_eq!(layout.children[0].height, 100.0);
783        assert_eq!(layout.children[0].x, 0.0);
784        assert_eq!(layout.children[0].y, 0.0);
785
786        assert_eq!(layout.children[1].width, 10.0);
787        assert_eq!(layout.children[1].height, 100.0);
788        assert_eq!(layout.children[1].x, 10.0);
789        assert_eq!(layout.children[1].y, 0.0);
790
791        assert_eq!(layout.children[2].width, 10.0);
792        assert_eq!(layout.children[2].height, 100.0);
793        assert_eq!(layout.children[2].x, 20.0);
794        assert_eq!(layout.children[2].y, 0.0);
795    }
796
797    #[test]
798    fn child_min_max_width_flexing() {
799        let layout = stretch::compute(&stretch::style::Node {
800            width: stretch::style::Dimension::Points(120.0),
801            height: stretch::style::Dimension::Points(50.0),
802            children: vec![
803                stretch::style::Node {
804                    flex_grow: 1.0,
805                    flex_shrink: 0.0,
806                    flex_basis: stretch::style::Dimension::Points(0.0),
807                    min_width: stretch::style::Dimension::Points(60.0),
808                    ..Default::default()
809                },
810                stretch::style::Node {
811                    flex_grow: 1.0,
812                    flex_shrink: 0.0,
813                    flex_basis: stretch::style::Dimension::Percent(0.5),
814                    max_width: stretch::style::Dimension::Points(20.0),
815                    ..Default::default()
816                },
817            ],
818            ..Default::default()
819        });
820
821        assert_eq!(layout.width, 120.0);
822        assert_eq!(layout.height, 50.0);
823        assert_eq!(layout.x, 0.0);
824        assert_eq!(layout.y, 0.0);
825
826        assert_eq!(layout.children[0].width, 100.0);
827        assert_eq!(layout.children[0].height, 50.0);
828        assert_eq!(layout.children[0].x, 0.0);
829        assert_eq!(layout.children[0].y, 0.0);
830
831        assert_eq!(layout.children[1].width, 20.0);
832        assert_eq!(layout.children[1].height, 50.0);
833        assert_eq!(layout.children[1].x, 100.0);
834        assert_eq!(layout.children[1].y, 0.0);
835    }
836
837    #[test]
838    fn absolute_layout_in_wrap_reverse_row_container_flex_end() {
839        let layout = stretch::compute(&stretch::style::Node {
840            width: stretch::style::Dimension::Points(100.0),
841            height: stretch::style::Dimension::Points(100.0),
842            children: vec![stretch::style::Node {
843                position: stretch::style::Position::Absolute,
844                align_self: stretch::style::AlignSelf::FlexEnd,
845                width: stretch::style::Dimension::Points(20.0),
846                height: stretch::style::Dimension::Points(20.0),
847                ..Default::default()
848            }],
849            ..Default::default()
850        });
851
852        assert_eq!(layout.width, 100.0);
853        assert_eq!(layout.height, 100.0);
854        assert_eq!(layout.x, 0.0);
855        assert_eq!(layout.y, 0.0);
856
857        assert_eq!(layout.children[0].width, 20.0);
858        assert_eq!(layout.children[0].height, 20.0);
859        assert_eq!(layout.children[0].x, 0.0);
860        assert_eq!(layout.children[0].y, 0.0);
861    }
862
863    #[test]
864    fn margin_and_flex_column() {
865        let layout = stretch::compute(&stretch::style::Node {
866            flex_direction: stretch::style::FlexDirection::Column,
867            width: stretch::style::Dimension::Points(100.0),
868            height: stretch::style::Dimension::Points(100.0),
869            children: vec![stretch::style::Node {
870                flex_grow: 1.0,
871                margin: stretch::style::Edges {
872                    top: stretch::style::Dimension::Points(10.0),
873                    bottom: stretch::style::Dimension::Points(10.0),
874                    ..Default::default()
875                },
876                ..Default::default()
877            }],
878            ..Default::default()
879        });
880
881        assert_eq!(layout.width, 100.0);
882        assert_eq!(layout.height, 100.0);
883        assert_eq!(layout.x, 0.0);
884        assert_eq!(layout.y, 0.0);
885
886        assert_eq!(layout.children[0].width, 100.0);
887        assert_eq!(layout.children[0].height, 80.0);
888        assert_eq!(layout.children[0].x, 0.0);
889        assert_eq!(layout.children[0].y, 10.0);
890    }
891
892    #[test]
893    fn flex_basis_flex_shrink_row() {
894        let layout = stretch::compute(&stretch::style::Node {
895            width: stretch::style::Dimension::Points(100.0),
896            height: stretch::style::Dimension::Points(100.0),
897            children: vec![
898                stretch::style::Node {
899                    flex_basis: stretch::style::Dimension::Points(100.0),
900                    ..Default::default()
901                },
902                stretch::style::Node {
903                    flex_basis: stretch::style::Dimension::Points(50.0),
904                    ..Default::default()
905                },
906            ],
907            ..Default::default()
908        });
909
910        assert_eq!(layout.width, 100.0);
911        assert_eq!(layout.height, 100.0);
912        assert_eq!(layout.x, 0.0);
913        assert_eq!(layout.y, 0.0);
914
915        assert_eq!(layout.children[0].width, 67.0);
916        assert_eq!(layout.children[0].height, 100.0);
917        assert_eq!(layout.children[0].x, 0.0);
918        assert_eq!(layout.children[0].y, 0.0);
919
920        assert_eq!(layout.children[1].width, 33.0);
921        assert_eq!(layout.children[1].height, 100.0);
922        assert_eq!(layout.children[1].x, 67.0);
923        assert_eq!(layout.children[1].y, 0.0);
924    }
925
926    #[test]
927    fn justify_content_overflow_min_max() {
928        let layout = stretch::compute(&stretch::style::Node {
929            flex_direction: stretch::style::FlexDirection::Column,
930            justify_content: stretch::style::JustifyContent::Center,
931            min_height: stretch::style::Dimension::Points(100.0),
932            max_height: stretch::style::Dimension::Points(110.0),
933            children: vec![
934                stretch::style::Node {
935                    width: stretch::style::Dimension::Points(50.0),
936                    height: stretch::style::Dimension::Points(50.0),
937                    ..Default::default()
938                },
939                stretch::style::Node {
940                    width: stretch::style::Dimension::Points(50.0),
941                    height: stretch::style::Dimension::Points(50.0),
942                    ..Default::default()
943                },
944                stretch::style::Node {
945                    width: stretch::style::Dimension::Points(50.0),
946                    height: stretch::style::Dimension::Points(50.0),
947                    ..Default::default()
948                },
949            ],
950            ..Default::default()
951        });
952
953        assert_eq!(layout.width, 50.0);
954        assert_eq!(layout.height, 110.0);
955        assert_eq!(layout.x, 0.0);
956        assert_eq!(layout.y, 0.0);
957
958        assert_eq!(layout.children[0].width, 50.0);
959        assert_eq!(layout.children[0].height, 37.0);
960        assert_eq!(layout.children[0].x, 0.0);
961        assert_eq!(layout.children[0].y, 0.0);
962
963        assert_eq!(layout.children[1].width, 50.0);
964        assert_eq!(layout.children[1].height, 36.0);
965        assert_eq!(layout.children[1].x, 0.0);
966        assert_eq!(layout.children[1].y, 37.0);
967
968        assert_eq!(layout.children[2].width, 50.0);
969        assert_eq!(layout.children[2].height, 37.0);
970        assert_eq!(layout.children[2].x, 0.0);
971        assert_eq!(layout.children[2].y, 73.0);
972    }
973
974    #[test]
975    fn wrap_reverse_column_fixed_size() {
976        let layout = stretch::compute(&stretch::style::Node {
977            flex_direction: stretch::style::FlexDirection::Column,
978            align_items: stretch::style::AlignItems::Center,
979            width: stretch::style::Dimension::Points(200.0),
980            height: stretch::style::Dimension::Points(100.0),
981            children: vec![
982                stretch::style::Node {
983                    width: stretch::style::Dimension::Points(30.0),
984                    height: stretch::style::Dimension::Points(10.0),
985                    ..Default::default()
986                },
987                stretch::style::Node {
988                    width: stretch::style::Dimension::Points(30.0),
989                    height: stretch::style::Dimension::Points(20.0),
990                    ..Default::default()
991                },
992                stretch::style::Node {
993                    width: stretch::style::Dimension::Points(30.0),
994                    height: stretch::style::Dimension::Points(30.0),
995                    ..Default::default()
996                },
997                stretch::style::Node {
998                    width: stretch::style::Dimension::Points(30.0),
999                    height: stretch::style::Dimension::Points(40.0),
1000                    ..Default::default()
1001                },
1002                stretch::style::Node {
1003                    width: stretch::style::Dimension::Points(30.0),
1004                    height: stretch::style::Dimension::Points(50.0),
1005                    ..Default::default()
1006                },
1007            ],
1008            ..Default::default()
1009        });
1010
1011        assert_eq!(layout.width, 200.0);
1012        assert_eq!(layout.height, 100.0);
1013        assert_eq!(layout.x, 0.0);
1014        assert_eq!(layout.y, 0.0);
1015
1016        assert_eq!(layout.children[0].width, 30.0);
1017        assert_eq!(layout.children[0].height, 10.0);
1018        assert_eq!(layout.children[0].x, 135.0);
1019        assert_eq!(layout.children[0].y, 0.0);
1020
1021        assert_eq!(layout.children[1].width, 30.0);
1022        assert_eq!(layout.children[1].height, 20.0);
1023        assert_eq!(layout.children[1].x, 135.0);
1024        assert_eq!(layout.children[1].y, 10.0);
1025
1026        assert_eq!(layout.children[2].width, 30.0);
1027        assert_eq!(layout.children[2].height, 30.0);
1028        assert_eq!(layout.children[2].x, 135.0);
1029        assert_eq!(layout.children[2].y, 30.0);
1030
1031        assert_eq!(layout.children[3].width, 30.0);
1032        assert_eq!(layout.children[3].height, 40.0);
1033        assert_eq!(layout.children[3].x, 135.0);
1034        assert_eq!(layout.children[3].y, 60.0);
1035
1036        assert_eq!(layout.children[4].width, 30.0);
1037        assert_eq!(layout.children[4].height, 50.0);
1038        assert_eq!(layout.children[4].x, 35.0);
1039        assert_eq!(layout.children[4].y, 0.0);
1040    }
1041
1042    #[test]
1043    fn max_width() {
1044        let layout = stretch::compute(&stretch::style::Node {
1045            flex_direction: stretch::style::FlexDirection::Column,
1046            width: stretch::style::Dimension::Points(100.0),
1047            height: stretch::style::Dimension::Points(100.0),
1048            children: vec![stretch::style::Node {
1049                max_width: stretch::style::Dimension::Points(50.0),
1050                height: stretch::style::Dimension::Points(10.0),
1051                ..Default::default()
1052            }],
1053            ..Default::default()
1054        });
1055
1056        assert_eq!(layout.width, 100.0);
1057        assert_eq!(layout.height, 100.0);
1058        assert_eq!(layout.x, 0.0);
1059        assert_eq!(layout.y, 0.0);
1060
1061        assert_eq!(layout.children[0].width, 50.0);
1062        assert_eq!(layout.children[0].height, 10.0);
1063        assert_eq!(layout.children[0].x, 0.0);
1064        assert_eq!(layout.children[0].y, 0.0);
1065    }
1066
1067    #[test]
1068    fn justify_content_row_center() {
1069        let layout = stretch::compute(&stretch::style::Node {
1070            justify_content: stretch::style::JustifyContent::Center,
1071            width: stretch::style::Dimension::Points(100.0),
1072            height: stretch::style::Dimension::Points(100.0),
1073            children: vec![
1074                stretch::style::Node {
1075                    width: stretch::style::Dimension::Points(10.0),
1076                    ..Default::default()
1077                },
1078                stretch::style::Node {
1079                    width: stretch::style::Dimension::Points(10.0),
1080                    ..Default::default()
1081                },
1082                stretch::style::Node {
1083                    width: stretch::style::Dimension::Points(10.0),
1084                    ..Default::default()
1085                },
1086            ],
1087            ..Default::default()
1088        });
1089
1090        assert_eq!(layout.width, 100.0);
1091        assert_eq!(layout.height, 100.0);
1092        assert_eq!(layout.x, 0.0);
1093        assert_eq!(layout.y, 0.0);
1094
1095        assert_eq!(layout.children[0].width, 10.0);
1096        assert_eq!(layout.children[0].height, 100.0);
1097        assert_eq!(layout.children[0].x, 35.0);
1098        assert_eq!(layout.children[0].y, 0.0);
1099
1100        assert_eq!(layout.children[1].width, 10.0);
1101        assert_eq!(layout.children[1].height, 100.0);
1102        assert_eq!(layout.children[1].x, 45.0);
1103        assert_eq!(layout.children[1].y, 0.0);
1104
1105        assert_eq!(layout.children[2].width, 10.0);
1106        assert_eq!(layout.children[2].height, 100.0);
1107        assert_eq!(layout.children[2].x, 55.0);
1108        assert_eq!(layout.children[2].y, 0.0);
1109    }
1110
1111    #[test]
1112    fn flex_grow_root_minimized() {
1113        let layout = stretch::compute(&stretch::style::Node {
1114            flex_direction: stretch::style::FlexDirection::Column,
1115            width: stretch::style::Dimension::Points(100.0),
1116            min_height: stretch::style::Dimension::Points(100.0),
1117            max_height: stretch::style::Dimension::Points(500.0),
1118            children: vec![stretch::style::Node {
1119                flex_direction: stretch::style::FlexDirection::Column,
1120                flex_grow: 1.0,
1121                min_height: stretch::style::Dimension::Points(100.0),
1122                max_height: stretch::style::Dimension::Points(500.0),
1123                children: vec![
1124                    stretch::style::Node {
1125                        flex_grow: 1.0,
1126                        flex_basis: stretch::style::Dimension::Points(200.0),
1127                        ..Default::default()
1128                    },
1129                    stretch::style::Node {
1130                        height: stretch::style::Dimension::Points(100.0),
1131                        ..Default::default()
1132                    },
1133                ],
1134                ..Default::default()
1135            }],
1136            ..Default::default()
1137        });
1138
1139        assert_eq!(layout.width, 100.0);
1140        assert_eq!(layout.height, 300.0);
1141        assert_eq!(layout.x, 0.0);
1142        assert_eq!(layout.y, 0.0);
1143
1144        assert_eq!(layout.children[0].width, 100.0);
1145        assert_eq!(layout.children[0].height, 300.0);
1146        assert_eq!(layout.children[0].x, 0.0);
1147        assert_eq!(layout.children[0].y, 0.0);
1148
1149        assert_eq!(layout.children[0].children[0].width, 100.0);
1150        assert_eq!(layout.children[0].children[0].height, 200.0);
1151        assert_eq!(layout.children[0].children[0].x, 0.0);
1152        assert_eq!(layout.children[0].children[0].y, 0.0);
1153
1154        assert_eq!(layout.children[0].children[1].width, 100.0);
1155        assert_eq!(layout.children[0].children[1].height, 100.0);
1156        assert_eq!(layout.children[0].children[1].x, 0.0);
1157        assert_eq!(layout.children[0].children[1].y, 200.0);
1158    }
1159
1160    #[test]
1161    fn container_with_unsized_child() {
1162        let layout = stretch::compute(&stretch::style::Node {
1163            width: stretch::style::Dimension::Points(100.0),
1164            height: stretch::style::Dimension::Points(100.0),
1165            children: vec![stretch::style::Node {
1166                ..Default::default()
1167            }],
1168            ..Default::default()
1169        });
1170
1171        assert_eq!(layout.width, 100.0);
1172        assert_eq!(layout.height, 100.0);
1173        assert_eq!(layout.x, 0.0);
1174        assert_eq!(layout.y, 0.0);
1175
1176        assert_eq!(layout.children[0].width, 0.0);
1177        assert_eq!(layout.children[0].height, 100.0);
1178        assert_eq!(layout.children[0].x, 0.0);
1179        assert_eq!(layout.children[0].y, 0.0);
1180    }
1181
1182    #[test]
1183    fn flex_grow_within_constrained_min_row() {
1184        let layout = stretch::compute(&stretch::style::Node {
1185            min_width: stretch::style::Dimension::Points(100.0),
1186            height: stretch::style::Dimension::Points(100.0),
1187            children: vec![
1188                stretch::style::Node {
1189                    flex_grow: 1.0,
1190                    ..Default::default()
1191                },
1192                stretch::style::Node {
1193                    width: stretch::style::Dimension::Points(50.0),
1194                    ..Default::default()
1195                },
1196            ],
1197            ..Default::default()
1198        });
1199
1200        assert_eq!(layout.width, 100.0);
1201        assert_eq!(layout.height, 100.0);
1202        assert_eq!(layout.x, 0.0);
1203        assert_eq!(layout.y, 0.0);
1204
1205        assert_eq!(layout.children[0].width, 50.0);
1206        assert_eq!(layout.children[0].height, 100.0);
1207        assert_eq!(layout.children[0].x, 0.0);
1208        assert_eq!(layout.children[0].y, 0.0);
1209
1210        assert_eq!(layout.children[1].width, 50.0);
1211        assert_eq!(layout.children[1].height, 100.0);
1212        assert_eq!(layout.children[1].x, 50.0);
1213        assert_eq!(layout.children[1].y, 0.0);
1214    }
1215
1216    #[test]
1217    fn absolute_layout_width_height_start_top_end_bottom() {
1218        let layout = stretch::compute(&stretch::style::Node {
1219            width: stretch::style::Dimension::Points(100.0),
1220            height: stretch::style::Dimension::Points(100.0),
1221            children: vec![stretch::style::Node {
1222                position: stretch::style::Position::Absolute,
1223                width: stretch::style::Dimension::Points(10.0),
1224                height: stretch::style::Dimension::Points(10.0),
1225                start: stretch::style::Dimension::Points(10.0),
1226                end: stretch::style::Dimension::Points(10.0),
1227                top: stretch::style::Dimension::Points(10.0),
1228                bottom: stretch::style::Dimension::Points(10.0),
1229                ..Default::default()
1230            }],
1231            ..Default::default()
1232        });
1233
1234        assert_eq!(layout.width, 100.0);
1235        assert_eq!(layout.height, 100.0);
1236        assert_eq!(layout.x, 0.0);
1237        assert_eq!(layout.y, 0.0);
1238
1239        assert_eq!(layout.children[0].width, 10.0);
1240        assert_eq!(layout.children[0].height, 10.0);
1241        assert_eq!(layout.children[0].x, 10.0);
1242        assert_eq!(layout.children[0].y, 10.0);
1243    }
1244
1245    #[test]
1246    fn overflow_main_axis() {
1247        let layout = stretch::compute(&stretch::style::Node {
1248            width: stretch::style::Dimension::Points(100.0),
1249            height: stretch::style::Dimension::Points(100.0),
1250            children: vec![stretch::style::Node {
1251                flex_shrink: 0.0,
1252                width: stretch::style::Dimension::Points(200.0),
1253                ..Default::default()
1254            }],
1255            ..Default::default()
1256        });
1257
1258        assert_eq!(layout.width, 100.0);
1259        assert_eq!(layout.height, 100.0);
1260        assert_eq!(layout.x, 0.0);
1261        assert_eq!(layout.y, 0.0);
1262
1263        assert_eq!(layout.children[0].width, 200.0);
1264        assert_eq!(layout.children[0].height, 100.0);
1265        assert_eq!(layout.children[0].x, 0.0);
1266        assert_eq!(layout.children[0].y, 0.0);
1267    }
1268
1269    #[test]
1270    fn flex_grow_to_min() {
1271        let layout = stretch::compute(&stretch::style::Node {
1272            flex_direction: stretch::style::FlexDirection::Column,
1273            width: stretch::style::Dimension::Points(100.0),
1274            min_height: stretch::style::Dimension::Points(100.0),
1275            max_height: stretch::style::Dimension::Points(500.0),
1276            children: vec![
1277                stretch::style::Node {
1278                    flex_grow: 1.0,
1279                    flex_shrink: 1.0,
1280                    ..Default::default()
1281                },
1282                stretch::style::Node {
1283                    height: stretch::style::Dimension::Points(50.0),
1284                    ..Default::default()
1285                },
1286            ],
1287            ..Default::default()
1288        });
1289
1290        assert_eq!(layout.width, 100.0);
1291        assert_eq!(layout.height, 100.0);
1292        assert_eq!(layout.x, 0.0);
1293        assert_eq!(layout.y, 0.0);
1294
1295        assert_eq!(layout.children[0].width, 100.0);
1296        assert_eq!(layout.children[0].height, 50.0);
1297        assert_eq!(layout.children[0].x, 0.0);
1298        assert_eq!(layout.children[0].y, 0.0);
1299
1300        assert_eq!(layout.children[1].width, 100.0);
1301        assert_eq!(layout.children[1].height, 50.0);
1302        assert_eq!(layout.children[1].x, 0.0);
1303        assert_eq!(layout.children[1].y, 50.0);
1304    }
1305
1306    #[test]
1307    fn absolute_layout_align_items_and_justify_content_center_and_top_position() {
1308        let layout = stretch::compute(&stretch::style::Node {
1309            align_items: stretch::style::AlignItems::Center,
1310            justify_content: stretch::style::JustifyContent::Center,
1311            width: stretch::style::Dimension::Points(110.0),
1312            height: stretch::style::Dimension::Points(100.0),
1313            children: vec![stretch::style::Node {
1314                position: stretch::style::Position::Absolute,
1315                width: stretch::style::Dimension::Points(60.0),
1316                height: stretch::style::Dimension::Points(40.0),
1317                top: stretch::style::Dimension::Points(10.0),
1318                ..Default::default()
1319            }],
1320            ..Default::default()
1321        });
1322
1323        assert_eq!(layout.width, 110.0);
1324        assert_eq!(layout.height, 100.0);
1325        assert_eq!(layout.x, 0.0);
1326        assert_eq!(layout.y, 0.0);
1327
1328        assert_eq!(layout.children[0].width, 60.0);
1329        assert_eq!(layout.children[0].height, 40.0);
1330        assert_eq!(layout.children[0].x, 25.0);
1331        assert_eq!(layout.children[0].y, 10.0);
1332    }
1333
1334    #[test]
1335    fn min_height() {
1336        let layout = stretch::compute(&stretch::style::Node {
1337            flex_direction: stretch::style::FlexDirection::Column,
1338            width: stretch::style::Dimension::Points(100.0),
1339            height: stretch::style::Dimension::Points(100.0),
1340            children: vec![
1341                stretch::style::Node {
1342                    flex_grow: 1.0,
1343                    min_height: stretch::style::Dimension::Points(60.0),
1344                    ..Default::default()
1345                },
1346                stretch::style::Node {
1347                    flex_grow: 1.0,
1348                    ..Default::default()
1349                },
1350            ],
1351            ..Default::default()
1352        });
1353
1354        assert_eq!(layout.width, 100.0);
1355        assert_eq!(layout.height, 100.0);
1356        assert_eq!(layout.x, 0.0);
1357        assert_eq!(layout.y, 0.0);
1358
1359        assert_eq!(layout.children[0].width, 100.0);
1360        assert_eq!(layout.children[0].height, 80.0);
1361        assert_eq!(layout.children[0].x, 0.0);
1362        assert_eq!(layout.children[0].y, 0.0);
1363
1364        assert_eq!(layout.children[1].width, 100.0);
1365        assert_eq!(layout.children[1].height, 20.0);
1366        assert_eq!(layout.children[1].x, 0.0);
1367        assert_eq!(layout.children[1].y, 80.0);
1368    }
1369
1370    #[test]
1371    fn justify_content_column_flex_start() {
1372        let layout = stretch::compute(&stretch::style::Node {
1373            flex_direction: stretch::style::FlexDirection::Column,
1374            width: stretch::style::Dimension::Points(100.0),
1375            height: stretch::style::Dimension::Points(100.0),
1376            children: vec![
1377                stretch::style::Node {
1378                    height: stretch::style::Dimension::Points(10.0),
1379                    ..Default::default()
1380                },
1381                stretch::style::Node {
1382                    height: stretch::style::Dimension::Points(10.0),
1383                    ..Default::default()
1384                },
1385                stretch::style::Node {
1386                    height: stretch::style::Dimension::Points(10.0),
1387                    ..Default::default()
1388                },
1389            ],
1390            ..Default::default()
1391        });
1392
1393        assert_eq!(layout.width, 100.0);
1394        assert_eq!(layout.height, 100.0);
1395        assert_eq!(layout.x, 0.0);
1396        assert_eq!(layout.y, 0.0);
1397
1398        assert_eq!(layout.children[0].width, 100.0);
1399        assert_eq!(layout.children[0].height, 10.0);
1400        assert_eq!(layout.children[0].x, 0.0);
1401        assert_eq!(layout.children[0].y, 0.0);
1402
1403        assert_eq!(layout.children[1].width, 100.0);
1404        assert_eq!(layout.children[1].height, 10.0);
1405        assert_eq!(layout.children[1].x, 0.0);
1406        assert_eq!(layout.children[1].y, 10.0);
1407
1408        assert_eq!(layout.children[2].width, 100.0);
1409        assert_eq!(layout.children[2].height, 10.0);
1410        assert_eq!(layout.children[2].x, 0.0);
1411        assert_eq!(layout.children[2].y, 20.0);
1412    }
1413
1414    #[test]
1415    fn absolute_layout_in_wrap_reverse_column_container() {
1416        let layout = stretch::compute(&stretch::style::Node {
1417            flex_direction: stretch::style::FlexDirection::Column,
1418            width: stretch::style::Dimension::Points(100.0),
1419            height: stretch::style::Dimension::Points(100.0),
1420            children: vec![stretch::style::Node {
1421                position: stretch::style::Position::Absolute,
1422                width: stretch::style::Dimension::Points(20.0),
1423                height: stretch::style::Dimension::Points(20.0),
1424                ..Default::default()
1425            }],
1426            ..Default::default()
1427        });
1428
1429        assert_eq!(layout.width, 100.0);
1430        assert_eq!(layout.height, 100.0);
1431        assert_eq!(layout.x, 0.0);
1432        assert_eq!(layout.y, 0.0);
1433
1434        assert_eq!(layout.children[0].width, 20.0);
1435        assert_eq!(layout.children[0].height, 20.0);
1436        assert_eq!(layout.children[0].x, 80.0);
1437        assert_eq!(layout.children[0].y, 0.0);
1438    }
1439
1440    #[test]
1441    fn margin_should_not_be_part_of_max_width() {
1442        let layout = stretch::compute(&stretch::style::Node {
1443            width: stretch::style::Dimension::Points(250.0),
1444            height: stretch::style::Dimension::Points(250.0),
1445            children: vec![stretch::style::Node {
1446                width: stretch::style::Dimension::Points(100.0),
1447                max_width: stretch::style::Dimension::Points(100.0),
1448                height: stretch::style::Dimension::Points(100.0),
1449                margin: stretch::style::Edges {
1450                    start: stretch::style::Dimension::Points(20.0),
1451                    ..Default::default()
1452                },
1453                ..Default::default()
1454            }],
1455            ..Default::default()
1456        });
1457
1458        assert_eq!(layout.width, 250.0);
1459        assert_eq!(layout.height, 250.0);
1460        assert_eq!(layout.x, 0.0);
1461        assert_eq!(layout.y, 0.0);
1462
1463        assert_eq!(layout.children[0].width, 100.0);
1464        assert_eq!(layout.children[0].height, 100.0);
1465        assert_eq!(layout.children[0].x, 20.0);
1466        assert_eq!(layout.children[0].y, 0.0);
1467    }
1468
1469    #[test]
1470    fn border_flex_child() {
1471        let layout = stretch::compute(&stretch::style::Node {
1472            width: stretch::style::Dimension::Points(100.0),
1473            height: stretch::style::Dimension::Points(100.0),
1474            border: stretch::style::Edges {
1475                start: stretch::style::Dimension::Points(10.0),
1476                end: stretch::style::Dimension::Points(10.0),
1477                top: stretch::style::Dimension::Points(10.0),
1478                bottom: stretch::style::Dimension::Points(10.0),
1479                ..Default::default()
1480            },
1481            children: vec![stretch::style::Node {
1482                flex_grow: 1.0,
1483                width: stretch::style::Dimension::Points(10.0),
1484                ..Default::default()
1485            }],
1486            ..Default::default()
1487        });
1488
1489        assert_eq!(layout.width, 100.0);
1490        assert_eq!(layout.height, 100.0);
1491        assert_eq!(layout.x, 0.0);
1492        assert_eq!(layout.y, 0.0);
1493
1494        assert_eq!(layout.children[0].width, 80.0);
1495        assert_eq!(layout.children[0].height, 80.0);
1496        assert_eq!(layout.children[0].x, 10.0);
1497        assert_eq!(layout.children[0].y, 10.0);
1498    }
1499
1500    #[test]
1501    fn margin_right() {
1502        let layout = stretch::compute(&stretch::style::Node {
1503            justify_content: stretch::style::JustifyContent::FlexEnd,
1504            width: stretch::style::Dimension::Points(100.0),
1505            height: stretch::style::Dimension::Points(100.0),
1506            children: vec![stretch::style::Node {
1507                width: stretch::style::Dimension::Points(10.0),
1508                margin: stretch::style::Edges {
1509                    end: stretch::style::Dimension::Points(10.0),
1510                    ..Default::default()
1511                },
1512                ..Default::default()
1513            }],
1514            ..Default::default()
1515        });
1516
1517        assert_eq!(layout.width, 100.0);
1518        assert_eq!(layout.height, 100.0);
1519        assert_eq!(layout.x, 0.0);
1520        assert_eq!(layout.y, 0.0);
1521
1522        assert_eq!(layout.children[0].width, 10.0);
1523        assert_eq!(layout.children[0].height, 100.0);
1524        assert_eq!(layout.children[0].x, 80.0);
1525        assert_eq!(layout.children[0].y, 0.0);
1526    }
1527
1528    #[test]
1529    fn align_flex_start_with_shrinking_children_with_stretch() {
1530        let layout = stretch::compute(&stretch::style::Node {
1531            width: stretch::style::Dimension::Points(500.0),
1532            height: stretch::style::Dimension::Points(500.0),
1533            children: vec![stretch::style::Node {
1534                align_items: stretch::style::AlignItems::FlexStart,
1535                children: vec![stretch::style::Node {
1536                    flex_grow: 1.0,
1537                    flex_shrink: 1.0,
1538                    children: vec![stretch::style::Node {
1539                        flex_grow: 1.0,
1540                        flex_shrink: 1.0,
1541                        ..Default::default()
1542                    }],
1543                    ..Default::default()
1544                }],
1545                ..Default::default()
1546            }],
1547            ..Default::default()
1548        });
1549
1550        assert_eq!(layout.width, 500.0);
1551        assert_eq!(layout.height, 500.0);
1552        assert_eq!(layout.x, 0.0);
1553        assert_eq!(layout.y, 0.0);
1554
1555        assert_eq!(layout.children[0].width, 0.0);
1556        assert_eq!(layout.children[0].height, 500.0);
1557        assert_eq!(layout.children[0].x, 0.0);
1558        assert_eq!(layout.children[0].y, 0.0);
1559
1560        assert_eq!(layout.children[0].children[0].width, 0.0);
1561        assert_eq!(layout.children[0].children[0].height, 0.0);
1562        assert_eq!(layout.children[0].children[0].x, 0.0);
1563        assert_eq!(layout.children[0].children[0].y, 0.0);
1564
1565        assert_eq!(layout.children[0].children[0].children[0].width, 0.0);
1566        assert_eq!(layout.children[0].children[0].children[0].height, 0.0);
1567        assert_eq!(layout.children[0].children[0].children[0].x, 0.0);
1568        assert_eq!(layout.children[0].children[0].children[0].y, 0.0);
1569    }
1570
1571    #[test]
1572    fn align_items_stretch() {
1573        let layout = stretch::compute(&stretch::style::Node {
1574            width: stretch::style::Dimension::Points(100.0),
1575            height: stretch::style::Dimension::Points(100.0),
1576            children: vec![stretch::style::Node {
1577                width: stretch::style::Dimension::Points(10.0),
1578                ..Default::default()
1579            }],
1580            ..Default::default()
1581        });
1582
1583        assert_eq!(layout.width, 100.0);
1584        assert_eq!(layout.height, 100.0);
1585        assert_eq!(layout.x, 0.0);
1586        assert_eq!(layout.y, 0.0);
1587
1588        assert_eq!(layout.children[0].width, 10.0);
1589        assert_eq!(layout.children[0].height, 100.0);
1590        assert_eq!(layout.children[0].x, 0.0);
1591        assert_eq!(layout.children[0].y, 0.0);
1592    }
1593
1594    #[test]
1595    fn parent_wrap_child_size_overflowing_parent() {
1596        let layout = stretch::compute(&stretch::style::Node {
1597            width: stretch::style::Dimension::Points(100.0),
1598            height: stretch::style::Dimension::Points(100.0),
1599            children: vec![stretch::style::Node {
1600                width: stretch::style::Dimension::Points(100.0),
1601                children: vec![stretch::style::Node {
1602                    width: stretch::style::Dimension::Points(100.0),
1603                    height: stretch::style::Dimension::Points(200.0),
1604                    ..Default::default()
1605                }],
1606                ..Default::default()
1607            }],
1608            ..Default::default()
1609        });
1610
1611        assert_eq!(layout.width, 100.0);
1612        assert_eq!(layout.height, 100.0);
1613        assert_eq!(layout.x, 0.0);
1614        assert_eq!(layout.y, 0.0);
1615
1616        assert_eq!(layout.children[0].width, 100.0);
1617        assert_eq!(layout.children[0].height, 100.0);
1618        assert_eq!(layout.children[0].x, 0.0);
1619        assert_eq!(layout.children[0].y, 0.0);
1620
1621        assert_eq!(layout.children[0].children[0].width, 100.0);
1622        assert_eq!(layout.children[0].children[0].height, 200.0);
1623        assert_eq!(layout.children[0].children[0].x, 0.0);
1624        assert_eq!(layout.children[0].children[0].y, 0.0);
1625    }
1626
1627    #[test]
1628    fn padding_stretch_child() {
1629        let layout = stretch::compute(&stretch::style::Node {
1630            width: stretch::style::Dimension::Points(100.0),
1631            height: stretch::style::Dimension::Points(100.0),
1632            padding: stretch::style::Edges {
1633                start: stretch::style::Dimension::Points(10.0),
1634                end: stretch::style::Dimension::Points(10.0),
1635                top: stretch::style::Dimension::Points(10.0),
1636                bottom: stretch::style::Dimension::Points(10.0),
1637                ..Default::default()
1638            },
1639            children: vec![stretch::style::Node {
1640                height: stretch::style::Dimension::Points(10.0),
1641                ..Default::default()
1642            }],
1643            ..Default::default()
1644        });
1645
1646        assert_eq!(layout.width, 100.0);
1647        assert_eq!(layout.height, 100.0);
1648        assert_eq!(layout.x, 0.0);
1649        assert_eq!(layout.y, 0.0);
1650
1651        assert_eq!(layout.children[0].width, 0.0);
1652        assert_eq!(layout.children[0].height, 10.0);
1653        assert_eq!(layout.children[0].x, 10.0);
1654        assert_eq!(layout.children[0].y, 10.0);
1655    }
1656
1657    #[test]
1658    fn wrap_nodes_with_content_sizing_overflowing_margin() {
1659        let layout = stretch::compute(&stretch::style::Node {
1660            flex_direction: stretch::style::FlexDirection::Column,
1661            width: stretch::style::Dimension::Points(500.0),
1662            height: stretch::style::Dimension::Points(500.0),
1663            children: vec![stretch::style::Node {
1664                width: stretch::style::Dimension::Points(85.0),
1665                children: vec![
1666                    stretch::style::Node {
1667                        flex_direction: stretch::style::FlexDirection::Column,
1668                        children: vec![stretch::style::Node {
1669                            width: stretch::style::Dimension::Points(40.0),
1670                            height: stretch::style::Dimension::Points(40.0),
1671                            ..Default::default()
1672                        }],
1673                        ..Default::default()
1674                    },
1675                    stretch::style::Node {
1676                        flex_direction: stretch::style::FlexDirection::Column,
1677                        margin: stretch::style::Edges {
1678                            end: stretch::style::Dimension::Points(10.0),
1679                            ..Default::default()
1680                        },
1681                        children: vec![stretch::style::Node {
1682                            width: stretch::style::Dimension::Points(40.0),
1683                            height: stretch::style::Dimension::Points(40.0),
1684                            ..Default::default()
1685                        }],
1686                        ..Default::default()
1687                    },
1688                ],
1689                ..Default::default()
1690            }],
1691            ..Default::default()
1692        });
1693
1694        assert_eq!(layout.width, 500.0);
1695        assert_eq!(layout.height, 500.0);
1696        assert_eq!(layout.x, 0.0);
1697        assert_eq!(layout.y, 0.0);
1698
1699        assert_eq!(layout.children[0].width, 85.0);
1700        assert_eq!(layout.children[0].height, 80.0);
1701        assert_eq!(layout.children[0].x, 0.0);
1702        assert_eq!(layout.children[0].y, 0.0);
1703
1704        assert_eq!(layout.children[0].children[0].width, 40.0);
1705        assert_eq!(layout.children[0].children[0].height, 40.0);
1706        assert_eq!(layout.children[0].children[0].x, 0.0);
1707        assert_eq!(layout.children[0].children[0].y, 0.0);
1708
1709        assert_eq!(layout.children[0].children[0].children[0].width, 40.0);
1710        assert_eq!(layout.children[0].children[0].children[0].height, 40.0);
1711        assert_eq!(layout.children[0].children[0].children[0].x, 0.0);
1712        assert_eq!(layout.children[0].children[0].children[0].y, 0.0);
1713
1714        assert_eq!(layout.children[0].children[1].width, 40.0);
1715        assert_eq!(layout.children[0].children[1].height, 40.0);
1716        assert_eq!(layout.children[0].children[1].x, 0.0);
1717        assert_eq!(layout.children[0].children[1].y, 40.0);
1718
1719        assert_eq!(layout.children[0].children[1].children[0].width, 40.0);
1720        assert_eq!(layout.children[0].children[1].children[0].height, 40.0);
1721        assert_eq!(layout.children[0].children[1].children[0].x, 0.0);
1722        assert_eq!(layout.children[0].children[1].children[0].y, 0.0);
1723    }
1724
1725    #[test]
1726    fn flex_shrink_flex_grow_row() {
1727        let layout = stretch::compute(&stretch::style::Node {
1728            width: stretch::style::Dimension::Points(500.0),
1729            height: stretch::style::Dimension::Points(500.0),
1730            children: vec![
1731                stretch::style::Node {
1732                    flex_grow: 0.0,
1733                    flex_shrink: 1.0,
1734                    width: stretch::style::Dimension::Points(500.0),
1735                    height: stretch::style::Dimension::Points(100.0),
1736                    ..Default::default()
1737                },
1738                stretch::style::Node {
1739                    flex_grow: 0.0,
1740                    flex_shrink: 1.0,
1741                    width: stretch::style::Dimension::Points(500.0),
1742                    height: stretch::style::Dimension::Points(100.0),
1743                    ..Default::default()
1744                },
1745            ],
1746            ..Default::default()
1747        });
1748
1749        assert_eq!(layout.width, 500.0);
1750        assert_eq!(layout.height, 500.0);
1751        assert_eq!(layout.x, 0.0);
1752        assert_eq!(layout.y, 0.0);
1753
1754        assert_eq!(layout.children[0].width, 250.0);
1755        assert_eq!(layout.children[0].height, 100.0);
1756        assert_eq!(layout.children[0].x, 0.0);
1757        assert_eq!(layout.children[0].y, 0.0);
1758
1759        assert_eq!(layout.children[1].width, 250.0);
1760        assert_eq!(layout.children[1].height, 100.0);
1761        assert_eq!(layout.children[1].x, 250.0);
1762        assert_eq!(layout.children[1].y, 0.0);
1763    }
1764
1765    #[test]
1766    fn flex_basis_flex_shrink_column() {
1767        let layout = stretch::compute(&stretch::style::Node {
1768            flex_direction: stretch::style::FlexDirection::Column,
1769            width: stretch::style::Dimension::Points(100.0),
1770            height: stretch::style::Dimension::Points(100.0),
1771            children: vec![
1772                stretch::style::Node {
1773                    flex_basis: stretch::style::Dimension::Points(100.0),
1774                    ..Default::default()
1775                },
1776                stretch::style::Node {
1777                    flex_basis: stretch::style::Dimension::Points(50.0),
1778                    ..Default::default()
1779                },
1780            ],
1781            ..Default::default()
1782        });
1783
1784        assert_eq!(layout.width, 100.0);
1785        assert_eq!(layout.height, 100.0);
1786        assert_eq!(layout.x, 0.0);
1787        assert_eq!(layout.y, 0.0);
1788
1789        assert_eq!(layout.children[0].width, 100.0);
1790        assert_eq!(layout.children[0].height, 67.0);
1791        assert_eq!(layout.children[0].x, 0.0);
1792        assert_eq!(layout.children[0].y, 0.0);
1793
1794        assert_eq!(layout.children[1].width, 100.0);
1795        assert_eq!(layout.children[1].height, 33.0);
1796        assert_eq!(layout.children[1].x, 0.0);
1797        assert_eq!(layout.children[1].y, 67.0);
1798    }
1799
1800    #[test]
1801    fn align_items_min_max() {
1802        let layout = stretch::compute(&stretch::style::Node {
1803            flex_direction: stretch::style::FlexDirection::Column,
1804            align_items: stretch::style::AlignItems::Center,
1805            min_width: stretch::style::Dimension::Points(100.0),
1806            max_width: stretch::style::Dimension::Points(200.0),
1807            height: stretch::style::Dimension::Points(100.0),
1808            children: vec![stretch::style::Node {
1809                width: stretch::style::Dimension::Points(60.0),
1810                height: stretch::style::Dimension::Points(60.0),
1811                ..Default::default()
1812            }],
1813            ..Default::default()
1814        });
1815
1816        assert_eq!(layout.width, 100.0);
1817        assert_eq!(layout.height, 100.0);
1818        assert_eq!(layout.x, 0.0);
1819        assert_eq!(layout.y, 0.0);
1820
1821        assert_eq!(layout.children[0].width, 60.0);
1822        assert_eq!(layout.children[0].height, 60.0);
1823        assert_eq!(layout.children[0].x, 20.0);
1824        assert_eq!(layout.children[0].y, 0.0);
1825    }
1826
1827    #[test]
1828    fn justify_content_row_min_width_and_margin() {
1829        let layout = stretch::compute(&stretch::style::Node {
1830            justify_content: stretch::style::JustifyContent::Center,
1831            min_width: stretch::style::Dimension::Points(50.0),
1832            margin: stretch::style::Edges {
1833                start: stretch::style::Dimension::Points(100.0),
1834                ..Default::default()
1835            },
1836            children: vec![stretch::style::Node {
1837                width: stretch::style::Dimension::Points(20.0),
1838                height: stretch::style::Dimension::Points(20.0),
1839                ..Default::default()
1840            }],
1841            ..Default::default()
1842        });
1843
1844        assert_eq!(layout.width, 50.0);
1845        assert_eq!(layout.height, 20.0);
1846        assert_eq!(layout.x, 100.0);
1847        assert_eq!(layout.y, 0.0);
1848
1849        assert_eq!(layout.children[0].width, 20.0);
1850        assert_eq!(layout.children[0].height, 20.0);
1851        assert_eq!(layout.children[0].x, 15.0);
1852        assert_eq!(layout.children[0].y, 0.0);
1853    }
1854
1855    #[test]
1856    fn align_self_flex_start() {
1857        let layout = stretch::compute(&stretch::style::Node {
1858            width: stretch::style::Dimension::Points(100.0),
1859            height: stretch::style::Dimension::Points(100.0),
1860            children: vec![stretch::style::Node {
1861                align_self: stretch::style::AlignSelf::FlexStart,
1862                width: stretch::style::Dimension::Points(10.0),
1863                height: stretch::style::Dimension::Points(10.0),
1864                ..Default::default()
1865            }],
1866            ..Default::default()
1867        });
1868
1869        assert_eq!(layout.width, 100.0);
1870        assert_eq!(layout.height, 100.0);
1871        assert_eq!(layout.x, 0.0);
1872        assert_eq!(layout.y, 0.0);
1873
1874        assert_eq!(layout.children[0].width, 10.0);
1875        assert_eq!(layout.children[0].height, 10.0);
1876        assert_eq!(layout.children[0].x, 0.0);
1877        assert_eq!(layout.children[0].y, 0.0);
1878    }
1879
1880    #[test]
1881    fn percentage_position_left_top() {
1882        let layout = stretch::compute(&stretch::style::Node {
1883            width: stretch::style::Dimension::Points(400.0),
1884            height: stretch::style::Dimension::Points(400.0),
1885            children: vec![stretch::style::Node {
1886                width: stretch::style::Dimension::Percent(0.4),
1887                height: stretch::style::Dimension::Percent(0.6),
1888                start: stretch::style::Dimension::Percent(0.1),
1889                top: stretch::style::Dimension::Percent(0.2),
1890                ..Default::default()
1891            }],
1892            ..Default::default()
1893        });
1894
1895        assert_eq!(layout.width, 400.0);
1896        assert_eq!(layout.height, 400.0);
1897        assert_eq!(layout.x, 0.0);
1898        assert_eq!(layout.y, 0.0);
1899
1900        assert_eq!(layout.children[0].width, 180.0);
1901        assert_eq!(layout.children[0].height, 220.0);
1902        assert_eq!(layout.children[0].x, 40.0);
1903        assert_eq!(layout.children[0].y, 80.0);
1904    }
1905
1906    #[test]
1907    fn border_stretch_child() {
1908        let layout = stretch::compute(&stretch::style::Node {
1909            width: stretch::style::Dimension::Points(100.0),
1910            height: stretch::style::Dimension::Points(100.0),
1911            border: stretch::style::Edges {
1912                start: stretch::style::Dimension::Points(10.0),
1913                end: stretch::style::Dimension::Points(10.0),
1914                top: stretch::style::Dimension::Points(10.0),
1915                bottom: stretch::style::Dimension::Points(10.0),
1916                ..Default::default()
1917            },
1918            children: vec![stretch::style::Node {
1919                width: stretch::style::Dimension::Points(10.0),
1920                ..Default::default()
1921            }],
1922            ..Default::default()
1923        });
1924
1925        assert_eq!(layout.width, 100.0);
1926        assert_eq!(layout.height, 100.0);
1927        assert_eq!(layout.x, 0.0);
1928        assert_eq!(layout.y, 0.0);
1929
1930        assert_eq!(layout.children[0].width, 10.0);
1931        assert_eq!(layout.children[0].height, 80.0);
1932        assert_eq!(layout.children[0].x, 10.0);
1933        assert_eq!(layout.children[0].y, 10.0);
1934    }
1935
1936    #[test]
1937    fn rounding_fractial_input_2() {
1938        let layout = stretch::compute(&stretch::style::Node {
1939            flex_direction: stretch::style::FlexDirection::Column,
1940            width: stretch::style::Dimension::Points(100.0),
1941            height: stretch::style::Dimension::Points(113.6),
1942            children: vec![
1943                stretch::style::Node {
1944                    flex_grow: 1.0,
1945                    flex_basis: stretch::style::Dimension::Points(50.0),
1946                    height: stretch::style::Dimension::Points(20.0),
1947                    ..Default::default()
1948                },
1949                stretch::style::Node {
1950                    flex_grow: 1.0,
1951                    height: stretch::style::Dimension::Points(10.0),
1952                    ..Default::default()
1953                },
1954                stretch::style::Node {
1955                    flex_grow: 1.0,
1956                    height: stretch::style::Dimension::Points(10.0),
1957                    ..Default::default()
1958                },
1959            ],
1960            ..Default::default()
1961        });
1962
1963        assert_eq!(layout.width, 100.0);
1964        assert_eq!(layout.height, 114.0);
1965        assert_eq!(layout.x, 0.0);
1966        assert_eq!(layout.y, 0.0);
1967
1968        assert_eq!(layout.children[0].width, 100.0);
1969        assert_eq!(layout.children[0].height, 65.0);
1970        assert_eq!(layout.children[0].x, 0.0);
1971        assert_eq!(layout.children[0].y, 0.0);
1972
1973        assert_eq!(layout.children[1].width, 100.0);
1974        assert_eq!(layout.children[1].height, 24.0);
1975        assert_eq!(layout.children[1].x, 0.0);
1976        assert_eq!(layout.children[1].y, 65.0);
1977
1978        assert_eq!(layout.children[2].width, 100.0);
1979        assert_eq!(layout.children[2].height, 25.0);
1980        assert_eq!(layout.children[2].x, 0.0);
1981        assert_eq!(layout.children[2].y, 89.0);
1982    }
1983
1984    #[test]
1985    fn percentage_flex_basis_main_max_width() {
1986        let layout = stretch::compute(&stretch::style::Node {
1987            width: stretch::style::Dimension::Points(200.0),
1988            height: stretch::style::Dimension::Points(200.0),
1989            children: vec![
1990                stretch::style::Node {
1991                    flex_grow: 1.0,
1992                    flex_basis: stretch::style::Dimension::Percent(0.2),
1993                    max_width: stretch::style::Dimension::Percent(0.6),
1994                    ..Default::default()
1995                },
1996                stretch::style::Node {
1997                    flex_grow: 4.0,
1998                    flex_basis: stretch::style::Dimension::Percent(0.1),
1999                    max_width: stretch::style::Dimension::Percent(0.2),
2000                    ..Default::default()
2001                },
2002            ],
2003            ..Default::default()
2004        });
2005
2006        assert_eq!(layout.width, 200.0);
2007        assert_eq!(layout.height, 200.0);
2008        assert_eq!(layout.x, 0.0);
2009        assert_eq!(layout.y, 0.0);
2010
2011        assert_eq!(layout.children[0].width, 120.0);
2012        assert_eq!(layout.children[0].height, 200.0);
2013        assert_eq!(layout.children[0].x, 0.0);
2014        assert_eq!(layout.children[0].y, 0.0);
2015
2016        assert_eq!(layout.children[1].width, 40.0);
2017        assert_eq!(layout.children[1].height, 200.0);
2018        assert_eq!(layout.children[1].x, 120.0);
2019        assert_eq!(layout.children[1].y, 0.0);
2020    }
2021
2022    #[test]
2023    fn margin_auto_top_and_bottom_strech() {
2024        let layout = stretch::compute(&stretch::style::Node {
2025            flex_direction: stretch::style::FlexDirection::Column,
2026            width: stretch::style::Dimension::Points(200.0),
2027            height: stretch::style::Dimension::Points(200.0),
2028            children: vec![
2029                stretch::style::Node {
2030                    width: stretch::style::Dimension::Points(50.0),
2031                    height: stretch::style::Dimension::Points(50.0),
2032                    margin: stretch::style::Edges {
2033                        top: stretch::style::Dimension::Auto,
2034                        bottom: stretch::style::Dimension::Auto,
2035                        ..Default::default()
2036                    },
2037                    ..Default::default()
2038                },
2039                stretch::style::Node {
2040                    width: stretch::style::Dimension::Points(50.0),
2041                    height: stretch::style::Dimension::Points(50.0),
2042                    ..Default::default()
2043                },
2044            ],
2045            ..Default::default()
2046        });
2047
2048        assert_eq!(layout.width, 200.0);
2049        assert_eq!(layout.height, 200.0);
2050        assert_eq!(layout.x, 0.0);
2051        assert_eq!(layout.y, 0.0);
2052
2053        assert_eq!(layout.children[0].width, 50.0);
2054        assert_eq!(layout.children[0].height, 50.0);
2055        assert_eq!(layout.children[0].x, 0.0);
2056        assert_eq!(layout.children[0].y, 50.0);
2057
2058        assert_eq!(layout.children[1].width, 50.0);
2059        assert_eq!(layout.children[1].height, 50.0);
2060        assert_eq!(layout.children[1].x, 0.0);
2061        assert_eq!(layout.children[1].y, 150.0);
2062    }
2063
2064    #[test]
2065    fn percentage_multiple_nested_with_padding_margin_and_percentage_values() {
2066        let layout = stretch::compute(&stretch::style::Node {
2067            flex_direction: stretch::style::FlexDirection::Column,
2068            width: stretch::style::Dimension::Points(200.0),
2069            height: stretch::style::Dimension::Points(200.0),
2070            children: vec![
2071                stretch::style::Node {
2072                    flex_direction: stretch::style::FlexDirection::Column,
2073                    flex_grow: 1.0,
2074                    flex_basis: stretch::style::Dimension::Percent(0.1),
2075                    min_width: stretch::style::Dimension::Percent(0.6),
2076                    margin: stretch::style::Edges {
2077                        start: stretch::style::Dimension::Points(5.0),
2078                        end: stretch::style::Dimension::Points(5.0),
2079                        top: stretch::style::Dimension::Points(5.0),
2080                        bottom: stretch::style::Dimension::Points(5.0),
2081                        ..Default::default()
2082                    },
2083                    padding: stretch::style::Edges {
2084                        start: stretch::style::Dimension::Points(3.0),
2085                        end: stretch::style::Dimension::Points(3.0),
2086                        top: stretch::style::Dimension::Points(3.0),
2087                        bottom: stretch::style::Dimension::Points(3.0),
2088                        ..Default::default()
2089                    },
2090                    children: vec![stretch::style::Node {
2091                        flex_direction: stretch::style::FlexDirection::Column,
2092                        width: stretch::style::Dimension::Percent(0.5),
2093                        margin: stretch::style::Edges {
2094                            start: stretch::style::Dimension::Points(5.0),
2095                            end: stretch::style::Dimension::Points(5.0),
2096                            top: stretch::style::Dimension::Points(5.0),
2097                            bottom: stretch::style::Dimension::Points(5.0),
2098                            ..Default::default()
2099                        },
2100                        padding: stretch::style::Edges {
2101                            start: stretch::style::Dimension::Percent(0.0),
2102                            end: stretch::style::Dimension::Percent(0.0),
2103                            top: stretch::style::Dimension::Percent(0.0),
2104                            bottom: stretch::style::Dimension::Percent(0.0),
2105                            ..Default::default()
2106                        },
2107                        children: vec![stretch::style::Node {
2108                            width: stretch::style::Dimension::Percent(0.4),
2109                            margin: stretch::style::Edges {
2110                                start: stretch::style::Dimension::Percent(0.1),
2111                                end: stretch::style::Dimension::Percent(0.1),
2112                                top: stretch::style::Dimension::Percent(0.1),
2113                                bottom: stretch::style::Dimension::Percent(0.1),
2114                                ..Default::default()
2115                            },
2116                            padding: stretch::style::Edges {
2117                                start: stretch::style::Dimension::Points(3.0),
2118                                end: stretch::style::Dimension::Points(3.0),
2119                                top: stretch::style::Dimension::Points(3.0),
2120                                bottom: stretch::style::Dimension::Points(3.0),
2121                                ..Default::default()
2122                            },
2123                            ..Default::default()
2124                        }],
2125                        ..Default::default()
2126                    }],
2127                    ..Default::default()
2128                },
2129                stretch::style::Node {
2130                    flex_grow: 4.0,
2131                    flex_basis: stretch::style::Dimension::Percent(0.2),
2132                    min_width: stretch::style::Dimension::Percent(0.2),
2133                    ..Default::default()
2134                },
2135            ],
2136            ..Default::default()
2137        });
2138
2139        assert_eq!(layout.width, 200.0);
2140        assert_eq!(layout.height, 200.0);
2141        assert_eq!(layout.x, 0.0);
2142        assert_eq!(layout.y, 0.0);
2143
2144        assert_eq!(layout.children[0].width, 190.0);
2145        assert_eq!(layout.children[0].height, 48.0);
2146        assert_eq!(layout.children[0].x, 5.0);
2147        assert_eq!(layout.children[0].y, 5.0);
2148
2149        assert_eq!(layout.children[0].children[0].width, 92.0);
2150        assert_eq!(layout.children[0].children[0].height, 25.0);
2151        assert_eq!(layout.children[0].children[0].x, 8.0);
2152        assert_eq!(layout.children[0].children[0].y, 8.0);
2153
2154        assert_eq!(layout.children[0].children[0].children[0].width, 36.0);
2155        assert_eq!(layout.children[0].children[0].children[0].height, 6.0);
2156        assert_eq!(layout.children[0].children[0].children[0].x, 10.0);
2157        assert_eq!(layout.children[0].children[0].children[0].y, 10.0);
2158
2159        assert_eq!(layout.children[1].width, 200.0);
2160        assert_eq!(layout.children[1].height, 142.0);
2161        assert_eq!(layout.children[1].x, 0.0);
2162        assert_eq!(layout.children[1].y, 58.0);
2163    }
2164
2165    #[test]
2166    fn flex_grow_within_constrained_min_column() {
2167        let layout = stretch::compute(&stretch::style::Node {
2168            flex_direction: stretch::style::FlexDirection::Column,
2169            min_height: stretch::style::Dimension::Points(100.0),
2170            children: vec![
2171                stretch::style::Node {
2172                    flex_grow: 1.0,
2173                    ..Default::default()
2174                },
2175                stretch::style::Node {
2176                    height: stretch::style::Dimension::Points(50.0),
2177                    ..Default::default()
2178                },
2179            ],
2180            ..Default::default()
2181        });
2182
2183        assert_eq!(layout.width, 0.0);
2184        assert_eq!(layout.height, 100.0);
2185        assert_eq!(layout.x, 0.0);
2186        assert_eq!(layout.y, 0.0);
2187
2188        assert_eq!(layout.children[0].width, 0.0);
2189        assert_eq!(layout.children[0].height, 50.0);
2190        assert_eq!(layout.children[0].x, 0.0);
2191        assert_eq!(layout.children[0].y, 0.0);
2192
2193        assert_eq!(layout.children[1].width, 0.0);
2194        assert_eq!(layout.children[1].height, 50.0);
2195        assert_eq!(layout.children[1].x, 0.0);
2196        assert_eq!(layout.children[1].y, 50.0);
2197    }
2198
2199    #[test]
2200    fn flex_grow_in_at_most_container() {
2201        let layout = stretch::compute(&stretch::style::Node {
2202            align_items: stretch::style::AlignItems::FlexStart,
2203            width: stretch::style::Dimension::Points(100.0),
2204            height: stretch::style::Dimension::Points(100.0),
2205            children: vec![stretch::style::Node {
2206                children: vec![stretch::style::Node {
2207                    flex_grow: 1.0,
2208                    flex_basis: stretch::style::Dimension::Points(0.0),
2209                    ..Default::default()
2210                }],
2211                ..Default::default()
2212            }],
2213            ..Default::default()
2214        });
2215
2216        assert_eq!(layout.width, 100.0);
2217        assert_eq!(layout.height, 100.0);
2218        assert_eq!(layout.x, 0.0);
2219        assert_eq!(layout.y, 0.0);
2220
2221        assert_eq!(layout.children[0].width, 0.0);
2222        assert_eq!(layout.children[0].height, 0.0);
2223        assert_eq!(layout.children[0].x, 0.0);
2224        assert_eq!(layout.children[0].y, 0.0);
2225
2226        assert_eq!(layout.children[0].children[0].width, 0.0);
2227        assert_eq!(layout.children[0].children[0].height, 0.0);
2228        assert_eq!(layout.children[0].children[0].x, 0.0);
2229        assert_eq!(layout.children[0].children[0].y, 0.0);
2230    }
2231
2232    #[test]
2233    fn margin_auto_left() {
2234        let layout = stretch::compute(&stretch::style::Node {
2235            align_items: stretch::style::AlignItems::Center,
2236            width: stretch::style::Dimension::Points(200.0),
2237            height: stretch::style::Dimension::Points(200.0),
2238            children: vec![
2239                stretch::style::Node {
2240                    width: stretch::style::Dimension::Points(50.0),
2241                    height: stretch::style::Dimension::Points(50.0),
2242                    margin: stretch::style::Edges {
2243                        start: stretch::style::Dimension::Auto,
2244                        ..Default::default()
2245                    },
2246                    ..Default::default()
2247                },
2248                stretch::style::Node {
2249                    width: stretch::style::Dimension::Points(50.0),
2250                    height: stretch::style::Dimension::Points(50.0),
2251                    ..Default::default()
2252                },
2253            ],
2254            ..Default::default()
2255        });
2256
2257        assert_eq!(layout.width, 200.0);
2258        assert_eq!(layout.height, 200.0);
2259        assert_eq!(layout.x, 0.0);
2260        assert_eq!(layout.y, 0.0);
2261
2262        assert_eq!(layout.children[0].width, 50.0);
2263        assert_eq!(layout.children[0].height, 50.0);
2264        assert_eq!(layout.children[0].x, 100.0);
2265        assert_eq!(layout.children[0].y, 75.0);
2266
2267        assert_eq!(layout.children[1].width, 50.0);
2268        assert_eq!(layout.children[1].height, 50.0);
2269        assert_eq!(layout.children[1].x, 150.0);
2270        assert_eq!(layout.children[1].y, 75.0);
2271    }
2272
2273    #[test]
2274    fn percentage_flex_basis_cross() {
2275        let layout = stretch::compute(&stretch::style::Node {
2276            flex_direction: stretch::style::FlexDirection::Column,
2277            width: stretch::style::Dimension::Points(200.0),
2278            height: stretch::style::Dimension::Points(200.0),
2279            children: vec![
2280                stretch::style::Node {
2281                    flex_grow: 1.0,
2282                    flex_basis: stretch::style::Dimension::Percent(0.5),
2283                    ..Default::default()
2284                },
2285                stretch::style::Node {
2286                    flex_grow: 1.0,
2287                    flex_basis: stretch::style::Dimension::Percent(0.2),
2288                    ..Default::default()
2289                },
2290            ],
2291            ..Default::default()
2292        });
2293
2294        assert_eq!(layout.width, 200.0);
2295        assert_eq!(layout.height, 200.0);
2296        assert_eq!(layout.x, 0.0);
2297        assert_eq!(layout.y, 0.0);
2298
2299        assert_eq!(layout.children[0].width, 200.0);
2300        assert_eq!(layout.children[0].height, 125.0);
2301        assert_eq!(layout.children[0].x, 0.0);
2302        assert_eq!(layout.children[0].y, 0.0);
2303
2304        assert_eq!(layout.children[1].width, 200.0);
2305        assert_eq!(layout.children[1].height, 75.0);
2306        assert_eq!(layout.children[1].x, 0.0);
2307        assert_eq!(layout.children[1].y, 125.0);
2308    }
2309
2310    #[test]
2311    fn percentage_absolute_position() {
2312        let layout = stretch::compute(&stretch::style::Node {
2313            flex_direction: stretch::style::FlexDirection::Column,
2314            width: stretch::style::Dimension::Points(200.0),
2315            height: stretch::style::Dimension::Points(100.0),
2316            children: vec![stretch::style::Node {
2317                position: stretch::style::Position::Absolute,
2318                width: stretch::style::Dimension::Points(10.0),
2319                height: stretch::style::Dimension::Points(10.0),
2320                start: stretch::style::Dimension::Percent(0.3),
2321                top: stretch::style::Dimension::Percent(0.1),
2322                ..Default::default()
2323            }],
2324            ..Default::default()
2325        });
2326
2327        assert_eq!(layout.width, 200.0);
2328        assert_eq!(layout.height, 100.0);
2329        assert_eq!(layout.x, 0.0);
2330        assert_eq!(layout.y, 0.0);
2331
2332        assert_eq!(layout.children[0].width, 10.0);
2333        assert_eq!(layout.children[0].height, 10.0);
2334        assert_eq!(layout.children[0].x, 60.0);
2335        assert_eq!(layout.children[0].y, 10.0);
2336    }
2337
2338    #[test]
2339    fn flex_basis_flex_grow_row() {
2340        let layout = stretch::compute(&stretch::style::Node {
2341            width: stretch::style::Dimension::Points(100.0),
2342            height: stretch::style::Dimension::Points(100.0),
2343            children: vec![
2344                stretch::style::Node {
2345                    flex_grow: 1.0,
2346                    flex_basis: stretch::style::Dimension::Points(50.0),
2347                    ..Default::default()
2348                },
2349                stretch::style::Node {
2350                    flex_grow: 1.0,
2351                    ..Default::default()
2352                },
2353            ],
2354            ..Default::default()
2355        });
2356
2357        assert_eq!(layout.width, 100.0);
2358        assert_eq!(layout.height, 100.0);
2359        assert_eq!(layout.x, 0.0);
2360        assert_eq!(layout.y, 0.0);
2361
2362        assert_eq!(layout.children[0].width, 75.0);
2363        assert_eq!(layout.children[0].height, 100.0);
2364        assert_eq!(layout.children[0].x, 0.0);
2365        assert_eq!(layout.children[0].y, 0.0);
2366
2367        assert_eq!(layout.children[1].width, 25.0);
2368        assert_eq!(layout.children[1].height, 100.0);
2369        assert_eq!(layout.children[1].x, 75.0);
2370        assert_eq!(layout.children[1].y, 0.0);
2371    }
2372
2373    #[test]
2374    fn absolute_layout_in_wrap_reverse_column_container_flex_end() {
2375        let layout = stretch::compute(&stretch::style::Node {
2376            flex_direction: stretch::style::FlexDirection::Column,
2377            width: stretch::style::Dimension::Points(100.0),
2378            height: stretch::style::Dimension::Points(100.0),
2379            children: vec![stretch::style::Node {
2380                position: stretch::style::Position::Absolute,
2381                align_self: stretch::style::AlignSelf::FlexEnd,
2382                width: stretch::style::Dimension::Points(20.0),
2383                height: stretch::style::Dimension::Points(20.0),
2384                ..Default::default()
2385            }],
2386            ..Default::default()
2387        });
2388
2389        assert_eq!(layout.width, 100.0);
2390        assert_eq!(layout.height, 100.0);
2391        assert_eq!(layout.x, 0.0);
2392        assert_eq!(layout.y, 0.0);
2393
2394        assert_eq!(layout.children[0].width, 20.0);
2395        assert_eq!(layout.children[0].height, 20.0);
2396        assert_eq!(layout.children[0].x, 0.0);
2397        assert_eq!(layout.children[0].y, 0.0);
2398    }
2399
2400    #[test]
2401    fn justify_content_row_flex_start() {
2402        let layout = stretch::compute(&stretch::style::Node {
2403            width: stretch::style::Dimension::Points(100.0),
2404            height: stretch::style::Dimension::Points(100.0),
2405            children: vec![
2406                stretch::style::Node {
2407                    width: stretch::style::Dimension::Points(10.0),
2408                    ..Default::default()
2409                },
2410                stretch::style::Node {
2411                    width: stretch::style::Dimension::Points(10.0),
2412                    ..Default::default()
2413                },
2414                stretch::style::Node {
2415                    width: stretch::style::Dimension::Points(10.0),
2416                    ..Default::default()
2417                },
2418            ],
2419            ..Default::default()
2420        });
2421
2422        assert_eq!(layout.width, 100.0);
2423        assert_eq!(layout.height, 100.0);
2424        assert_eq!(layout.x, 0.0);
2425        assert_eq!(layout.y, 0.0);
2426
2427        assert_eq!(layout.children[0].width, 10.0);
2428        assert_eq!(layout.children[0].height, 100.0);
2429        assert_eq!(layout.children[0].x, 0.0);
2430        assert_eq!(layout.children[0].y, 0.0);
2431
2432        assert_eq!(layout.children[1].width, 10.0);
2433        assert_eq!(layout.children[1].height, 100.0);
2434        assert_eq!(layout.children[1].x, 10.0);
2435        assert_eq!(layout.children[1].y, 0.0);
2436
2437        assert_eq!(layout.children[2].width, 10.0);
2438        assert_eq!(layout.children[2].height, 100.0);
2439        assert_eq!(layout.children[2].x, 20.0);
2440        assert_eq!(layout.children[2].y, 0.0);
2441    }
2442
2443    #[test]
2444    fn margin_auto_left_right_child_bigger_than_parent() {
2445        let layout = stretch::compute(&stretch::style::Node {
2446            justify_content: stretch::style::JustifyContent::Center,
2447            width: stretch::style::Dimension::Points(52.0),
2448            height: stretch::style::Dimension::Points(52.0),
2449            children: vec![stretch::style::Node {
2450                width: stretch::style::Dimension::Points(72.0),
2451                height: stretch::style::Dimension::Points(72.0),
2452                margin: stretch::style::Edges {
2453                    start: stretch::style::Dimension::Auto,
2454                    end: stretch::style::Dimension::Auto,
2455                    ..Default::default()
2456                },
2457                ..Default::default()
2458            }],
2459            ..Default::default()
2460        });
2461
2462        assert_eq!(layout.width, 52.0);
2463        assert_eq!(layout.height, 52.0);
2464        assert_eq!(layout.x, 0.0);
2465        assert_eq!(layout.y, 0.0);
2466
2467        assert_eq!(layout.children[0].width, 52.0);
2468        assert_eq!(layout.children[0].height, 72.0);
2469        assert_eq!(layout.children[0].x, 0.0);
2470        assert_eq!(layout.children[0].y, 0.0);
2471    }
2472
2473    #[test]
2474    fn margin_fix_left_auto_right_child_bigger_than_parent() {
2475        let layout = stretch::compute(&stretch::style::Node {
2476            justify_content: stretch::style::JustifyContent::Center,
2477            width: stretch::style::Dimension::Points(52.0),
2478            height: stretch::style::Dimension::Points(52.0),
2479            children: vec![stretch::style::Node {
2480                width: stretch::style::Dimension::Points(72.0),
2481                height: stretch::style::Dimension::Points(72.0),
2482                margin: stretch::style::Edges {
2483                    start: stretch::style::Dimension::Points(10.0),
2484                    end: stretch::style::Dimension::Auto,
2485                    ..Default::default()
2486                },
2487                ..Default::default()
2488            }],
2489            ..Default::default()
2490        });
2491
2492        assert_eq!(layout.width, 52.0);
2493        assert_eq!(layout.height, 52.0);
2494        assert_eq!(layout.x, 0.0);
2495        assert_eq!(layout.y, 0.0);
2496
2497        assert_eq!(layout.children[0].width, 42.0);
2498        assert_eq!(layout.children[0].height, 72.0);
2499        assert_eq!(layout.children[0].x, 10.0);
2500        assert_eq!(layout.children[0].y, 0.0);
2501    }
2502
2503    #[test]
2504    fn percentage_container_in_wrapping_container() {
2505        let layout = stretch::compute(&stretch::style::Node {
2506            flex_direction: stretch::style::FlexDirection::Column,
2507            align_items: stretch::style::AlignItems::Center,
2508            justify_content: stretch::style::JustifyContent::Center,
2509            width: stretch::style::Dimension::Points(200.0),
2510            height: stretch::style::Dimension::Points(200.0),
2511            children: vec![stretch::style::Node {
2512                flex_direction: stretch::style::FlexDirection::Column,
2513                children: vec![stretch::style::Node {
2514                    justify_content: stretch::style::JustifyContent::Center,
2515                    width: stretch::style::Dimension::Percent(1.0),
2516                    children: vec![
2517                        stretch::style::Node {
2518                            width: stretch::style::Dimension::Points(50.0),
2519                            height: stretch::style::Dimension::Points(50.0),
2520                            ..Default::default()
2521                        },
2522                        stretch::style::Node {
2523                            width: stretch::style::Dimension::Points(50.0),
2524                            height: stretch::style::Dimension::Points(50.0),
2525                            ..Default::default()
2526                        },
2527                    ],
2528                    ..Default::default()
2529                }],
2530                ..Default::default()
2531            }],
2532            ..Default::default()
2533        });
2534
2535        assert_eq!(layout.width, 200.0);
2536        assert_eq!(layout.height, 200.0);
2537        assert_eq!(layout.x, 0.0);
2538        assert_eq!(layout.y, 0.0);
2539
2540        assert_eq!(layout.children[0].width, 100.0);
2541        assert_eq!(layout.children[0].height, 50.0);
2542        assert_eq!(layout.children[0].x, 50.0);
2543        assert_eq!(layout.children[0].y, 75.0);
2544
2545        assert_eq!(layout.children[0].children[0].width, 100.0);
2546        assert_eq!(layout.children[0].children[0].height, 50.0);
2547        assert_eq!(layout.children[0].children[0].x, 0.0);
2548        assert_eq!(layout.children[0].children[0].y, 0.0);
2549
2550        assert_eq!(layout.children[0].children[0].children[0].width, 50.0);
2551        assert_eq!(layout.children[0].children[0].children[0].height, 50.0);
2552        assert_eq!(layout.children[0].children[0].children[0].x, 0.0);
2553        assert_eq!(layout.children[0].children[0].children[0].y, 0.0);
2554
2555        assert_eq!(layout.children[0].children[0].children[1].width, 50.0);
2556        assert_eq!(layout.children[0].children[0].children[1].height, 50.0);
2557        assert_eq!(layout.children[0].children[0].children[1].x, 50.0);
2558        assert_eq!(layout.children[0].children[0].children[1].y, 0.0);
2559    }
2560
2561    #[test]
2562    fn margin_auto_left_stretching_child() {
2563        let layout = stretch::compute(&stretch::style::Node {
2564            align_items: stretch::style::AlignItems::Center,
2565            width: stretch::style::Dimension::Points(200.0),
2566            height: stretch::style::Dimension::Points(200.0),
2567            children: vec![
2568                stretch::style::Node {
2569                    flex_grow: 1.0,
2570                    flex_shrink: 1.0,
2571                    flex_basis: stretch::style::Dimension::Percent(0.0),
2572                    margin: stretch::style::Edges {
2573                        start: stretch::style::Dimension::Auto,
2574                        ..Default::default()
2575                    },
2576                    ..Default::default()
2577                },
2578                stretch::style::Node {
2579                    width: stretch::style::Dimension::Points(50.0),
2580                    height: stretch::style::Dimension::Points(50.0),
2581                    ..Default::default()
2582                },
2583            ],
2584            ..Default::default()
2585        });
2586
2587        assert_eq!(layout.width, 200.0);
2588        assert_eq!(layout.height, 200.0);
2589        assert_eq!(layout.x, 0.0);
2590        assert_eq!(layout.y, 0.0);
2591
2592        assert_eq!(layout.children[0].width, 150.0);
2593        assert_eq!(layout.children[0].height, 0.0);
2594        assert_eq!(layout.children[0].x, 0.0);
2595        assert_eq!(layout.children[0].y, 100.0);
2596
2597        assert_eq!(layout.children[1].width, 50.0);
2598        assert_eq!(layout.children[1].height, 50.0);
2599        assert_eq!(layout.children[1].x, 150.0);
2600        assert_eq!(layout.children[1].y, 75.0);
2601    }
2602
2603    #[test]
2604    fn percentage_flex_basis_cross_max_width() {
2605        let layout = stretch::compute(&stretch::style::Node {
2606            flex_direction: stretch::style::FlexDirection::Column,
2607            width: stretch::style::Dimension::Points(200.0),
2608            height: stretch::style::Dimension::Points(200.0),
2609            children: vec![
2610                stretch::style::Node {
2611                    flex_grow: 1.0,
2612                    flex_basis: stretch::style::Dimension::Percent(0.1),
2613                    max_width: stretch::style::Dimension::Percent(0.6),
2614                    ..Default::default()
2615                },
2616                stretch::style::Node {
2617                    flex_grow: 4.0,
2618                    flex_basis: stretch::style::Dimension::Percent(0.2),
2619                    max_width: stretch::style::Dimension::Percent(0.2),
2620                    ..Default::default()
2621                },
2622            ],
2623            ..Default::default()
2624        });
2625
2626        assert_eq!(layout.width, 200.0);
2627        assert_eq!(layout.height, 200.0);
2628        assert_eq!(layout.x, 0.0);
2629        assert_eq!(layout.y, 0.0);
2630
2631        assert_eq!(layout.children[0].width, 120.0);
2632        assert_eq!(layout.children[0].height, 50.0);
2633        assert_eq!(layout.children[0].x, 0.0);
2634        assert_eq!(layout.children[0].y, 0.0);
2635
2636        assert_eq!(layout.children[1].width, 40.0);
2637        assert_eq!(layout.children[1].height, 150.0);
2638        assert_eq!(layout.children[1].x, 0.0);
2639        assert_eq!(layout.children[1].y, 50.0);
2640    }
2641
2642    #[test]
2643    fn align_items_flex_end_child_without_margin_bigger_than_parent() {
2644        let layout = stretch::compute(&stretch::style::Node {
2645            align_items: stretch::style::AlignItems::Center,
2646            justify_content: stretch::style::JustifyContent::Center,
2647            width: stretch::style::Dimension::Points(52.0),
2648            height: stretch::style::Dimension::Points(52.0),
2649            children: vec![stretch::style::Node {
2650                align_items: stretch::style::AlignItems::FlexEnd,
2651                children: vec![stretch::style::Node {
2652                    width: stretch::style::Dimension::Points(72.0),
2653                    height: stretch::style::Dimension::Points(72.0),
2654                    ..Default::default()
2655                }],
2656                ..Default::default()
2657            }],
2658            ..Default::default()
2659        });
2660
2661        assert_eq!(layout.width, 52.0);
2662        assert_eq!(layout.height, 52.0);
2663        assert_eq!(layout.x, 0.0);
2664        assert_eq!(layout.y, 0.0);
2665
2666        assert_eq!(layout.children[0].width, 72.0);
2667        assert_eq!(layout.children[0].height, 72.0);
2668        assert_eq!(layout.children[0].x, -10.0);
2669        assert_eq!(layout.children[0].y, -10.0);
2670
2671        assert_eq!(layout.children[0].children[0].width, 72.0);
2672        assert_eq!(layout.children[0].children[0].height, 72.0);
2673        assert_eq!(layout.children[0].children[0].x, 0.0);
2674        assert_eq!(layout.children[0].children[0].y, 0.0);
2675    }
2676
2677    #[test]
2678    fn size_defined_by_child_with_padding() {
2679        let layout = stretch::compute(&stretch::style::Node {
2680            padding: stretch::style::Edges {
2681                start: stretch::style::Dimension::Points(10.0),
2682                end: stretch::style::Dimension::Points(10.0),
2683                top: stretch::style::Dimension::Points(10.0),
2684                bottom: stretch::style::Dimension::Points(10.0),
2685                ..Default::default()
2686            },
2687            children: vec![stretch::style::Node {
2688                width: stretch::style::Dimension::Points(10.0),
2689                height: stretch::style::Dimension::Points(10.0),
2690                ..Default::default()
2691            }],
2692            ..Default::default()
2693        });
2694
2695        assert_eq!(layout.width, 30.0);
2696        assert_eq!(layout.height, 30.0);
2697        assert_eq!(layout.x, 0.0);
2698        assert_eq!(layout.y, 0.0);
2699
2700        assert_eq!(layout.children[0].width, 10.0);
2701        assert_eq!(layout.children[0].height, 10.0);
2702        assert_eq!(layout.children[0].x, 10.0);
2703        assert_eq!(layout.children[0].y, 10.0);
2704    }
2705
2706    #[test]
2707    fn absolute_layout_within_border() {
2708        let layout = stretch::compute(&stretch::style::Node {
2709            width: stretch::style::Dimension::Points(100.0),
2710            height: stretch::style::Dimension::Points(100.0),
2711            padding: stretch::style::Edges {
2712                start: stretch::style::Dimension::Points(10.0),
2713                end: stretch::style::Dimension::Points(10.0),
2714                top: stretch::style::Dimension::Points(10.0),
2715                bottom: stretch::style::Dimension::Points(10.0),
2716                ..Default::default()
2717            },
2718            border: stretch::style::Edges {
2719                start: stretch::style::Dimension::Points(10.0),
2720                end: stretch::style::Dimension::Points(10.0),
2721                top: stretch::style::Dimension::Points(10.0),
2722                bottom: stretch::style::Dimension::Points(10.0),
2723                ..Default::default()
2724            },
2725            children: vec![
2726                stretch::style::Node {
2727                    position: stretch::style::Position::Absolute,
2728                    width: stretch::style::Dimension::Points(50.0),
2729                    height: stretch::style::Dimension::Points(50.0),
2730                    start: stretch::style::Dimension::Points(0.0),
2731                    top: stretch::style::Dimension::Points(0.0),
2732                    ..Default::default()
2733                },
2734                stretch::style::Node {
2735                    position: stretch::style::Position::Absolute,
2736                    width: stretch::style::Dimension::Points(50.0),
2737                    height: stretch::style::Dimension::Points(50.0),
2738                    end: stretch::style::Dimension::Points(0.0),
2739                    bottom: stretch::style::Dimension::Points(0.0),
2740                    ..Default::default()
2741                },
2742                stretch::style::Node {
2743                    position: stretch::style::Position::Absolute,
2744                    width: stretch::style::Dimension::Points(50.0),
2745                    height: stretch::style::Dimension::Points(50.0),
2746                    margin: stretch::style::Edges {
2747                        start: stretch::style::Dimension::Points(10.0),
2748                        end: stretch::style::Dimension::Points(10.0),
2749                        top: stretch::style::Dimension::Points(10.0),
2750                        bottom: stretch::style::Dimension::Points(10.0),
2751                        ..Default::default()
2752                    },
2753                    start: stretch::style::Dimension::Points(0.0),
2754                    top: stretch::style::Dimension::Points(0.0),
2755                    ..Default::default()
2756                },
2757                stretch::style::Node {
2758                    position: stretch::style::Position::Absolute,
2759                    width: stretch::style::Dimension::Points(50.0),
2760                    height: stretch::style::Dimension::Points(50.0),
2761                    margin: stretch::style::Edges {
2762                        start: stretch::style::Dimension::Points(10.0),
2763                        end: stretch::style::Dimension::Points(10.0),
2764                        top: stretch::style::Dimension::Points(10.0),
2765                        bottom: stretch::style::Dimension::Points(10.0),
2766                        ..Default::default()
2767                    },
2768                    end: stretch::style::Dimension::Points(0.0),
2769                    bottom: stretch::style::Dimension::Points(0.0),
2770                    ..Default::default()
2771                },
2772            ],
2773            ..Default::default()
2774        });
2775
2776        assert_eq!(layout.width, 100.0);
2777        assert_eq!(layout.height, 100.0);
2778        assert_eq!(layout.x, 0.0);
2779        assert_eq!(layout.y, 0.0);
2780
2781        assert_eq!(layout.children[0].width, 50.0);
2782        assert_eq!(layout.children[0].height, 50.0);
2783        assert_eq!(layout.children[0].x, 10.0);
2784        assert_eq!(layout.children[0].y, 10.0);
2785
2786        assert_eq!(layout.children[1].width, 50.0);
2787        assert_eq!(layout.children[1].height, 50.0);
2788        assert_eq!(layout.children[1].x, 40.0);
2789        assert_eq!(layout.children[1].y, 40.0);
2790
2791        assert_eq!(layout.children[2].width, 50.0);
2792        assert_eq!(layout.children[2].height, 50.0);
2793        assert_eq!(layout.children[2].x, 20.0);
2794        assert_eq!(layout.children[2].y, 20.0);
2795
2796        assert_eq!(layout.children[3].width, 50.0);
2797        assert_eq!(layout.children[3].height, 50.0);
2798        assert_eq!(layout.children[3].x, 30.0);
2799        assert_eq!(layout.children[3].y, 30.0);
2800    }
2801
2802    #[test]
2803    fn margin_auto_left_fix_right_child_bigger_than_parent() {
2804        let layout = stretch::compute(&stretch::style::Node {
2805            justify_content: stretch::style::JustifyContent::Center,
2806            width: stretch::style::Dimension::Points(52.0),
2807            height: stretch::style::Dimension::Points(52.0),
2808            children: vec![stretch::style::Node {
2809                width: stretch::style::Dimension::Points(72.0),
2810                height: stretch::style::Dimension::Points(72.0),
2811                margin: stretch::style::Edges {
2812                    start: stretch::style::Dimension::Auto,
2813                    end: stretch::style::Dimension::Points(10.0),
2814                    ..Default::default()
2815                },
2816                ..Default::default()
2817            }],
2818            ..Default::default()
2819        });
2820
2821        assert_eq!(layout.width, 52.0);
2822        assert_eq!(layout.height, 52.0);
2823        assert_eq!(layout.x, 0.0);
2824        assert_eq!(layout.y, 0.0);
2825
2826        assert_eq!(layout.children[0].width, 42.0);
2827        assert_eq!(layout.children[0].height, 72.0);
2828        assert_eq!(layout.children[0].x, 0.0);
2829        assert_eq!(layout.children[0].y, 0.0);
2830    }
2831
2832    #[test]
2833    fn justify_content_row_flex_end() {
2834        let layout = stretch::compute(&stretch::style::Node {
2835            justify_content: stretch::style::JustifyContent::FlexEnd,
2836            width: stretch::style::Dimension::Points(100.0),
2837            height: stretch::style::Dimension::Points(100.0),
2838            children: vec![
2839                stretch::style::Node {
2840                    width: stretch::style::Dimension::Points(10.0),
2841                    ..Default::default()
2842                },
2843                stretch::style::Node {
2844                    width: stretch::style::Dimension::Points(10.0),
2845                    ..Default::default()
2846                },
2847                stretch::style::Node {
2848                    width: stretch::style::Dimension::Points(10.0),
2849                    ..Default::default()
2850                },
2851            ],
2852            ..Default::default()
2853        });
2854
2855        assert_eq!(layout.width, 100.0);
2856        assert_eq!(layout.height, 100.0);
2857        assert_eq!(layout.x, 0.0);
2858        assert_eq!(layout.y, 0.0);
2859
2860        assert_eq!(layout.children[0].width, 10.0);
2861        assert_eq!(layout.children[0].height, 100.0);
2862        assert_eq!(layout.children[0].x, 70.0);
2863        assert_eq!(layout.children[0].y, 0.0);
2864
2865        assert_eq!(layout.children[1].width, 10.0);
2866        assert_eq!(layout.children[1].height, 100.0);
2867        assert_eq!(layout.children[1].x, 80.0);
2868        assert_eq!(layout.children[1].y, 0.0);
2869
2870        assert_eq!(layout.children[2].width, 10.0);
2871        assert_eq!(layout.children[2].height, 100.0);
2872        assert_eq!(layout.children[2].x, 90.0);
2873        assert_eq!(layout.children[2].y, 0.0);
2874    }
2875
2876    #[test]
2877    fn margin_bottom() {
2878        let layout = stretch::compute(&stretch::style::Node {
2879            flex_direction: stretch::style::FlexDirection::Column,
2880            justify_content: stretch::style::JustifyContent::FlexEnd,
2881            width: stretch::style::Dimension::Points(100.0),
2882            height: stretch::style::Dimension::Points(100.0),
2883            children: vec![stretch::style::Node {
2884                height: stretch::style::Dimension::Points(10.0),
2885                margin: stretch::style::Edges {
2886                    bottom: stretch::style::Dimension::Points(10.0),
2887                    ..Default::default()
2888                },
2889                ..Default::default()
2890            }],
2891            ..Default::default()
2892        });
2893
2894        assert_eq!(layout.width, 100.0);
2895        assert_eq!(layout.height, 100.0);
2896        assert_eq!(layout.x, 0.0);
2897        assert_eq!(layout.y, 0.0);
2898
2899        assert_eq!(layout.children[0].width, 100.0);
2900        assert_eq!(layout.children[0].height, 10.0);
2901        assert_eq!(layout.children[0].x, 0.0);
2902        assert_eq!(layout.children[0].y, 80.0);
2903    }
2904
2905    #[test]
2906    fn margin_should_not_be_part_of_max_height() {
2907        let layout = stretch::compute(&stretch::style::Node {
2908            width: stretch::style::Dimension::Points(250.0),
2909            height: stretch::style::Dimension::Points(250.0),
2910            children: vec![stretch::style::Node {
2911                width: stretch::style::Dimension::Points(100.0),
2912                height: stretch::style::Dimension::Points(100.0),
2913                max_height: stretch::style::Dimension::Points(100.0),
2914                margin: stretch::style::Edges {
2915                    top: stretch::style::Dimension::Points(20.0),
2916                    ..Default::default()
2917                },
2918                ..Default::default()
2919            }],
2920            ..Default::default()
2921        });
2922
2923        assert_eq!(layout.width, 250.0);
2924        assert_eq!(layout.height, 250.0);
2925        assert_eq!(layout.x, 0.0);
2926        assert_eq!(layout.y, 0.0);
2927
2928        assert_eq!(layout.children[0].width, 100.0);
2929        assert_eq!(layout.children[0].height, 100.0);
2930        assert_eq!(layout.children[0].x, 0.0);
2931        assert_eq!(layout.children[0].y, 20.0);
2932    }
2933
2934    #[test]
2935    fn percentage_flex_basis_cross_min_height() {
2936        let layout = stretch::compute(&stretch::style::Node {
2937            flex_direction: stretch::style::FlexDirection::Column,
2938            width: stretch::style::Dimension::Points(200.0),
2939            height: stretch::style::Dimension::Points(200.0),
2940            children: vec![
2941                stretch::style::Node {
2942                    flex_grow: 1.0,
2943                    min_height: stretch::style::Dimension::Percent(0.6),
2944                    ..Default::default()
2945                },
2946                stretch::style::Node {
2947                    flex_grow: 2.0,
2948                    min_height: stretch::style::Dimension::Percent(0.1),
2949                    ..Default::default()
2950                },
2951            ],
2952            ..Default::default()
2953        });
2954
2955        assert_eq!(layout.width, 200.0);
2956        assert_eq!(layout.height, 200.0);
2957        assert_eq!(layout.x, 0.0);
2958        assert_eq!(layout.y, 0.0);
2959
2960        assert_eq!(layout.children[0].width, 200.0);
2961        assert_eq!(layout.children[0].height, 140.0);
2962        assert_eq!(layout.children[0].x, 0.0);
2963        assert_eq!(layout.children[0].y, 0.0);
2964
2965        assert_eq!(layout.children[1].width, 200.0);
2966        assert_eq!(layout.children[1].height, 60.0);
2967        assert_eq!(layout.children[1].x, 0.0);
2968        assert_eq!(layout.children[1].y, 140.0);
2969    }
2970
2971    #[test]
2972    fn nested_overflowing_child_in_constraint_parent() {
2973        let layout = stretch::compute(&stretch::style::Node {
2974            width: stretch::style::Dimension::Points(100.0),
2975            height: stretch::style::Dimension::Points(100.0),
2976            children: vec![stretch::style::Node {
2977                width: stretch::style::Dimension::Points(100.0),
2978                height: stretch::style::Dimension::Points(100.0),
2979                children: vec![stretch::style::Node {
2980                    width: stretch::style::Dimension::Points(200.0),
2981                    height: stretch::style::Dimension::Points(200.0),
2982                    ..Default::default()
2983                }],
2984                ..Default::default()
2985            }],
2986            ..Default::default()
2987        });
2988
2989        assert_eq!(layout.width, 100.0);
2990        assert_eq!(layout.height, 100.0);
2991        assert_eq!(layout.x, 0.0);
2992        assert_eq!(layout.y, 0.0);
2993
2994        assert_eq!(layout.children[0].width, 100.0);
2995        assert_eq!(layout.children[0].height, 100.0);
2996        assert_eq!(layout.children[0].x, 0.0);
2997        assert_eq!(layout.children[0].y, 0.0);
2998
2999        assert_eq!(layout.children[0].children[0].width, 100.0);
3000        assert_eq!(layout.children[0].children[0].height, 200.0);
3001        assert_eq!(layout.children[0].children[0].x, 0.0);
3002        assert_eq!(layout.children[0].children[0].y, 0.0);
3003    }
3004
3005    #[test]
3006    fn wrapped_row_within_align_items_center() {
3007        let layout = stretch::compute(&stretch::style::Node {
3008            flex_direction: stretch::style::FlexDirection::Column,
3009            align_items: stretch::style::AlignItems::Center,
3010            width: stretch::style::Dimension::Points(200.0),
3011            height: stretch::style::Dimension::Points(200.0),
3012            children: vec![stretch::style::Node {
3013                children: vec![
3014                    stretch::style::Node {
3015                        width: stretch::style::Dimension::Points(150.0),
3016                        height: stretch::style::Dimension::Points(80.0),
3017                        ..Default::default()
3018                    },
3019                    stretch::style::Node {
3020                        width: stretch::style::Dimension::Points(80.0),
3021                        height: stretch::style::Dimension::Points(80.0),
3022                        ..Default::default()
3023                    },
3024                ],
3025                ..Default::default()
3026            }],
3027            ..Default::default()
3028        });
3029
3030        assert_eq!(layout.width, 200.0);
3031        assert_eq!(layout.height, 200.0);
3032        assert_eq!(layout.x, 0.0);
3033        assert_eq!(layout.y, 0.0);
3034
3035        assert_eq!(layout.children[0].width, 200.0);
3036        assert_eq!(layout.children[0].height, 160.0);
3037        assert_eq!(layout.children[0].x, 0.0);
3038        assert_eq!(layout.children[0].y, 0.0);
3039
3040        assert_eq!(layout.children[0].children[0].width, 150.0);
3041        assert_eq!(layout.children[0].children[0].height, 80.0);
3042        assert_eq!(layout.children[0].children[0].x, 0.0);
3043        assert_eq!(layout.children[0].children[0].y, 0.0);
3044
3045        assert_eq!(layout.children[0].children[1].width, 80.0);
3046        assert_eq!(layout.children[0].children[1].height, 80.0);
3047        assert_eq!(layout.children[0].children[1].x, 0.0);
3048        assert_eq!(layout.children[0].children[1].y, 80.0);
3049    }
3050
3051    #[test]
3052    fn justify_content_column_center() {
3053        let layout = stretch::compute(&stretch::style::Node {
3054            flex_direction: stretch::style::FlexDirection::Column,
3055            justify_content: stretch::style::JustifyContent::Center,
3056            width: stretch::style::Dimension::Points(100.0),
3057            height: stretch::style::Dimension::Points(100.0),
3058            children: vec![
3059                stretch::style::Node {
3060                    height: stretch::style::Dimension::Points(10.0),
3061                    ..Default::default()
3062                },
3063                stretch::style::Node {
3064                    height: stretch::style::Dimension::Points(10.0),
3065                    ..Default::default()
3066                },
3067                stretch::style::Node {
3068                    height: stretch::style::Dimension::Points(10.0),
3069                    ..Default::default()
3070                },
3071            ],
3072            ..Default::default()
3073        });
3074
3075        assert_eq!(layout.width, 100.0);
3076        assert_eq!(layout.height, 100.0);
3077        assert_eq!(layout.x, 0.0);
3078        assert_eq!(layout.y, 0.0);
3079
3080        assert_eq!(layout.children[0].width, 100.0);
3081        assert_eq!(layout.children[0].height, 10.0);
3082        assert_eq!(layout.children[0].x, 0.0);
3083        assert_eq!(layout.children[0].y, 35.0);
3084
3085        assert_eq!(layout.children[1].width, 100.0);
3086        assert_eq!(layout.children[1].height, 10.0);
3087        assert_eq!(layout.children[1].x, 0.0);
3088        assert_eq!(layout.children[1].y, 45.0);
3089
3090        assert_eq!(layout.children[2].width, 100.0);
3091        assert_eq!(layout.children[2].height, 10.0);
3092        assert_eq!(layout.children[2].x, 0.0);
3093        assert_eq!(layout.children[2].y, 55.0);
3094    }
3095
3096    #[test]
3097    fn align_items_center_child_with_margin_bigger_than_parent() {
3098        let layout = stretch::compute(&stretch::style::Node {
3099            align_items: stretch::style::AlignItems::Center,
3100            justify_content: stretch::style::JustifyContent::Center,
3101            width: stretch::style::Dimension::Points(52.0),
3102            height: stretch::style::Dimension::Points(52.0),
3103            children: vec![stretch::style::Node {
3104                align_items: stretch::style::AlignItems::Center,
3105                children: vec![stretch::style::Node {
3106                    width: stretch::style::Dimension::Points(52.0),
3107                    height: stretch::style::Dimension::Points(52.0),
3108                    margin: stretch::style::Edges {
3109                        start: stretch::style::Dimension::Points(10.0),
3110                        end: stretch::style::Dimension::Points(10.0),
3111                        ..Default::default()
3112                    },
3113                    ..Default::default()
3114                }],
3115                ..Default::default()
3116            }],
3117            ..Default::default()
3118        });
3119
3120        assert_eq!(layout.width, 52.0);
3121        assert_eq!(layout.height, 52.0);
3122        assert_eq!(layout.x, 0.0);
3123        assert_eq!(layout.y, 0.0);
3124
3125        assert_eq!(layout.children[0].width, 72.0);
3126        assert_eq!(layout.children[0].height, 52.0);
3127        assert_eq!(layout.children[0].x, -10.0);
3128        assert_eq!(layout.children[0].y, 0.0);
3129
3130        assert_eq!(layout.children[0].children[0].width, 52.0);
3131        assert_eq!(layout.children[0].children[0].height, 52.0);
3132        assert_eq!(layout.children[0].children[0].x, 10.0);
3133        assert_eq!(layout.children[0].children[0].y, 0.0);
3134    }
3135
3136    #[test]
3137    fn percentage_width_height() {
3138        let layout = stretch::compute(&stretch::style::Node {
3139            width: stretch::style::Dimension::Points(200.0),
3140            height: stretch::style::Dimension::Points(200.0),
3141            children: vec![stretch::style::Node {
3142                width: stretch::style::Dimension::Percent(0.3),
3143                height: stretch::style::Dimension::Percent(0.3),
3144                ..Default::default()
3145            }],
3146            ..Default::default()
3147        });
3148
3149        assert_eq!(layout.width, 200.0);
3150        assert_eq!(layout.height, 200.0);
3151        assert_eq!(layout.x, 0.0);
3152        assert_eq!(layout.y, 0.0);
3153
3154        assert_eq!(layout.children[0].width, 60.0);
3155        assert_eq!(layout.children[0].height, 60.0);
3156        assert_eq!(layout.children[0].x, 0.0);
3157        assert_eq!(layout.children[0].y, 0.0);
3158    }
3159
3160    #[test]
3161    fn margin_auto_mutiple_children_column() {
3162        let layout = stretch::compute(&stretch::style::Node {
3163            flex_direction: stretch::style::FlexDirection::Column,
3164            align_items: stretch::style::AlignItems::Center,
3165            width: stretch::style::Dimension::Points(200.0),
3166            height: stretch::style::Dimension::Points(200.0),
3167            children: vec![
3168                stretch::style::Node {
3169                    width: stretch::style::Dimension::Points(50.0),
3170                    height: stretch::style::Dimension::Points(50.0),
3171                    margin: stretch::style::Edges {
3172                        top: stretch::style::Dimension::Auto,
3173                        ..Default::default()
3174                    },
3175                    ..Default::default()
3176                },
3177                stretch::style::Node {
3178                    width: stretch::style::Dimension::Points(50.0),
3179                    height: stretch::style::Dimension::Points(50.0),
3180                    margin: stretch::style::Edges {
3181                        top: stretch::style::Dimension::Auto,
3182                        ..Default::default()
3183                    },
3184                    ..Default::default()
3185                },
3186                stretch::style::Node {
3187                    width: stretch::style::Dimension::Points(50.0),
3188                    height: stretch::style::Dimension::Points(50.0),
3189                    ..Default::default()
3190                },
3191            ],
3192            ..Default::default()
3193        });
3194
3195        assert_eq!(layout.width, 200.0);
3196        assert_eq!(layout.height, 200.0);
3197        assert_eq!(layout.x, 0.0);
3198        assert_eq!(layout.y, 0.0);
3199
3200        assert_eq!(layout.children[0].width, 50.0);
3201        assert_eq!(layout.children[0].height, 50.0);
3202        assert_eq!(layout.children[0].x, 75.0);
3203        assert_eq!(layout.children[0].y, 25.0);
3204
3205        assert_eq!(layout.children[1].width, 50.0);
3206        assert_eq!(layout.children[1].height, 50.0);
3207        assert_eq!(layout.children[1].x, 75.0);
3208        assert_eq!(layout.children[1].y, 100.0);
3209
3210        assert_eq!(layout.children[2].width, 50.0);
3211        assert_eq!(layout.children[2].height, 50.0);
3212        assert_eq!(layout.children[2].x, 75.0);
3213        assert_eq!(layout.children[2].y, 150.0);
3214    }
3215
3216    #[test]
3217    fn min_width_overrides_width_on_root() {
3218        let layout = stretch::compute(&stretch::style::Node {
3219            width: stretch::style::Dimension::Points(50.0),
3220            min_width: stretch::style::Dimension::Points(100.0),
3221            ..Default::default()
3222        });
3223
3224        assert_eq!(layout.width, 100.0);
3225        assert_eq!(layout.height, 0.0);
3226        assert_eq!(layout.x, 0.0);
3227        assert_eq!(layout.y, 0.0);
3228    }
3229
3230    #[test]
3231    fn flex_wrap_wrap_to_child_height() {
3232        let layout = stretch::compute(&stretch::style::Node {
3233            flex_direction: stretch::style::FlexDirection::Column,
3234            children: vec![
3235                stretch::style::Node {
3236                    align_items: stretch::style::AlignItems::FlexStart,
3237                    children: vec![stretch::style::Node {
3238                        flex_direction: stretch::style::FlexDirection::Column,
3239                        width: stretch::style::Dimension::Points(100.0),
3240                        children: vec![stretch::style::Node {
3241                            width: stretch::style::Dimension::Points(100.0),
3242                            height: stretch::style::Dimension::Points(100.0),
3243                            ..Default::default()
3244                        }],
3245                        ..Default::default()
3246                    }],
3247                    ..Default::default()
3248                },
3249                stretch::style::Node {
3250                    width: stretch::style::Dimension::Points(100.0),
3251                    height: stretch::style::Dimension::Points(100.0),
3252                    ..Default::default()
3253                },
3254            ],
3255            ..Default::default()
3256        });
3257
3258        assert_eq!(layout.width, 100.0);
3259        assert_eq!(layout.height, 200.0);
3260        assert_eq!(layout.x, 0.0);
3261        assert_eq!(layout.y, 0.0);
3262
3263        assert_eq!(layout.children[0].width, 100.0);
3264        assert_eq!(layout.children[0].height, 100.0);
3265        assert_eq!(layout.children[0].x, 0.0);
3266        assert_eq!(layout.children[0].y, 0.0);
3267
3268        assert_eq!(layout.children[0].children[0].width, 100.0);
3269        assert_eq!(layout.children[0].children[0].height, 100.0);
3270        assert_eq!(layout.children[0].children[0].x, 0.0);
3271        assert_eq!(layout.children[0].children[0].y, 0.0);
3272
3273        assert_eq!(layout.children[0].children[0].children[0].width, 100.0);
3274        assert_eq!(layout.children[0].children[0].children[0].height, 100.0);
3275        assert_eq!(layout.children[0].children[0].children[0].x, 0.0);
3276        assert_eq!(layout.children[0].children[0].children[0].y, 0.0);
3277
3278        assert_eq!(layout.children[1].width, 100.0);
3279        assert_eq!(layout.children[1].height, 100.0);
3280        assert_eq!(layout.children[1].x, 0.0);
3281        assert_eq!(layout.children[1].y, 100.0);
3282    }
3283
3284    #[test]
3285    fn wrap_nodes_with_content_sizing_margin_cross() {
3286        let layout = stretch::compute(&stretch::style::Node {
3287            flex_direction: stretch::style::FlexDirection::Column,
3288            width: stretch::style::Dimension::Points(500.0),
3289            height: stretch::style::Dimension::Points(500.0),
3290            children: vec![stretch::style::Node {
3291                width: stretch::style::Dimension::Points(70.0),
3292                children: vec![
3293                    stretch::style::Node {
3294                        flex_direction: stretch::style::FlexDirection::Column,
3295                        children: vec![stretch::style::Node {
3296                            width: stretch::style::Dimension::Points(40.0),
3297                            height: stretch::style::Dimension::Points(40.0),
3298                            ..Default::default()
3299                        }],
3300                        ..Default::default()
3301                    },
3302                    stretch::style::Node {
3303                        flex_direction: stretch::style::FlexDirection::Column,
3304                        margin: stretch::style::Edges {
3305                            top: stretch::style::Dimension::Points(10.0),
3306                            ..Default::default()
3307                        },
3308                        children: vec![stretch::style::Node {
3309                            width: stretch::style::Dimension::Points(40.0),
3310                            height: stretch::style::Dimension::Points(40.0),
3311                            ..Default::default()
3312                        }],
3313                        ..Default::default()
3314                    },
3315                ],
3316                ..Default::default()
3317            }],
3318            ..Default::default()
3319        });
3320
3321        assert_eq!(layout.width, 500.0);
3322        assert_eq!(layout.height, 500.0);
3323        assert_eq!(layout.x, 0.0);
3324        assert_eq!(layout.y, 0.0);
3325
3326        assert_eq!(layout.children[0].width, 70.0);
3327        assert_eq!(layout.children[0].height, 90.0);
3328        assert_eq!(layout.children[0].x, 0.0);
3329        assert_eq!(layout.children[0].y, 0.0);
3330
3331        assert_eq!(layout.children[0].children[0].width, 40.0);
3332        assert_eq!(layout.children[0].children[0].height, 40.0);
3333        assert_eq!(layout.children[0].children[0].x, 0.0);
3334        assert_eq!(layout.children[0].children[0].y, 0.0);
3335
3336        assert_eq!(layout.children[0].children[0].children[0].width, 40.0);
3337        assert_eq!(layout.children[0].children[0].children[0].height, 40.0);
3338        assert_eq!(layout.children[0].children[0].children[0].x, 0.0);
3339        assert_eq!(layout.children[0].children[0].children[0].y, 0.0);
3340
3341        assert_eq!(layout.children[0].children[1].width, 40.0);
3342        assert_eq!(layout.children[0].children[1].height, 40.0);
3343        assert_eq!(layout.children[0].children[1].x, 0.0);
3344        assert_eq!(layout.children[0].children[1].y, 50.0);
3345
3346        assert_eq!(layout.children[0].children[1].children[0].width, 40.0);
3347        assert_eq!(layout.children[0].children[1].children[0].height, 40.0);
3348        assert_eq!(layout.children[0].children[1].children[0].x, 0.0);
3349        assert_eq!(layout.children[0].children[1].children[0].y, 0.0);
3350    }
3351
3352    #[test]
3353    fn align_baseline() {
3354        let layout = stretch::compute(&stretch::style::Node {
3355            align_items: stretch::style::AlignItems::Baseline,
3356            width: stretch::style::Dimension::Points(100.0),
3357            height: stretch::style::Dimension::Points(100.0),
3358            children: vec![
3359                stretch::style::Node {
3360                    width: stretch::style::Dimension::Points(50.0),
3361                    height: stretch::style::Dimension::Points(50.0),
3362                    ..Default::default()
3363                },
3364                stretch::style::Node {
3365                    width: stretch::style::Dimension::Points(50.0),
3366                    height: stretch::style::Dimension::Points(20.0),
3367                    ..Default::default()
3368                },
3369            ],
3370            ..Default::default()
3371        });
3372
3373        assert_eq!(layout.width, 100.0);
3374        assert_eq!(layout.height, 100.0);
3375        assert_eq!(layout.x, 0.0);
3376        assert_eq!(layout.y, 0.0);
3377
3378        assert_eq!(layout.children[0].width, 50.0);
3379        assert_eq!(layout.children[0].height, 50.0);
3380        assert_eq!(layout.children[0].x, 0.0);
3381        assert_eq!(layout.children[0].y, 0.0);
3382
3383        assert_eq!(layout.children[1].width, 50.0);
3384        assert_eq!(layout.children[1].height, 20.0);
3385        assert_eq!(layout.children[1].x, 50.0);
3386        assert_eq!(layout.children[1].y, 30.0);
3387    }
3388
3389    #[test]
3390    fn margin_with_sibling_row() {
3391        let layout = stretch::compute(&stretch::style::Node {
3392            width: stretch::style::Dimension::Points(100.0),
3393            height: stretch::style::Dimension::Points(100.0),
3394            children: vec![
3395                stretch::style::Node {
3396                    flex_grow: 1.0,
3397                    margin: stretch::style::Edges {
3398                        end: stretch::style::Dimension::Points(10.0),
3399                        ..Default::default()
3400                    },
3401                    ..Default::default()
3402                },
3403                stretch::style::Node {
3404                    flex_grow: 1.0,
3405                    ..Default::default()
3406                },
3407            ],
3408            ..Default::default()
3409        });
3410
3411        assert_eq!(layout.width, 100.0);
3412        assert_eq!(layout.height, 100.0);
3413        assert_eq!(layout.x, 0.0);
3414        assert_eq!(layout.y, 0.0);
3415
3416        assert_eq!(layout.children[0].width, 45.0);
3417        assert_eq!(layout.children[0].height, 100.0);
3418        assert_eq!(layout.children[0].x, 0.0);
3419        assert_eq!(layout.children[0].y, 0.0);
3420
3421        assert_eq!(layout.children[1].width, 45.0);
3422        assert_eq!(layout.children[1].height, 100.0);
3423        assert_eq!(layout.children[1].x, 55.0);
3424        assert_eq!(layout.children[1].y, 0.0);
3425    }
3426
3427    #[test]
3428    fn wrap_reverse_row_align_content_space_around() {
3429        let layout = stretch::compute(&stretch::style::Node {
3430            align_content: stretch::style::AlignContent::SpaceAround,
3431            width: stretch::style::Dimension::Points(100.0),
3432            children: vec![
3433                stretch::style::Node {
3434                    width: stretch::style::Dimension::Points(30.0),
3435                    height: stretch::style::Dimension::Points(10.0),
3436                    ..Default::default()
3437                },
3438                stretch::style::Node {
3439                    width: stretch::style::Dimension::Points(30.0),
3440                    height: stretch::style::Dimension::Points(20.0),
3441                    ..Default::default()
3442                },
3443                stretch::style::Node {
3444                    width: stretch::style::Dimension::Points(30.0),
3445                    height: stretch::style::Dimension::Points(30.0),
3446                    ..Default::default()
3447                },
3448                stretch::style::Node {
3449                    width: stretch::style::Dimension::Points(30.0),
3450                    height: stretch::style::Dimension::Points(40.0),
3451                    ..Default::default()
3452                },
3453                stretch::style::Node {
3454                    width: stretch::style::Dimension::Points(30.0),
3455                    height: stretch::style::Dimension::Points(50.0),
3456                    ..Default::default()
3457                },
3458            ],
3459            ..Default::default()
3460        });
3461
3462        assert_eq!(layout.width, 100.0);
3463        assert_eq!(layout.height, 80.0);
3464        assert_eq!(layout.x, 0.0);
3465        assert_eq!(layout.y, 0.0);
3466
3467        assert_eq!(layout.children[0].width, 30.0);
3468        assert_eq!(layout.children[0].height, 10.0);
3469        assert_eq!(layout.children[0].x, 0.0);
3470        assert_eq!(layout.children[0].y, 70.0);
3471
3472        assert_eq!(layout.children[1].width, 30.0);
3473        assert_eq!(layout.children[1].height, 20.0);
3474        assert_eq!(layout.children[1].x, 30.0);
3475        assert_eq!(layout.children[1].y, 60.0);
3476
3477        assert_eq!(layout.children[2].width, 30.0);
3478        assert_eq!(layout.children[2].height, 30.0);
3479        assert_eq!(layout.children[2].x, 60.0);
3480        assert_eq!(layout.children[2].y, 50.0);
3481
3482        assert_eq!(layout.children[3].width, 30.0);
3483        assert_eq!(layout.children[3].height, 40.0);
3484        assert_eq!(layout.children[3].x, 0.0);
3485        assert_eq!(layout.children[3].y, 10.0);
3486
3487        assert_eq!(layout.children[4].width, 30.0);
3488        assert_eq!(layout.children[4].height, 50.0);
3489        assert_eq!(layout.children[4].x, 30.0);
3490        assert_eq!(layout.children[4].y, 0.0);
3491    }
3492
3493    #[test]
3494    fn align_items_center_with_child_margin() {
3495        let layout = stretch::compute(&stretch::style::Node {
3496            align_items: stretch::style::AlignItems::Center,
3497            width: stretch::style::Dimension::Points(100.0),
3498            height: stretch::style::Dimension::Points(100.0),
3499            children: vec![stretch::style::Node {
3500                width: stretch::style::Dimension::Points(10.0),
3501                height: stretch::style::Dimension::Points(10.0),
3502                margin: stretch::style::Edges {
3503                    top: stretch::style::Dimension::Points(10.0),
3504                    ..Default::default()
3505                },
3506                ..Default::default()
3507            }],
3508            ..Default::default()
3509        });
3510
3511        assert_eq!(layout.width, 100.0);
3512        assert_eq!(layout.height, 100.0);
3513        assert_eq!(layout.x, 0.0);
3514        assert_eq!(layout.y, 0.0);
3515
3516        assert_eq!(layout.children[0].width, 10.0);
3517        assert_eq!(layout.children[0].height, 10.0);
3518        assert_eq!(layout.children[0].x, 0.0);
3519        assert_eq!(layout.children[0].y, 50.0);
3520    }
3521
3522    #[test]
3523    fn flex_direction_column_reverse() {
3524        let layout = stretch::compute(&stretch::style::Node {
3525            flex_direction: stretch::style::FlexDirection::ColumnReverse,
3526            width: stretch::style::Dimension::Points(100.0),
3527            height: stretch::style::Dimension::Points(100.0),
3528            children: vec![
3529                stretch::style::Node {
3530                    height: stretch::style::Dimension::Points(10.0),
3531                    ..Default::default()
3532                },
3533                stretch::style::Node {
3534                    height: stretch::style::Dimension::Points(10.0),
3535                    ..Default::default()
3536                },
3537                stretch::style::Node {
3538                    height: stretch::style::Dimension::Points(10.0),
3539                    ..Default::default()
3540                },
3541            ],
3542            ..Default::default()
3543        });
3544
3545        assert_eq!(layout.width, 100.0);
3546        assert_eq!(layout.height, 100.0);
3547        assert_eq!(layout.x, 0.0);
3548        assert_eq!(layout.y, 0.0);
3549
3550        assert_eq!(layout.children[0].width, 100.0);
3551        assert_eq!(layout.children[0].height, 10.0);
3552        assert_eq!(layout.children[0].x, 0.0);
3553        assert_eq!(layout.children[0].y, 90.0);
3554
3555        assert_eq!(layout.children[1].width, 100.0);
3556        assert_eq!(layout.children[1].height, 10.0);
3557        assert_eq!(layout.children[1].x, 0.0);
3558        assert_eq!(layout.children[1].y, 80.0);
3559
3560        assert_eq!(layout.children[2].width, 100.0);
3561        assert_eq!(layout.children[2].height, 10.0);
3562        assert_eq!(layout.children[2].x, 0.0);
3563        assert_eq!(layout.children[2].y, 70.0);
3564    }
3565
3566    #[test]
3567    fn flex_direction_column() {
3568        let layout = stretch::compute(&stretch::style::Node {
3569            flex_direction: stretch::style::FlexDirection::Column,
3570            width: stretch::style::Dimension::Points(100.0),
3571            height: stretch::style::Dimension::Points(100.0),
3572            children: vec![
3573                stretch::style::Node {
3574                    height: stretch::style::Dimension::Points(10.0),
3575                    ..Default::default()
3576                },
3577                stretch::style::Node {
3578                    height: stretch::style::Dimension::Points(10.0),
3579                    ..Default::default()
3580                },
3581                stretch::style::Node {
3582                    height: stretch::style::Dimension::Points(10.0),
3583                    ..Default::default()
3584                },
3585            ],
3586            ..Default::default()
3587        });
3588
3589        assert_eq!(layout.width, 100.0);
3590        assert_eq!(layout.height, 100.0);
3591        assert_eq!(layout.x, 0.0);
3592        assert_eq!(layout.y, 0.0);
3593
3594        assert_eq!(layout.children[0].width, 100.0);
3595        assert_eq!(layout.children[0].height, 10.0);
3596        assert_eq!(layout.children[0].x, 0.0);
3597        assert_eq!(layout.children[0].y, 0.0);
3598
3599        assert_eq!(layout.children[1].width, 100.0);
3600        assert_eq!(layout.children[1].height, 10.0);
3601        assert_eq!(layout.children[1].x, 0.0);
3602        assert_eq!(layout.children[1].y, 10.0);
3603
3604        assert_eq!(layout.children[2].width, 100.0);
3605        assert_eq!(layout.children[2].height, 10.0);
3606        assert_eq!(layout.children[2].x, 0.0);
3607        assert_eq!(layout.children[2].y, 20.0);
3608    }
3609
3610    #[test]
3611    fn align_items_center_child_without_margin_bigger_than_parent() {
3612        let layout = stretch::compute(&stretch::style::Node {
3613            align_items: stretch::style::AlignItems::Center,
3614            justify_content: stretch::style::JustifyContent::Center,
3615            width: stretch::style::Dimension::Points(52.0),
3616            height: stretch::style::Dimension::Points(52.0),
3617            children: vec![stretch::style::Node {
3618                align_items: stretch::style::AlignItems::Center,
3619                children: vec![stretch::style::Node {
3620                    width: stretch::style::Dimension::Points(72.0),
3621                    height: stretch::style::Dimension::Points(72.0),
3622                    ..Default::default()
3623                }],
3624                ..Default::default()
3625            }],
3626            ..Default::default()
3627        });
3628
3629        assert_eq!(layout.width, 52.0);
3630        assert_eq!(layout.height, 52.0);
3631        assert_eq!(layout.x, 0.0);
3632        assert_eq!(layout.y, 0.0);
3633
3634        assert_eq!(layout.children[0].width, 72.0);
3635        assert_eq!(layout.children[0].height, 72.0);
3636        assert_eq!(layout.children[0].x, -10.0);
3637        assert_eq!(layout.children[0].y, -10.0);
3638
3639        assert_eq!(layout.children[0].children[0].width, 72.0);
3640        assert_eq!(layout.children[0].children[0].height, 72.0);
3641        assert_eq!(layout.children[0].children[0].x, 0.0);
3642        assert_eq!(layout.children[0].children[0].y, 0.0);
3643    }
3644
3645    #[test]
3646    fn align_self_flex_end_override_flex_start() {
3647        let layout = stretch::compute(&stretch::style::Node {
3648            align_items: stretch::style::AlignItems::FlexStart,
3649            width: stretch::style::Dimension::Points(100.0),
3650            height: stretch::style::Dimension::Points(100.0),
3651            children: vec![stretch::style::Node {
3652                align_self: stretch::style::AlignSelf::FlexEnd,
3653                width: stretch::style::Dimension::Points(10.0),
3654                height: stretch::style::Dimension::Points(10.0),
3655                ..Default::default()
3656            }],
3657            ..Default::default()
3658        });
3659
3660        assert_eq!(layout.width, 100.0);
3661        assert_eq!(layout.height, 100.0);
3662        assert_eq!(layout.x, 0.0);
3663        assert_eq!(layout.y, 0.0);
3664
3665        assert_eq!(layout.children[0].width, 10.0);
3666        assert_eq!(layout.children[0].height, 10.0);
3667        assert_eq!(layout.children[0].x, 0.0);
3668        assert_eq!(layout.children[0].y, 90.0);
3669    }
3670
3671    #[test]
3672    fn rounding_total_fractial() {
3673        let layout = stretch::compute(&stretch::style::Node {
3674            flex_direction: stretch::style::FlexDirection::Column,
3675            width: stretch::style::Dimension::Points(87.4),
3676            height: stretch::style::Dimension::Points(113.4),
3677            children: vec![
3678                stretch::style::Node {
3679                    flex_grow: 0.7,
3680                    flex_basis: stretch::style::Dimension::Points(50.3),
3681                    height: stretch::style::Dimension::Points(20.3),
3682                    ..Default::default()
3683                },
3684                stretch::style::Node {
3685                    flex_grow: 1.6,
3686                    height: stretch::style::Dimension::Points(10.0),
3687                    ..Default::default()
3688                },
3689                stretch::style::Node {
3690                    flex_grow: 1.1,
3691                    height: stretch::style::Dimension::Points(10.7),
3692                    ..Default::default()
3693                },
3694            ],
3695            ..Default::default()
3696        });
3697
3698        assert_eq!(layout.width, 87.0);
3699        assert_eq!(layout.height, 113.0);
3700        assert_eq!(layout.x, 0.0);
3701        assert_eq!(layout.y, 0.0);
3702
3703        assert_eq!(layout.children[0].width, 87.0);
3704        assert_eq!(layout.children[0].height, 59.0);
3705        assert_eq!(layout.children[0].x, 0.0);
3706        assert_eq!(layout.children[0].y, 0.0);
3707
3708        assert_eq!(layout.children[1].width, 87.0);
3709        assert_eq!(layout.children[1].height, 30.0);
3710        assert_eq!(layout.children[1].x, 0.0);
3711        assert_eq!(layout.children[1].y, 59.0);
3712
3713        assert_eq!(layout.children[2].width, 87.0);
3714        assert_eq!(layout.children[2].height, 24.0);
3715        assert_eq!(layout.children[2].x, 0.0);
3716        assert_eq!(layout.children[2].y, 89.0);
3717    }
3718
3719    #[test]
3720    fn align_baseline_child_multiline() {
3721        let layout = stretch::compute(&stretch::style::Node {
3722            align_items: stretch::style::AlignItems::Baseline,
3723            width: stretch::style::Dimension::Points(100.0),
3724            children: vec![
3725                stretch::style::Node {
3726                    width: stretch::style::Dimension::Points(50.0),
3727                    height: stretch::style::Dimension::Points(60.0),
3728                    ..Default::default()
3729                },
3730                stretch::style::Node {
3731                    width: stretch::style::Dimension::Points(50.0),
3732                    children: vec![
3733                        stretch::style::Node {
3734                            width: stretch::style::Dimension::Points(25.0),
3735                            height: stretch::style::Dimension::Points(20.0),
3736                            ..Default::default()
3737                        },
3738                        stretch::style::Node {
3739                            width: stretch::style::Dimension::Points(25.0),
3740                            height: stretch::style::Dimension::Points(10.0),
3741                            ..Default::default()
3742                        },
3743                        stretch::style::Node {
3744                            width: stretch::style::Dimension::Points(25.0),
3745                            height: stretch::style::Dimension::Points(20.0),
3746                            ..Default::default()
3747                        },
3748                        stretch::style::Node {
3749                            width: stretch::style::Dimension::Points(25.0),
3750                            height: stretch::style::Dimension::Points(10.0),
3751                            ..Default::default()
3752                        },
3753                    ],
3754                    ..Default::default()
3755                },
3756            ],
3757            ..Default::default()
3758        });
3759
3760        assert_eq!(layout.width, 100.0);
3761        assert_eq!(layout.height, 80.0);
3762        assert_eq!(layout.x, 0.0);
3763        assert_eq!(layout.y, 0.0);
3764
3765        assert_eq!(layout.children[0].width, 50.0);
3766        assert_eq!(layout.children[0].height, 60.0);
3767        assert_eq!(layout.children[0].x, 0.0);
3768        assert_eq!(layout.children[0].y, 0.0);
3769
3770        assert_eq!(layout.children[1].width, 50.0);
3771        assert_eq!(layout.children[1].height, 40.0);
3772        assert_eq!(layout.children[1].x, 50.0);
3773        assert_eq!(layout.children[1].y, 40.0);
3774
3775        assert_eq!(layout.children[1].children[0].width, 25.0);
3776        assert_eq!(layout.children[1].children[0].height, 20.0);
3777        assert_eq!(layout.children[1].children[0].x, 0.0);
3778        assert_eq!(layout.children[1].children[0].y, 0.0);
3779
3780        assert_eq!(layout.children[1].children[1].width, 25.0);
3781        assert_eq!(layout.children[1].children[1].height, 10.0);
3782        assert_eq!(layout.children[1].children[1].x, 25.0);
3783        assert_eq!(layout.children[1].children[1].y, 0.0);
3784
3785        assert_eq!(layout.children[1].children[2].width, 25.0);
3786        assert_eq!(layout.children[1].children[2].height, 20.0);
3787        assert_eq!(layout.children[1].children[2].x, 0.0);
3788        assert_eq!(layout.children[1].children[2].y, 20.0);
3789
3790        assert_eq!(layout.children[1].children[3].width, 25.0);
3791        assert_eq!(layout.children[1].children[3].height, 10.0);
3792        assert_eq!(layout.children[1].children[3].x, 25.0);
3793        assert_eq!(layout.children[1].children[3].y, 20.0);
3794    }
3795
3796    #[test]
3797    fn absolute_layout_align_items_center_on_child_only() {
3798        let layout = stretch::compute(&stretch::style::Node {
3799            width: stretch::style::Dimension::Points(110.0),
3800            height: stretch::style::Dimension::Points(100.0),
3801            children: vec![stretch::style::Node {
3802                position: stretch::style::Position::Absolute,
3803                align_self: stretch::style::AlignSelf::Center,
3804                width: stretch::style::Dimension::Points(60.0),
3805                height: stretch::style::Dimension::Points(40.0),
3806                ..Default::default()
3807            }],
3808            ..Default::default()
3809        });
3810
3811        assert_eq!(layout.width, 110.0);
3812        assert_eq!(layout.height, 100.0);
3813        assert_eq!(layout.x, 0.0);
3814        assert_eq!(layout.y, 0.0);
3815
3816        assert_eq!(layout.children[0].width, 60.0);
3817        assert_eq!(layout.children[0].height, 40.0);
3818        assert_eq!(layout.children[0].x, 0.0);
3819        assert_eq!(layout.children[0].y, 30.0);
3820    }
3821
3822    #[test]
3823    fn wrap_reverse_row_single_line_different_size() {
3824        let layout = stretch::compute(&stretch::style::Node {
3825            align_content: stretch::style::AlignContent::FlexStart,
3826            width: stretch::style::Dimension::Points(300.0),
3827            children: vec![
3828                stretch::style::Node {
3829                    width: stretch::style::Dimension::Points(30.0),
3830                    height: stretch::style::Dimension::Points(10.0),
3831                    ..Default::default()
3832                },
3833                stretch::style::Node {
3834                    width: stretch::style::Dimension::Points(30.0),
3835                    height: stretch::style::Dimension::Points(20.0),
3836                    ..Default::default()
3837                },
3838                stretch::style::Node {
3839                    width: stretch::style::Dimension::Points(30.0),
3840                    height: stretch::style::Dimension::Points(30.0),
3841                    ..Default::default()
3842                },
3843                stretch::style::Node {
3844                    width: stretch::style::Dimension::Points(30.0),
3845                    height: stretch::style::Dimension::Points(40.0),
3846                    ..Default::default()
3847                },
3848                stretch::style::Node {
3849                    width: stretch::style::Dimension::Points(30.0),
3850                    height: stretch::style::Dimension::Points(50.0),
3851                    ..Default::default()
3852                },
3853            ],
3854            ..Default::default()
3855        });
3856
3857        assert_eq!(layout.width, 300.0);
3858        assert_eq!(layout.height, 50.0);
3859        assert_eq!(layout.x, 0.0);
3860        assert_eq!(layout.y, 0.0);
3861
3862        assert_eq!(layout.children[0].width, 30.0);
3863        assert_eq!(layout.children[0].height, 10.0);
3864        assert_eq!(layout.children[0].x, 0.0);
3865        assert_eq!(layout.children[0].y, 40.0);
3866
3867        assert_eq!(layout.children[1].width, 30.0);
3868        assert_eq!(layout.children[1].height, 20.0);
3869        assert_eq!(layout.children[1].x, 30.0);
3870        assert_eq!(layout.children[1].y, 30.0);
3871
3872        assert_eq!(layout.children[2].width, 30.0);
3873        assert_eq!(layout.children[2].height, 30.0);
3874        assert_eq!(layout.children[2].x, 60.0);
3875        assert_eq!(layout.children[2].y, 20.0);
3876
3877        assert_eq!(layout.children[3].width, 30.0);
3878        assert_eq!(layout.children[3].height, 40.0);
3879        assert_eq!(layout.children[3].x, 90.0);
3880        assert_eq!(layout.children[3].y, 10.0);
3881
3882        assert_eq!(layout.children[4].width, 30.0);
3883        assert_eq!(layout.children[4].height, 50.0);
3884        assert_eq!(layout.children[4].x, 120.0);
3885        assert_eq!(layout.children[4].y, 0.0);
3886    }
3887
3888    #[test]
3889    fn rounding_fractial_input_4() {
3890        let layout = stretch::compute(&stretch::style::Node {
3891            flex_direction: stretch::style::FlexDirection::Column,
3892            width: stretch::style::Dimension::Points(100.0),
3893            height: stretch::style::Dimension::Points(113.4),
3894            children: vec![
3895                stretch::style::Node {
3896                    flex_grow: 1.0,
3897                    flex_basis: stretch::style::Dimension::Points(50.0),
3898                    height: stretch::style::Dimension::Points(20.0),
3899                    ..Default::default()
3900                },
3901                stretch::style::Node {
3902                    flex_grow: 1.0,
3903                    height: stretch::style::Dimension::Points(10.0),
3904                    ..Default::default()
3905                },
3906                stretch::style::Node {
3907                    flex_grow: 1.0,
3908                    height: stretch::style::Dimension::Points(10.0),
3909                    ..Default::default()
3910                },
3911            ],
3912            ..Default::default()
3913        });
3914
3915        assert_eq!(layout.width, 100.0);
3916        assert_eq!(layout.height, 113.0);
3917        assert_eq!(layout.x, 0.0);
3918        assert_eq!(layout.y, 0.0);
3919
3920        assert_eq!(layout.children[0].width, 100.0);
3921        assert_eq!(layout.children[0].height, 64.0);
3922        assert_eq!(layout.children[0].x, 0.0);
3923        assert_eq!(layout.children[0].y, 0.0);
3924
3925        assert_eq!(layout.children[1].width, 100.0);
3926        assert_eq!(layout.children[1].height, 25.0);
3927        assert_eq!(layout.children[1].x, 0.0);
3928        assert_eq!(layout.children[1].y, 64.0);
3929
3930        assert_eq!(layout.children[2].width, 100.0);
3931        assert_eq!(layout.children[2].height, 24.0);
3932        assert_eq!(layout.children[2].x, 0.0);
3933        assert_eq!(layout.children[2].y, 89.0);
3934    }
3935
3936    #[test]
3937    fn padding_flex_child() {
3938        let layout = stretch::compute(&stretch::style::Node {
3939            width: stretch::style::Dimension::Points(100.0),
3940            height: stretch::style::Dimension::Points(100.0),
3941            padding: stretch::style::Edges {
3942                start: stretch::style::Dimension::Points(10.0),
3943                end: stretch::style::Dimension::Points(10.0),
3944                top: stretch::style::Dimension::Points(10.0),
3945                bottom: stretch::style::Dimension::Points(10.0),
3946                ..Default::default()
3947            },
3948            children: vec![stretch::style::Node {
3949                flex_grow: 1.0,
3950                width: stretch::style::Dimension::Points(10.0),
3951                ..Default::default()
3952            }],
3953            ..Default::default()
3954        });
3955
3956        assert_eq!(layout.width, 100.0);
3957        assert_eq!(layout.height, 100.0);
3958        assert_eq!(layout.x, 0.0);
3959        assert_eq!(layout.y, 0.0);
3960
3961        assert_eq!(layout.children[0].width, 80.0);
3962        assert_eq!(layout.children[0].height, 80.0);
3963        assert_eq!(layout.children[0].x, 10.0);
3964        assert_eq!(layout.children[0].y, 10.0);
3965    }
3966
3967    #[test]
3968    fn flex_direction_row_reverse() {
3969        let layout = stretch::compute(&stretch::style::Node {
3970            flex_direction: stretch::style::FlexDirection::RowReverse,
3971            width: stretch::style::Dimension::Points(100.0),
3972            height: stretch::style::Dimension::Points(100.0),
3973            children: vec![
3974                stretch::style::Node {
3975                    width: stretch::style::Dimension::Points(10.0),
3976                    ..Default::default()
3977                },
3978                stretch::style::Node {
3979                    width: stretch::style::Dimension::Points(10.0),
3980                    ..Default::default()
3981                },
3982                stretch::style::Node {
3983                    width: stretch::style::Dimension::Points(10.0),
3984                    ..Default::default()
3985                },
3986            ],
3987            ..Default::default()
3988        });
3989
3990        assert_eq!(layout.width, 100.0);
3991        assert_eq!(layout.height, 100.0);
3992        assert_eq!(layout.x, 0.0);
3993        assert_eq!(layout.y, 0.0);
3994
3995        assert_eq!(layout.children[0].width, 10.0);
3996        assert_eq!(layout.children[0].height, 100.0);
3997        assert_eq!(layout.children[0].x, 90.0);
3998        assert_eq!(layout.children[0].y, 0.0);
3999
4000        assert_eq!(layout.children[1].width, 10.0);
4001        assert_eq!(layout.children[1].height, 100.0);
4002        assert_eq!(layout.children[1].x, 80.0);
4003        assert_eq!(layout.children[1].y, 0.0);
4004
4005        assert_eq!(layout.children[2].width, 10.0);
4006        assert_eq!(layout.children[2].height, 100.0);
4007        assert_eq!(layout.children[2].x, 70.0);
4008        assert_eq!(layout.children[2].y, 0.0);
4009    }
4010
4011    #[test]
4012    fn wrap_reverse_row_align_content_stretch() {
4013        let layout = stretch::compute(&stretch::style::Node {
4014            width: stretch::style::Dimension::Points(100.0),
4015            children: vec![
4016                stretch::style::Node {
4017                    width: stretch::style::Dimension::Points(30.0),
4018                    height: stretch::style::Dimension::Points(10.0),
4019                    ..Default::default()
4020                },
4021                stretch::style::Node {
4022                    width: stretch::style::Dimension::Points(30.0),
4023                    height: stretch::style::Dimension::Points(20.0),
4024                    ..Default::default()
4025                },
4026                stretch::style::Node {
4027                    width: stretch::style::Dimension::Points(30.0),
4028                    height: stretch::style::Dimension::Points(30.0),
4029                    ..Default::default()
4030                },
4031                stretch::style::Node {
4032                    width: stretch::style::Dimension::Points(30.0),
4033                    height: stretch::style::Dimension::Points(40.0),
4034                    ..Default::default()
4035                },
4036                stretch::style::Node {
4037                    width: stretch::style::Dimension::Points(30.0),
4038                    height: stretch::style::Dimension::Points(50.0),
4039                    ..Default::default()
4040                },
4041            ],
4042            ..Default::default()
4043        });
4044
4045        assert_eq!(layout.width, 100.0);
4046        assert_eq!(layout.height, 80.0);
4047        assert_eq!(layout.x, 0.0);
4048        assert_eq!(layout.y, 0.0);
4049
4050        assert_eq!(layout.children[0].width, 30.0);
4051        assert_eq!(layout.children[0].height, 10.0);
4052        assert_eq!(layout.children[0].x, 0.0);
4053        assert_eq!(layout.children[0].y, 70.0);
4054
4055        assert_eq!(layout.children[1].width, 30.0);
4056        assert_eq!(layout.children[1].height, 20.0);
4057        assert_eq!(layout.children[1].x, 30.0);
4058        assert_eq!(layout.children[1].y, 60.0);
4059
4060        assert_eq!(layout.children[2].width, 30.0);
4061        assert_eq!(layout.children[2].height, 30.0);
4062        assert_eq!(layout.children[2].x, 60.0);
4063        assert_eq!(layout.children[2].y, 50.0);
4064
4065        assert_eq!(layout.children[3].width, 30.0);
4066        assert_eq!(layout.children[3].height, 40.0);
4067        assert_eq!(layout.children[3].x, 0.0);
4068        assert_eq!(layout.children[3].y, 10.0);
4069
4070        assert_eq!(layout.children[4].width, 30.0);
4071        assert_eq!(layout.children[4].height, 50.0);
4072        assert_eq!(layout.children[4].x, 30.0);
4073        assert_eq!(layout.children[4].y, 0.0);
4074    }
4075
4076    #[test]
4077    fn margin_auto_top() {
4078        let layout = stretch::compute(&stretch::style::Node {
4079            align_items: stretch::style::AlignItems::Center,
4080            width: stretch::style::Dimension::Points(200.0),
4081            height: stretch::style::Dimension::Points(200.0),
4082            children: vec![
4083                stretch::style::Node {
4084                    width: stretch::style::Dimension::Points(50.0),
4085                    height: stretch::style::Dimension::Points(50.0),
4086                    margin: stretch::style::Edges {
4087                        top: stretch::style::Dimension::Auto,
4088                        ..Default::default()
4089                    },
4090                    ..Default::default()
4091                },
4092                stretch::style::Node {
4093                    width: stretch::style::Dimension::Points(50.0),
4094                    height: stretch::style::Dimension::Points(50.0),
4095                    ..Default::default()
4096                },
4097            ],
4098            ..Default::default()
4099        });
4100
4101        assert_eq!(layout.width, 200.0);
4102        assert_eq!(layout.height, 200.0);
4103        assert_eq!(layout.x, 0.0);
4104        assert_eq!(layout.y, 0.0);
4105
4106        assert_eq!(layout.children[0].width, 50.0);
4107        assert_eq!(layout.children[0].height, 50.0);
4108        assert_eq!(layout.children[0].x, 0.0);
4109        assert_eq!(layout.children[0].y, 150.0);
4110
4111        assert_eq!(layout.children[1].width, 50.0);
4112        assert_eq!(layout.children[1].height, 50.0);
4113        assert_eq!(layout.children[1].x, 50.0);
4114        assert_eq!(layout.children[1].y, 75.0);
4115    }
4116
4117    #[test]
4118    fn flex_grow_within_constrained_max_row() {
4119        let layout = stretch::compute(&stretch::style::Node {
4120            flex_direction: stretch::style::FlexDirection::Column,
4121            width: stretch::style::Dimension::Points(200.0),
4122            children: vec![stretch::style::Node {
4123                max_width: stretch::style::Dimension::Points(100.0),
4124                height: stretch::style::Dimension::Points(100.0),
4125                children: vec![
4126                    stretch::style::Node {
4127                        flex_shrink: 1.0,
4128                        flex_basis: stretch::style::Dimension::Points(100.0),
4129                        ..Default::default()
4130                    },
4131                    stretch::style::Node {
4132                        width: stretch::style::Dimension::Points(50.0),
4133                        ..Default::default()
4134                    },
4135                ],
4136                ..Default::default()
4137            }],
4138            ..Default::default()
4139        });
4140
4141        assert_eq!(layout.width, 200.0);
4142        assert_eq!(layout.height, 100.0);
4143        assert_eq!(layout.x, 0.0);
4144        assert_eq!(layout.y, 0.0);
4145
4146        assert_eq!(layout.children[0].width, 100.0);
4147        assert_eq!(layout.children[0].height, 100.0);
4148        assert_eq!(layout.children[0].x, 0.0);
4149        assert_eq!(layout.children[0].y, 0.0);
4150
4151        assert_eq!(layout.children[0].children[0].width, 67.0);
4152        assert_eq!(layout.children[0].children[0].height, 100.0);
4153        assert_eq!(layout.children[0].children[0].x, 0.0);
4154        assert_eq!(layout.children[0].children[0].y, 0.0);
4155
4156        assert_eq!(layout.children[0].children[1].width, 33.0);
4157        assert_eq!(layout.children[0].children[1].height, 100.0);
4158        assert_eq!(layout.children[0].children[1].x, 67.0);
4159        assert_eq!(layout.children[0].children[1].y, 0.0);
4160    }
4161
4162    #[test]
4163    fn absolute_layout_align_items_and_justify_content_center() {
4164        let layout = stretch::compute(&stretch::style::Node {
4165            align_items: stretch::style::AlignItems::Center,
4166            justify_content: stretch::style::JustifyContent::Center,
4167            width: stretch::style::Dimension::Points(110.0),
4168            height: stretch::style::Dimension::Points(100.0),
4169            children: vec![stretch::style::Node {
4170                position: stretch::style::Position::Absolute,
4171                width: stretch::style::Dimension::Points(60.0),
4172                height: stretch::style::Dimension::Points(40.0),
4173                ..Default::default()
4174            }],
4175            ..Default::default()
4176        });
4177
4178        assert_eq!(layout.width, 110.0);
4179        assert_eq!(layout.height, 100.0);
4180        assert_eq!(layout.x, 0.0);
4181        assert_eq!(layout.y, 0.0);
4182
4183        assert_eq!(layout.children[0].width, 60.0);
4184        assert_eq!(layout.children[0].height, 40.0);
4185        assert_eq!(layout.children[0].x, 25.0);
4186        assert_eq!(layout.children[0].y, 30.0);
4187    }
4188
4189    #[test]
4190    fn align_self_flex_end() {
4191        let layout = stretch::compute(&stretch::style::Node {
4192            width: stretch::style::Dimension::Points(100.0),
4193            height: stretch::style::Dimension::Points(100.0),
4194            children: vec![stretch::style::Node {
4195                align_self: stretch::style::AlignSelf::FlexEnd,
4196                width: stretch::style::Dimension::Points(10.0),
4197                height: stretch::style::Dimension::Points(10.0),
4198                ..Default::default()
4199            }],
4200            ..Default::default()
4201        });
4202
4203        assert_eq!(layout.width, 100.0);
4204        assert_eq!(layout.height, 100.0);
4205        assert_eq!(layout.x, 0.0);
4206        assert_eq!(layout.y, 0.0);
4207
4208        assert_eq!(layout.children[0].width, 10.0);
4209        assert_eq!(layout.children[0].height, 10.0);
4210        assert_eq!(layout.children[0].x, 0.0);
4211        assert_eq!(layout.children[0].y, 90.0);
4212    }
4213
4214    #[test]
4215    fn margin_auto_left_child_bigger_than_parent() {
4216        let layout = stretch::compute(&stretch::style::Node {
4217            justify_content: stretch::style::JustifyContent::Center,
4218            width: stretch::style::Dimension::Points(52.0),
4219            height: stretch::style::Dimension::Points(52.0),
4220            children: vec![stretch::style::Node {
4221                width: stretch::style::Dimension::Points(72.0),
4222                height: stretch::style::Dimension::Points(72.0),
4223                margin: stretch::style::Edges {
4224                    start: stretch::style::Dimension::Auto,
4225                    ..Default::default()
4226                },
4227                ..Default::default()
4228            }],
4229            ..Default::default()
4230        });
4231
4232        assert_eq!(layout.width, 52.0);
4233        assert_eq!(layout.height, 52.0);
4234        assert_eq!(layout.x, 0.0);
4235        assert_eq!(layout.y, 0.0);
4236
4237        assert_eq!(layout.children[0].width, 52.0);
4238        assert_eq!(layout.children[0].height, 72.0);
4239        assert_eq!(layout.children[0].x, 0.0);
4240        assert_eq!(layout.children[0].y, 0.0);
4241    }
4242
4243    #[test]
4244    fn wrapped_row_within_align_items_flex_end() {
4245        let layout = stretch::compute(&stretch::style::Node {
4246            flex_direction: stretch::style::FlexDirection::Column,
4247            align_items: stretch::style::AlignItems::FlexEnd,
4248            width: stretch::style::Dimension::Points(200.0),
4249            height: stretch::style::Dimension::Points(200.0),
4250            children: vec![stretch::style::Node {
4251                children: vec![
4252                    stretch::style::Node {
4253                        width: stretch::style::Dimension::Points(150.0),
4254                        height: stretch::style::Dimension::Points(80.0),
4255                        ..Default::default()
4256                    },
4257                    stretch::style::Node {
4258                        width: stretch::style::Dimension::Points(80.0),
4259                        height: stretch::style::Dimension::Points(80.0),
4260                        ..Default::default()
4261                    },
4262                ],
4263                ..Default::default()
4264            }],
4265            ..Default::default()
4266        });
4267
4268        assert_eq!(layout.width, 200.0);
4269        assert_eq!(layout.height, 200.0);
4270        assert_eq!(layout.x, 0.0);
4271        assert_eq!(layout.y, 0.0);
4272
4273        assert_eq!(layout.children[0].width, 200.0);
4274        assert_eq!(layout.children[0].height, 160.0);
4275        assert_eq!(layout.children[0].x, 0.0);
4276        assert_eq!(layout.children[0].y, 0.0);
4277
4278        assert_eq!(layout.children[0].children[0].width, 150.0);
4279        assert_eq!(layout.children[0].children[0].height, 80.0);
4280        assert_eq!(layout.children[0].children[0].x, 0.0);
4281        assert_eq!(layout.children[0].children[0].y, 0.0);
4282
4283        assert_eq!(layout.children[0].children[1].width, 80.0);
4284        assert_eq!(layout.children[0].children[1].height, 80.0);
4285        assert_eq!(layout.children[0].children[1].x, 0.0);
4286        assert_eq!(layout.children[0].children[1].y, 80.0);
4287    }
4288
4289    #[test]
4290    fn min_height_overrides_height() {
4291        let layout = stretch::compute(&stretch::style::Node {
4292            children: vec![stretch::style::Node {
4293                height: stretch::style::Dimension::Points(50.0),
4294                min_height: stretch::style::Dimension::Points(100.0),
4295                ..Default::default()
4296            }],
4297            ..Default::default()
4298        });
4299
4300        assert_eq!(layout.width, 0.0);
4301        assert_eq!(layout.height, 100.0);
4302        assert_eq!(layout.x, 0.0);
4303        assert_eq!(layout.y, 0.0);
4304
4305        assert_eq!(layout.children[0].width, 0.0);
4306        assert_eq!(layout.children[0].height, 100.0);
4307        assert_eq!(layout.children[0].x, 0.0);
4308        assert_eq!(layout.children[0].y, 0.0);
4309    }
4310
4311    #[test]
4312    fn align_strech_should_size_based_on_parent() {
4313        let layout = stretch::compute(&stretch::style::Node {
4314            width: stretch::style::Dimension::Points(100.0),
4315            height: stretch::style::Dimension::Points(100.0),
4316            children: vec![stretch::style::Node {
4317                justify_content: stretch::style::JustifyContent::Center,
4318                flex_grow: 0.0,
4319                flex_shrink: 1.0,
4320                children: vec![stretch::style::Node {
4321                    flex_grow: 1.0,
4322                    flex_shrink: 1.0,
4323                    children: vec![stretch::style::Node {
4324                        width: stretch::style::Dimension::Points(20.0),
4325                        height: stretch::style::Dimension::Points(20.0),
4326                        ..Default::default()
4327                    }],
4328                    ..Default::default()
4329                }],
4330                ..Default::default()
4331            }],
4332            ..Default::default()
4333        });
4334
4335        assert_eq!(layout.width, 100.0);
4336        assert_eq!(layout.height, 100.0);
4337        assert_eq!(layout.x, 0.0);
4338        assert_eq!(layout.y, 0.0);
4339
4340        assert_eq!(layout.children[0].width, 20.0);
4341        assert_eq!(layout.children[0].height, 100.0);
4342        assert_eq!(layout.children[0].x, 0.0);
4343        assert_eq!(layout.children[0].y, 0.0);
4344
4345        assert_eq!(layout.children[0].children[0].width, 20.0);
4346        assert_eq!(layout.children[0].children[0].height, 100.0);
4347        assert_eq!(layout.children[0].children[0].x, 0.0);
4348        assert_eq!(layout.children[0].children[0].y, 0.0);
4349
4350        assert_eq!(layout.children[0].children[0].children[0].width, 20.0);
4351        assert_eq!(layout.children[0].children[0].children[0].height, 20.0);
4352        assert_eq!(layout.children[0].children[0].children[0].x, 0.0);
4353        assert_eq!(layout.children[0].children[0].children[0].y, 0.0);
4354    }
4355
4356    #[test]
4357    fn wrap_row_align_items_flex_end() {
4358        let layout = stretch::compute(&stretch::style::Node {
4359            align_items: stretch::style::AlignItems::FlexEnd,
4360            width: stretch::style::Dimension::Points(100.0),
4361            children: vec![
4362                stretch::style::Node {
4363                    width: stretch::style::Dimension::Points(30.0),
4364                    height: stretch::style::Dimension::Points(10.0),
4365                    ..Default::default()
4366                },
4367                stretch::style::Node {
4368                    width: stretch::style::Dimension::Points(30.0),
4369                    height: stretch::style::Dimension::Points(20.0),
4370                    ..Default::default()
4371                },
4372                stretch::style::Node {
4373                    width: stretch::style::Dimension::Points(30.0),
4374                    height: stretch::style::Dimension::Points(30.0),
4375                    ..Default::default()
4376                },
4377                stretch::style::Node {
4378                    width: stretch::style::Dimension::Points(30.0),
4379                    height: stretch::style::Dimension::Points(30.0),
4380                    ..Default::default()
4381                },
4382            ],
4383            ..Default::default()
4384        });
4385
4386        assert_eq!(layout.width, 100.0);
4387        assert_eq!(layout.height, 60.0);
4388        assert_eq!(layout.x, 0.0);
4389        assert_eq!(layout.y, 0.0);
4390
4391        assert_eq!(layout.children[0].width, 30.0);
4392        assert_eq!(layout.children[0].height, 10.0);
4393        assert_eq!(layout.children[0].x, 0.0);
4394        assert_eq!(layout.children[0].y, 20.0);
4395
4396        assert_eq!(layout.children[1].width, 30.0);
4397        assert_eq!(layout.children[1].height, 20.0);
4398        assert_eq!(layout.children[1].x, 30.0);
4399        assert_eq!(layout.children[1].y, 10.0);
4400
4401        assert_eq!(layout.children[2].width, 30.0);
4402        assert_eq!(layout.children[2].height, 30.0);
4403        assert_eq!(layout.children[2].x, 60.0);
4404        assert_eq!(layout.children[2].y, 0.0);
4405
4406        assert_eq!(layout.children[3].width, 30.0);
4407        assert_eq!(layout.children[3].height, 30.0);
4408        assert_eq!(layout.children[3].x, 0.0);
4409        assert_eq!(layout.children[3].y, 30.0);
4410    }
4411
4412    #[test]
4413    fn size_defined_by_child_with_border() {
4414        let layout = stretch::compute(&stretch::style::Node {
4415            border: stretch::style::Edges {
4416                start: stretch::style::Dimension::Points(10.0),
4417                end: stretch::style::Dimension::Points(10.0),
4418                top: stretch::style::Dimension::Points(10.0),
4419                bottom: stretch::style::Dimension::Points(10.0),
4420                ..Default::default()
4421            },
4422            children: vec![stretch::style::Node {
4423                width: stretch::style::Dimension::Points(10.0),
4424                height: stretch::style::Dimension::Points(10.0),
4425                ..Default::default()
4426            }],
4427            ..Default::default()
4428        });
4429
4430        assert_eq!(layout.width, 30.0);
4431        assert_eq!(layout.height, 30.0);
4432        assert_eq!(layout.x, 0.0);
4433        assert_eq!(layout.y, 0.0);
4434
4435        assert_eq!(layout.children[0].width, 10.0);
4436        assert_eq!(layout.children[0].height, 10.0);
4437        assert_eq!(layout.children[0].x, 10.0);
4438        assert_eq!(layout.children[0].y, 10.0);
4439    }
4440
4441    #[test]
4442    fn margin_auto_bottom_and_top_justify_center() {
4443        let layout = stretch::compute(&stretch::style::Node {
4444            justify_content: stretch::style::JustifyContent::Center,
4445            width: stretch::style::Dimension::Points(200.0),
4446            height: stretch::style::Dimension::Points(200.0),
4447            children: vec![
4448                stretch::style::Node {
4449                    width: stretch::style::Dimension::Points(50.0),
4450                    height: stretch::style::Dimension::Points(50.0),
4451                    margin: stretch::style::Edges {
4452                        top: stretch::style::Dimension::Auto,
4453                        bottom: stretch::style::Dimension::Auto,
4454                        ..Default::default()
4455                    },
4456                    ..Default::default()
4457                },
4458                stretch::style::Node {
4459                    width: stretch::style::Dimension::Points(50.0),
4460                    height: stretch::style::Dimension::Points(50.0),
4461                    ..Default::default()
4462                },
4463            ],
4464            ..Default::default()
4465        });
4466
4467        assert_eq!(layout.width, 200.0);
4468        assert_eq!(layout.height, 200.0);
4469        assert_eq!(layout.x, 0.0);
4470        assert_eq!(layout.y, 0.0);
4471
4472        assert_eq!(layout.children[0].width, 50.0);
4473        assert_eq!(layout.children[0].height, 50.0);
4474        assert_eq!(layout.children[0].x, 50.0);
4475        assert_eq!(layout.children[0].y, 75.0);
4476
4477        assert_eq!(layout.children[1].width, 50.0);
4478        assert_eq!(layout.children[1].height, 50.0);
4479        assert_eq!(layout.children[1].x, 100.0);
4480        assert_eq!(layout.children[1].y, 0.0);
4481    }
4482
4483    #[test]
4484    fn flex_basis_overrides_main_size() {
4485        let layout = stretch::compute(&stretch::style::Node {
4486            width: stretch::style::Dimension::Points(100.0),
4487            height: stretch::style::Dimension::Points(100.0),
4488            children: vec![
4489                stretch::style::Node {
4490                    flex_grow: 1.0,
4491                    flex_basis: stretch::style::Dimension::Points(50.0),
4492                    width: stretch::style::Dimension::Points(20.0),
4493                    ..Default::default()
4494                },
4495                stretch::style::Node {
4496                    flex_grow: 1.0,
4497                    width: stretch::style::Dimension::Points(10.0),
4498                    ..Default::default()
4499                },
4500                stretch::style::Node {
4501                    flex_grow: 1.0,
4502                    width: stretch::style::Dimension::Points(10.0),
4503                    ..Default::default()
4504                },
4505            ],
4506            ..Default::default()
4507        });
4508
4509        assert_eq!(layout.width, 100.0);
4510        assert_eq!(layout.height, 100.0);
4511        assert_eq!(layout.x, 0.0);
4512        assert_eq!(layout.y, 0.0);
4513
4514        assert_eq!(layout.children[0].width, 60.0);
4515        assert_eq!(layout.children[0].height, 100.0);
4516        assert_eq!(layout.children[0].x, 0.0);
4517        assert_eq!(layout.children[0].y, 0.0);
4518
4519        assert_eq!(layout.children[1].width, 20.0);
4520        assert_eq!(layout.children[1].height, 100.0);
4521        assert_eq!(layout.children[1].x, 60.0);
4522        assert_eq!(layout.children[1].y, 0.0);
4523
4524        assert_eq!(layout.children[2].width, 20.0);
4525        assert_eq!(layout.children[2].height, 100.0);
4526        assert_eq!(layout.children[2].x, 80.0);
4527        assert_eq!(layout.children[2].y, 0.0);
4528    }
4529
4530    #[test]
4531    fn wrapped_row_within_align_items_flex_start() {
4532        let layout = stretch::compute(&stretch::style::Node {
4533            flex_direction: stretch::style::FlexDirection::Column,
4534            align_items: stretch::style::AlignItems::FlexStart,
4535            width: stretch::style::Dimension::Points(200.0),
4536            height: stretch::style::Dimension::Points(200.0),
4537            children: vec![stretch::style::Node {
4538                children: vec![
4539                    stretch::style::Node {
4540                        width: stretch::style::Dimension::Points(150.0),
4541                        height: stretch::style::Dimension::Points(80.0),
4542                        ..Default::default()
4543                    },
4544                    stretch::style::Node {
4545                        width: stretch::style::Dimension::Points(80.0),
4546                        height: stretch::style::Dimension::Points(80.0),
4547                        ..Default::default()
4548                    },
4549                ],
4550                ..Default::default()
4551            }],
4552            ..Default::default()
4553        });
4554
4555        assert_eq!(layout.width, 200.0);
4556        assert_eq!(layout.height, 200.0);
4557        assert_eq!(layout.x, 0.0);
4558        assert_eq!(layout.y, 0.0);
4559
4560        assert_eq!(layout.children[0].width, 200.0);
4561        assert_eq!(layout.children[0].height, 160.0);
4562        assert_eq!(layout.children[0].x, 0.0);
4563        assert_eq!(layout.children[0].y, 0.0);
4564
4565        assert_eq!(layout.children[0].children[0].width, 150.0);
4566        assert_eq!(layout.children[0].children[0].height, 80.0);
4567        assert_eq!(layout.children[0].children[0].x, 0.0);
4568        assert_eq!(layout.children[0].children[0].y, 0.0);
4569
4570        assert_eq!(layout.children[0].children[1].width, 80.0);
4571        assert_eq!(layout.children[0].children[1].height, 80.0);
4572        assert_eq!(layout.children[0].children[1].x, 0.0);
4573        assert_eq!(layout.children[0].children[1].y, 80.0);
4574    }
4575
4576    #[test]
4577    fn align_center_should_size_based_on_content() {
4578        let layout = stretch::compute(&stretch::style::Node {
4579            align_items: stretch::style::AlignItems::Center,
4580            width: stretch::style::Dimension::Points(100.0),
4581            height: stretch::style::Dimension::Points(100.0),
4582            margin: stretch::style::Edges {
4583                top: stretch::style::Dimension::Points(20.0),
4584                ..Default::default()
4585            },
4586            children: vec![stretch::style::Node {
4587                justify_content: stretch::style::JustifyContent::Center,
4588                flex_grow: 0.0,
4589                flex_shrink: 1.0,
4590                children: vec![stretch::style::Node {
4591                    flex_grow: 1.0,
4592                    flex_shrink: 1.0,
4593                    children: vec![stretch::style::Node {
4594                        width: stretch::style::Dimension::Points(20.0),
4595                        height: stretch::style::Dimension::Points(20.0),
4596                        ..Default::default()
4597                    }],
4598                    ..Default::default()
4599                }],
4600                ..Default::default()
4601            }],
4602            ..Default::default()
4603        });
4604
4605        assert_eq!(layout.width, 100.0);
4606        assert_eq!(layout.height, 100.0);
4607        assert_eq!(layout.x, 0.0);
4608        assert_eq!(layout.y, 20.0);
4609
4610        assert_eq!(layout.children[0].width, 20.0);
4611        assert_eq!(layout.children[0].height, 20.0);
4612        assert_eq!(layout.children[0].x, 0.0);
4613        assert_eq!(layout.children[0].y, 40.0);
4614
4615        assert_eq!(layout.children[0].children[0].width, 20.0);
4616        assert_eq!(layout.children[0].children[0].height, 20.0);
4617        assert_eq!(layout.children[0].children[0].x, 0.0);
4618        assert_eq!(layout.children[0].children[0].y, 0.0);
4619
4620        assert_eq!(layout.children[0].children[0].children[0].width, 20.0);
4621        assert_eq!(layout.children[0].children[0].children[0].height, 20.0);
4622        assert_eq!(layout.children[0].children[0].children[0].x, 0.0);
4623        assert_eq!(layout.children[0].children[0].children[0].y, 0.0);
4624    }
4625
4626    #[test]
4627    fn margin_auto_right() {
4628        let layout = stretch::compute(&stretch::style::Node {
4629            align_items: stretch::style::AlignItems::Center,
4630            width: stretch::style::Dimension::Points(200.0),
4631            height: stretch::style::Dimension::Points(200.0),
4632            children: vec![
4633                stretch::style::Node {
4634                    width: stretch::style::Dimension::Points(50.0),
4635                    height: stretch::style::Dimension::Points(50.0),
4636                    margin: stretch::style::Edges {
4637                        end: stretch::style::Dimension::Auto,
4638                        ..Default::default()
4639                    },
4640                    ..Default::default()
4641                },
4642                stretch::style::Node {
4643                    width: stretch::style::Dimension::Points(50.0),
4644                    height: stretch::style::Dimension::Points(50.0),
4645                    ..Default::default()
4646                },
4647            ],
4648            ..Default::default()
4649        });
4650
4651        assert_eq!(layout.width, 200.0);
4652        assert_eq!(layout.height, 200.0);
4653        assert_eq!(layout.x, 0.0);
4654        assert_eq!(layout.y, 0.0);
4655
4656        assert_eq!(layout.children[0].width, 50.0);
4657        assert_eq!(layout.children[0].height, 50.0);
4658        assert_eq!(layout.children[0].x, 0.0);
4659        assert_eq!(layout.children[0].y, 75.0);
4660
4661        assert_eq!(layout.children[1].width, 50.0);
4662        assert_eq!(layout.children[1].height, 50.0);
4663        assert_eq!(layout.children[1].x, 150.0);
4664        assert_eq!(layout.children[1].y, 75.0);
4665    }
4666
4667    #[test]
4668    fn wrap_reverse_row_align_content_center() {
4669        let layout = stretch::compute(&stretch::style::Node {
4670            align_content: stretch::style::AlignContent::Center,
4671            width: stretch::style::Dimension::Points(100.0),
4672            children: vec![
4673                stretch::style::Node {
4674                    width: stretch::style::Dimension::Points(30.0),
4675                    height: stretch::style::Dimension::Points(10.0),
4676                    ..Default::default()
4677                },
4678                stretch::style::Node {
4679                    width: stretch::style::Dimension::Points(30.0),
4680                    height: stretch::style::Dimension::Points(20.0),
4681                    ..Default::default()
4682                },
4683                stretch::style::Node {
4684                    width: stretch::style::Dimension::Points(30.0),
4685                    height: stretch::style::Dimension::Points(30.0),
4686                    ..Default::default()
4687                },
4688                stretch::style::Node {
4689                    width: stretch::style::Dimension::Points(30.0),
4690                    height: stretch::style::Dimension::Points(40.0),
4691                    ..Default::default()
4692                },
4693                stretch::style::Node {
4694                    width: stretch::style::Dimension::Points(30.0),
4695                    height: stretch::style::Dimension::Points(50.0),
4696                    ..Default::default()
4697                },
4698            ],
4699            ..Default::default()
4700        });
4701
4702        assert_eq!(layout.width, 100.0);
4703        assert_eq!(layout.height, 80.0);
4704        assert_eq!(layout.x, 0.0);
4705        assert_eq!(layout.y, 0.0);
4706
4707        assert_eq!(layout.children[0].width, 30.0);
4708        assert_eq!(layout.children[0].height, 10.0);
4709        assert_eq!(layout.children[0].x, 0.0);
4710        assert_eq!(layout.children[0].y, 70.0);
4711
4712        assert_eq!(layout.children[1].width, 30.0);
4713        assert_eq!(layout.children[1].height, 20.0);
4714        assert_eq!(layout.children[1].x, 30.0);
4715        assert_eq!(layout.children[1].y, 60.0);
4716
4717        assert_eq!(layout.children[2].width, 30.0);
4718        assert_eq!(layout.children[2].height, 30.0);
4719        assert_eq!(layout.children[2].x, 60.0);
4720        assert_eq!(layout.children[2].y, 50.0);
4721
4722        assert_eq!(layout.children[3].width, 30.0);
4723        assert_eq!(layout.children[3].height, 40.0);
4724        assert_eq!(layout.children[3].x, 0.0);
4725        assert_eq!(layout.children[3].y, 10.0);
4726
4727        assert_eq!(layout.children[4].width, 30.0);
4728        assert_eq!(layout.children[4].height, 50.0);
4729        assert_eq!(layout.children[4].x, 30.0);
4730        assert_eq!(layout.children[4].y, 0.0);
4731    }
4732
4733    #[test]
4734    fn padding_no_child() {
4735        let layout = stretch::compute(&stretch::style::Node {
4736            padding: stretch::style::Edges {
4737                start: stretch::style::Dimension::Points(10.0),
4738                end: stretch::style::Dimension::Points(10.0),
4739                top: stretch::style::Dimension::Points(10.0),
4740                bottom: stretch::style::Dimension::Points(10.0),
4741                ..Default::default()
4742            },
4743            ..Default::default()
4744        });
4745
4746        assert_eq!(layout.width, 20.0);
4747        assert_eq!(layout.height, 20.0);
4748        assert_eq!(layout.x, 0.0);
4749        assert_eq!(layout.y, 0.0);
4750    }
4751
4752    #[test]
4753    fn margin_with_sibling_column() {
4754        let layout = stretch::compute(&stretch::style::Node {
4755            flex_direction: stretch::style::FlexDirection::Column,
4756            width: stretch::style::Dimension::Points(100.0),
4757            height: stretch::style::Dimension::Points(100.0),
4758            children: vec![
4759                stretch::style::Node {
4760                    flex_grow: 1.0,
4761                    margin: stretch::style::Edges {
4762                        bottom: stretch::style::Dimension::Points(10.0),
4763                        ..Default::default()
4764                    },
4765                    ..Default::default()
4766                },
4767                stretch::style::Node {
4768                    flex_grow: 1.0,
4769                    ..Default::default()
4770                },
4771            ],
4772            ..Default::default()
4773        });
4774
4775        assert_eq!(layout.width, 100.0);
4776        assert_eq!(layout.height, 100.0);
4777        assert_eq!(layout.x, 0.0);
4778        assert_eq!(layout.y, 0.0);
4779
4780        assert_eq!(layout.children[0].width, 100.0);
4781        assert_eq!(layout.children[0].height, 45.0);
4782        assert_eq!(layout.children[0].x, 0.0);
4783        assert_eq!(layout.children[0].y, 0.0);
4784
4785        assert_eq!(layout.children[1].width, 100.0);
4786        assert_eq!(layout.children[1].height, 45.0);
4787        assert_eq!(layout.children[1].x, 0.0);
4788        assert_eq!(layout.children[1].y, 55.0);
4789    }
4790
4791    #[test]
4792    fn flex_direction_row_no_width() {
4793        let layout = stretch::compute(&stretch::style::Node {
4794            height: stretch::style::Dimension::Points(100.0),
4795            children: vec![
4796                stretch::style::Node {
4797                    width: stretch::style::Dimension::Points(10.0),
4798                    ..Default::default()
4799                },
4800                stretch::style::Node {
4801                    width: stretch::style::Dimension::Points(10.0),
4802                    ..Default::default()
4803                },
4804                stretch::style::Node {
4805                    width: stretch::style::Dimension::Points(10.0),
4806                    ..Default::default()
4807                },
4808            ],
4809            ..Default::default()
4810        });
4811
4812        assert_eq!(layout.width, 30.0);
4813        assert_eq!(layout.height, 100.0);
4814        assert_eq!(layout.x, 0.0);
4815        assert_eq!(layout.y, 0.0);
4816
4817        assert_eq!(layout.children[0].width, 10.0);
4818        assert_eq!(layout.children[0].height, 100.0);
4819        assert_eq!(layout.children[0].x, 0.0);
4820        assert_eq!(layout.children[0].y, 0.0);
4821
4822        assert_eq!(layout.children[1].width, 10.0);
4823        assert_eq!(layout.children[1].height, 100.0);
4824        assert_eq!(layout.children[1].x, 10.0);
4825        assert_eq!(layout.children[1].y, 0.0);
4826
4827        assert_eq!(layout.children[2].width, 10.0);
4828        assert_eq!(layout.children[2].height, 100.0);
4829        assert_eq!(layout.children[2].x, 20.0);
4830        assert_eq!(layout.children[2].y, 0.0);
4831    }
4832
4833    #[test]
4834    fn max_width_overrides_width_on_root() {
4835        let layout = stretch::compute(&stretch::style::Node {
4836            width: stretch::style::Dimension::Points(200.0),
4837            max_width: stretch::style::Dimension::Points(100.0),
4838            ..Default::default()
4839        });
4840
4841        assert_eq!(layout.width, 100.0);
4842        assert_eq!(layout.height, 0.0);
4843        assert_eq!(layout.x, 0.0);
4844        assert_eq!(layout.y, 0.0);
4845    }
4846
4847    #[test]
4848    fn margin_auto_left_and_right() {
4849        let layout = stretch::compute(&stretch::style::Node {
4850            width: stretch::style::Dimension::Points(200.0),
4851            height: stretch::style::Dimension::Points(200.0),
4852            children: vec![
4853                stretch::style::Node {
4854                    width: stretch::style::Dimension::Points(50.0),
4855                    height: stretch::style::Dimension::Points(50.0),
4856                    margin: stretch::style::Edges {
4857                        start: stretch::style::Dimension::Auto,
4858                        end: stretch::style::Dimension::Auto,
4859                        ..Default::default()
4860                    },
4861                    ..Default::default()
4862                },
4863                stretch::style::Node {
4864                    width: stretch::style::Dimension::Points(50.0),
4865                    height: stretch::style::Dimension::Points(50.0),
4866                    ..Default::default()
4867                },
4868            ],
4869            ..Default::default()
4870        });
4871
4872        assert_eq!(layout.width, 200.0);
4873        assert_eq!(layout.height, 200.0);
4874        assert_eq!(layout.x, 0.0);
4875        assert_eq!(layout.y, 0.0);
4876
4877        assert_eq!(layout.children[0].width, 50.0);
4878        assert_eq!(layout.children[0].height, 50.0);
4879        assert_eq!(layout.children[0].x, 50.0);
4880        assert_eq!(layout.children[0].y, 0.0);
4881
4882        assert_eq!(layout.children[1].width, 50.0);
4883        assert_eq!(layout.children[1].height, 50.0);
4884        assert_eq!(layout.children[1].x, 150.0);
4885        assert_eq!(layout.children[1].y, 0.0);
4886    }
4887
4888    #[test]
4889    fn flex_direction_column_no_height() {
4890        let layout = stretch::compute(&stretch::style::Node {
4891            flex_direction: stretch::style::FlexDirection::Column,
4892            width: stretch::style::Dimension::Points(100.0),
4893            children: vec![
4894                stretch::style::Node {
4895                    height: stretch::style::Dimension::Points(10.0),
4896                    ..Default::default()
4897                },
4898                stretch::style::Node {
4899                    height: stretch::style::Dimension::Points(10.0),
4900                    ..Default::default()
4901                },
4902                stretch::style::Node {
4903                    height: stretch::style::Dimension::Points(10.0),
4904                    ..Default::default()
4905                },
4906            ],
4907            ..Default::default()
4908        });
4909
4910        assert_eq!(layout.width, 100.0);
4911        assert_eq!(layout.height, 30.0);
4912        assert_eq!(layout.x, 0.0);
4913        assert_eq!(layout.y, 0.0);
4914
4915        assert_eq!(layout.children[0].width, 100.0);
4916        assert_eq!(layout.children[0].height, 10.0);
4917        assert_eq!(layout.children[0].x, 0.0);
4918        assert_eq!(layout.children[0].y, 0.0);
4919
4920        assert_eq!(layout.children[1].width, 100.0);
4921        assert_eq!(layout.children[1].height, 10.0);
4922        assert_eq!(layout.children[1].x, 0.0);
4923        assert_eq!(layout.children[1].y, 10.0);
4924
4925        assert_eq!(layout.children[2].width, 100.0);
4926        assert_eq!(layout.children[2].height, 10.0);
4927        assert_eq!(layout.children[2].x, 0.0);
4928        assert_eq!(layout.children[2].y, 20.0);
4929    }
4930
4931    #[test]
4932    fn absolute_layout_in_wrap_reverse_row_container() {
4933        let layout = stretch::compute(&stretch::style::Node {
4934            width: stretch::style::Dimension::Points(100.0),
4935            height: stretch::style::Dimension::Points(100.0),
4936            children: vec![stretch::style::Node {
4937                position: stretch::style::Position::Absolute,
4938                width: stretch::style::Dimension::Points(20.0),
4939                height: stretch::style::Dimension::Points(20.0),
4940                ..Default::default()
4941            }],
4942            ..Default::default()
4943        });
4944
4945        assert_eq!(layout.width, 100.0);
4946        assert_eq!(layout.height, 100.0);
4947        assert_eq!(layout.x, 0.0);
4948        assert_eq!(layout.y, 0.0);
4949
4950        assert_eq!(layout.children[0].width, 20.0);
4951        assert_eq!(layout.children[0].height, 20.0);
4952        assert_eq!(layout.children[0].x, 0.0);
4953        assert_eq!(layout.children[0].y, 80.0);
4954    }
4955
4956    #[test]
4957    fn percentage_margin_should_calculate_based_only_on_width() {
4958        let layout = stretch::compute(&stretch::style::Node {
4959            flex_direction: stretch::style::FlexDirection::Column,
4960            width: stretch::style::Dimension::Points(200.0),
4961            height: stretch::style::Dimension::Points(100.0),
4962            children: vec![stretch::style::Node {
4963                flex_direction: stretch::style::FlexDirection::Column,
4964                flex_grow: 1.0,
4965                margin: stretch::style::Edges {
4966                    start: stretch::style::Dimension::Percent(0.1),
4967                    end: stretch::style::Dimension::Percent(0.1),
4968                    top: stretch::style::Dimension::Percent(0.1),
4969                    bottom: stretch::style::Dimension::Percent(0.1),
4970                    ..Default::default()
4971                },
4972                children: vec![stretch::style::Node {
4973                    width: stretch::style::Dimension::Points(10.0),
4974                    height: stretch::style::Dimension::Points(10.0),
4975                    ..Default::default()
4976                }],
4977                ..Default::default()
4978            }],
4979            ..Default::default()
4980        });
4981
4982        assert_eq!(layout.width, 200.0);
4983        assert_eq!(layout.height, 100.0);
4984        assert_eq!(layout.x, 0.0);
4985        assert_eq!(layout.y, 0.0);
4986
4987        assert_eq!(layout.children[0].width, 160.0);
4988        assert_eq!(layout.children[0].height, 60.0);
4989        assert_eq!(layout.children[0].x, 20.0);
4990        assert_eq!(layout.children[0].y, 20.0);
4991
4992        assert_eq!(layout.children[0].children[0].width, 10.0);
4993        assert_eq!(layout.children[0].children[0].height, 10.0);
4994        assert_eq!(layout.children[0].children[0].x, 0.0);
4995        assert_eq!(layout.children[0].children[0].y, 0.0);
4996    }
4997
4998    #[test]
4999    fn absolute_layout_start_top_end_bottom() {
5000        let layout = stretch::compute(&stretch::style::Node {
5001            width: stretch::style::Dimension::Points(100.0),
5002            height: stretch::style::Dimension::Points(100.0),
5003            children: vec![stretch::style::Node {
5004                position: stretch::style::Position::Absolute,
5005                start: stretch::style::Dimension::Points(10.0),
5006                end: stretch::style::Dimension::Points(10.0),
5007                top: stretch::style::Dimension::Points(10.0),
5008                bottom: stretch::style::Dimension::Points(10.0),
5009                ..Default::default()
5010            }],
5011            ..Default::default()
5012        });
5013
5014        assert_eq!(layout.width, 100.0);
5015        assert_eq!(layout.height, 100.0);
5016        assert_eq!(layout.x, 0.0);
5017        assert_eq!(layout.y, 0.0);
5018
5019        assert_eq!(layout.children[0].width, 80.0);
5020        assert_eq!(layout.children[0].height, 80.0);
5021        assert_eq!(layout.children[0].x, 10.0);
5022        assert_eq!(layout.children[0].y, 10.0);
5023    }
5024
5025    #[test]
5026    fn min_width() {
5027        let layout = stretch::compute(&stretch::style::Node {
5028            width: stretch::style::Dimension::Points(100.0),
5029            height: stretch::style::Dimension::Points(100.0),
5030            children: vec![
5031                stretch::style::Node {
5032                    flex_grow: 1.0,
5033                    min_width: stretch::style::Dimension::Points(60.0),
5034                    ..Default::default()
5035                },
5036                stretch::style::Node {
5037                    flex_grow: 1.0,
5038                    ..Default::default()
5039                },
5040            ],
5041            ..Default::default()
5042        });
5043
5044        assert_eq!(layout.width, 100.0);
5045        assert_eq!(layout.height, 100.0);
5046        assert_eq!(layout.x, 0.0);
5047        assert_eq!(layout.y, 0.0);
5048
5049        assert_eq!(layout.children[0].width, 80.0);
5050        assert_eq!(layout.children[0].height, 100.0);
5051        assert_eq!(layout.children[0].x, 0.0);
5052        assert_eq!(layout.children[0].y, 0.0);
5053
5054        assert_eq!(layout.children[1].width, 20.0);
5055        assert_eq!(layout.children[1].height, 100.0);
5056        assert_eq!(layout.children[1].x, 80.0);
5057        assert_eq!(layout.children[1].y, 0.0);
5058    }
5059
5060    #[test]
5061    fn min_height_overrides_height_on_root() {
5062        let layout = stretch::compute(&stretch::style::Node {
5063            height: stretch::style::Dimension::Points(50.0),
5064            min_height: stretch::style::Dimension::Points(100.0),
5065            ..Default::default()
5066        });
5067
5068        assert_eq!(layout.width, 0.0);
5069        assert_eq!(layout.height, 100.0);
5070        assert_eq!(layout.x, 0.0);
5071        assert_eq!(layout.y, 0.0);
5072    }
5073
5074    #[test]
5075    fn absolute_layout_width_height_end_bottom() {
5076        let layout = stretch::compute(&stretch::style::Node {
5077            width: stretch::style::Dimension::Points(100.0),
5078            height: stretch::style::Dimension::Points(100.0),
5079            children: vec![stretch::style::Node {
5080                position: stretch::style::Position::Absolute,
5081                width: stretch::style::Dimension::Points(10.0),
5082                height: stretch::style::Dimension::Points(10.0),
5083                end: stretch::style::Dimension::Points(10.0),
5084                bottom: stretch::style::Dimension::Points(10.0),
5085                ..Default::default()
5086            }],
5087            ..Default::default()
5088        });
5089
5090        assert_eq!(layout.width, 100.0);
5091        assert_eq!(layout.height, 100.0);
5092        assert_eq!(layout.x, 0.0);
5093        assert_eq!(layout.y, 0.0);
5094
5095        assert_eq!(layout.children[0].width, 10.0);
5096        assert_eq!(layout.children[0].height, 10.0);
5097        assert_eq!(layout.children[0].x, 80.0);
5098        assert_eq!(layout.children[0].y, 80.0);
5099    }
5100
5101    #[test]
5102    fn align_self_center() {
5103        let layout = stretch::compute(&stretch::style::Node {
5104            width: stretch::style::Dimension::Points(100.0),
5105            height: stretch::style::Dimension::Points(100.0),
5106            children: vec![stretch::style::Node {
5107                align_self: stretch::style::AlignSelf::Center,
5108                width: stretch::style::Dimension::Points(10.0),
5109                height: stretch::style::Dimension::Points(10.0),
5110                ..Default::default()
5111            }],
5112            ..Default::default()
5113        });
5114
5115        assert_eq!(layout.width, 100.0);
5116        assert_eq!(layout.height, 100.0);
5117        assert_eq!(layout.x, 0.0);
5118        assert_eq!(layout.y, 0.0);
5119
5120        assert_eq!(layout.children[0].width, 10.0);
5121        assert_eq!(layout.children[0].height, 10.0);
5122        assert_eq!(layout.children[0].x, 0.0);
5123        assert_eq!(layout.children[0].y, 45.0);
5124    }
5125
5126    #[test]
5127    fn wrapped_column_max_height() {
5128        let layout = stretch::compute(&stretch::style::Node {
5129            flex_direction: stretch::style::FlexDirection::Column,
5130            align_items: stretch::style::AlignItems::Center,
5131            align_content: stretch::style::AlignContent::Center,
5132            justify_content: stretch::style::JustifyContent::Center,
5133            width: stretch::style::Dimension::Points(700.0),
5134            height: stretch::style::Dimension::Points(500.0),
5135            children: vec![
5136                stretch::style::Node {
5137                    width: stretch::style::Dimension::Points(100.0),
5138                    height: stretch::style::Dimension::Points(500.0),
5139                    max_height: stretch::style::Dimension::Points(200.0),
5140                    ..Default::default()
5141                },
5142                stretch::style::Node {
5143                    width: stretch::style::Dimension::Points(200.0),
5144                    height: stretch::style::Dimension::Points(200.0),
5145                    margin: stretch::style::Edges {
5146                        start: stretch::style::Dimension::Points(20.0),
5147                        end: stretch::style::Dimension::Points(20.0),
5148                        top: stretch::style::Dimension::Points(20.0),
5149                        bottom: stretch::style::Dimension::Points(20.0),
5150                        ..Default::default()
5151                    },
5152                    ..Default::default()
5153                },
5154                stretch::style::Node {
5155                    width: stretch::style::Dimension::Points(100.0),
5156                    height: stretch::style::Dimension::Points(100.0),
5157                    ..Default::default()
5158                },
5159            ],
5160            ..Default::default()
5161        });
5162
5163        assert_eq!(layout.width, 700.0);
5164        assert_eq!(layout.height, 500.0);
5165        assert_eq!(layout.x, 0.0);
5166        assert_eq!(layout.y, 0.0);
5167
5168        assert_eq!(layout.children[0].width, 100.0);
5169        assert_eq!(layout.children[0].height, 200.0);
5170        assert_eq!(layout.children[0].x, 250.0);
5171        assert_eq!(layout.children[0].y, 30.0);
5172
5173        assert_eq!(layout.children[1].width, 200.0);
5174        assert_eq!(layout.children[1].height, 200.0);
5175        assert_eq!(layout.children[1].x, 200.0);
5176        assert_eq!(layout.children[1].y, 250.0);
5177
5178        assert_eq!(layout.children[2].width, 100.0);
5179        assert_eq!(layout.children[2].height, 100.0);
5180        assert_eq!(layout.children[2].x, 420.0);
5181        assert_eq!(layout.children[2].y, 200.0);
5182    }
5183
5184    #[test]
5185    fn wrap_row() {
5186        let layout = stretch::compute(&stretch::style::Node {
5187            width: stretch::style::Dimension::Points(100.0),
5188            children: vec![
5189                stretch::style::Node {
5190                    width: stretch::style::Dimension::Points(30.0),
5191                    height: stretch::style::Dimension::Points(30.0),
5192                    ..Default::default()
5193                },
5194                stretch::style::Node {
5195                    width: stretch::style::Dimension::Points(30.0),
5196                    height: stretch::style::Dimension::Points(30.0),
5197                    ..Default::default()
5198                },
5199                stretch::style::Node {
5200                    width: stretch::style::Dimension::Points(30.0),
5201                    height: stretch::style::Dimension::Points(30.0),
5202                    ..Default::default()
5203                },
5204                stretch::style::Node {
5205                    width: stretch::style::Dimension::Points(30.0),
5206                    height: stretch::style::Dimension::Points(30.0),
5207                    ..Default::default()
5208                },
5209            ],
5210            ..Default::default()
5211        });
5212
5213        assert_eq!(layout.width, 100.0);
5214        assert_eq!(layout.height, 60.0);
5215        assert_eq!(layout.x, 0.0);
5216        assert_eq!(layout.y, 0.0);
5217
5218        assert_eq!(layout.children[0].width, 30.0);
5219        assert_eq!(layout.children[0].height, 30.0);
5220        assert_eq!(layout.children[0].x, 0.0);
5221        assert_eq!(layout.children[0].y, 0.0);
5222
5223        assert_eq!(layout.children[1].width, 30.0);
5224        assert_eq!(layout.children[1].height, 30.0);
5225        assert_eq!(layout.children[1].x, 30.0);
5226        assert_eq!(layout.children[1].y, 0.0);
5227
5228        assert_eq!(layout.children[2].width, 30.0);
5229        assert_eq!(layout.children[2].height, 30.0);
5230        assert_eq!(layout.children[2].x, 60.0);
5231        assert_eq!(layout.children[2].y, 0.0);
5232
5233        assert_eq!(layout.children[3].width, 30.0);
5234        assert_eq!(layout.children[3].height, 30.0);
5235        assert_eq!(layout.children[3].x, 0.0);
5236        assert_eq!(layout.children[3].y, 30.0);
5237    }
5238
5239    #[test]
5240    fn max_height() {
5241        let layout = stretch::compute(&stretch::style::Node {
5242            width: stretch::style::Dimension::Points(100.0),
5243            height: stretch::style::Dimension::Points(100.0),
5244            children: vec![stretch::style::Node {
5245                width: stretch::style::Dimension::Points(10.0),
5246                max_height: stretch::style::Dimension::Points(50.0),
5247                ..Default::default()
5248            }],
5249            ..Default::default()
5250        });
5251
5252        assert_eq!(layout.width, 100.0);
5253        assert_eq!(layout.height, 100.0);
5254        assert_eq!(layout.x, 0.0);
5255        assert_eq!(layout.y, 0.0);
5256
5257        assert_eq!(layout.children[0].width, 10.0);
5258        assert_eq!(layout.children[0].height, 50.0);
5259        assert_eq!(layout.children[0].x, 0.0);
5260        assert_eq!(layout.children[0].y, 0.0);
5261    }
5262
5263    #[test]
5264    fn flex_grow_child() {
5265        let layout = stretch::compute(&stretch::style::Node {
5266            children: vec![stretch::style::Node {
5267                flex_grow: 1.0,
5268                flex_basis: stretch::style::Dimension::Points(0.0),
5269                height: stretch::style::Dimension::Points(100.0),
5270                ..Default::default()
5271            }],
5272            ..Default::default()
5273        });
5274
5275        assert_eq!(layout.width, 0.0);
5276        assert_eq!(layout.height, 100.0);
5277        assert_eq!(layout.x, 0.0);
5278        assert_eq!(layout.y, 0.0);
5279
5280        assert_eq!(layout.children[0].width, 0.0);
5281        assert_eq!(layout.children[0].height, 100.0);
5282        assert_eq!(layout.children[0].x, 0.0);
5283        assert_eq!(layout.children[0].y, 0.0);
5284    }
5285
5286    #[test]
5287    fn align_items_flex_end_child_with_margin_bigger_than_parent() {
5288        let layout = stretch::compute(&stretch::style::Node {
5289            align_items: stretch::style::AlignItems::Center,
5290            justify_content: stretch::style::JustifyContent::Center,
5291            width: stretch::style::Dimension::Points(52.0),
5292            height: stretch::style::Dimension::Points(52.0),
5293            children: vec![stretch::style::Node {
5294                align_items: stretch::style::AlignItems::FlexEnd,
5295                children: vec![stretch::style::Node {
5296                    width: stretch::style::Dimension::Points(52.0),
5297                    height: stretch::style::Dimension::Points(52.0),
5298                    margin: stretch::style::Edges {
5299                        start: stretch::style::Dimension::Points(10.0),
5300                        end: stretch::style::Dimension::Points(10.0),
5301                        ..Default::default()
5302                    },
5303                    ..Default::default()
5304                }],
5305                ..Default::default()
5306            }],
5307            ..Default::default()
5308        });
5309
5310        assert_eq!(layout.width, 52.0);
5311        assert_eq!(layout.height, 52.0);
5312        assert_eq!(layout.x, 0.0);
5313        assert_eq!(layout.y, 0.0);
5314
5315        assert_eq!(layout.children[0].width, 72.0);
5316        assert_eq!(layout.children[0].height, 52.0);
5317        assert_eq!(layout.children[0].x, -10.0);
5318        assert_eq!(layout.children[0].y, 0.0);
5319
5320        assert_eq!(layout.children[0].children[0].width, 52.0);
5321        assert_eq!(layout.children[0].children[0].height, 52.0);
5322        assert_eq!(layout.children[0].children[0].x, 10.0);
5323        assert_eq!(layout.children[0].children[0].y, 0.0);
5324    }
5325
5326    #[test]
5327    fn justify_content_row_max_width_and_margin() {
5328        let layout = stretch::compute(&stretch::style::Node {
5329            justify_content: stretch::style::JustifyContent::Center,
5330            width: stretch::style::Dimension::Points(100.0),
5331            max_width: stretch::style::Dimension::Points(80.0),
5332            margin: stretch::style::Edges {
5333                start: stretch::style::Dimension::Points(100.0),
5334                ..Default::default()
5335            },
5336            children: vec![stretch::style::Node {
5337                width: stretch::style::Dimension::Points(20.0),
5338                height: stretch::style::Dimension::Points(20.0),
5339                ..Default::default()
5340            }],
5341            ..Default::default()
5342        });
5343
5344        assert_eq!(layout.width, 80.0);
5345        assert_eq!(layout.height, 20.0);
5346        assert_eq!(layout.x, 100.0);
5347        assert_eq!(layout.y, 0.0);
5348
5349        assert_eq!(layout.children[0].width, 20.0);
5350        assert_eq!(layout.children[0].height, 20.0);
5351        assert_eq!(layout.children[0].x, 30.0);
5352        assert_eq!(layout.children[0].y, 0.0);
5353    }
5354
5355    #[test]
5356    fn margin_left() {
5357        let layout = stretch::compute(&stretch::style::Node {
5358            width: stretch::style::Dimension::Points(100.0),
5359            height: stretch::style::Dimension::Points(100.0),
5360            children: vec![stretch::style::Node {
5361                width: stretch::style::Dimension::Points(10.0),
5362                margin: stretch::style::Edges {
5363                    start: stretch::style::Dimension::Points(10.0),
5364                    ..Default::default()
5365                },
5366                ..Default::default()
5367            }],
5368            ..Default::default()
5369        });
5370
5371        assert_eq!(layout.width, 100.0);
5372        assert_eq!(layout.height, 100.0);
5373        assert_eq!(layout.x, 0.0);
5374        assert_eq!(layout.y, 0.0);
5375
5376        assert_eq!(layout.children[0].width, 10.0);
5377        assert_eq!(layout.children[0].height, 100.0);
5378        assert_eq!(layout.children[0].x, 10.0);
5379        assert_eq!(layout.children[0].y, 0.0);
5380    }
5381
5382    #[test]
5383    fn size_defined_by_child() {
5384        let layout = stretch::compute(&stretch::style::Node {
5385            children: vec![stretch::style::Node {
5386                width: stretch::style::Dimension::Points(100.0),
5387                height: stretch::style::Dimension::Points(100.0),
5388                ..Default::default()
5389            }],
5390            ..Default::default()
5391        });
5392
5393        assert_eq!(layout.width, 100.0);
5394        assert_eq!(layout.height, 100.0);
5395        assert_eq!(layout.x, 0.0);
5396        assert_eq!(layout.y, 0.0);
5397
5398        assert_eq!(layout.children[0].width, 100.0);
5399        assert_eq!(layout.children[0].height, 100.0);
5400        assert_eq!(layout.children[0].x, 0.0);
5401        assert_eq!(layout.children[0].y, 0.0);
5402    }
5403
5404    #[test]
5405    fn rounding_total_fractial_nested() {
5406        let layout = stretch::compute(&stretch::style::Node {
5407            flex_direction: stretch::style::FlexDirection::Column,
5408            width: stretch::style::Dimension::Points(87.4),
5409            height: stretch::style::Dimension::Points(113.4),
5410            children: vec![
5411                stretch::style::Node {
5412                    flex_direction: stretch::style::FlexDirection::Column,
5413                    flex_grow: 0.7,
5414                    flex_basis: stretch::style::Dimension::Points(50.3),
5415                    height: stretch::style::Dimension::Points(20.3),
5416                    children: vec![
5417                        stretch::style::Node {
5418                            flex_grow: 1.0,
5419                            flex_basis: stretch::style::Dimension::Points(0.3),
5420                            height: stretch::style::Dimension::Points(9.9),
5421                            bottom: stretch::style::Dimension::Points(13.3),
5422                            ..Default::default()
5423                        },
5424                        stretch::style::Node {
5425                            flex_grow: 4.0,
5426                            flex_basis: stretch::style::Dimension::Points(0.3),
5427                            height: stretch::style::Dimension::Points(1.1),
5428                            top: stretch::style::Dimension::Points(13.3),
5429                            ..Default::default()
5430                        },
5431                    ],
5432                    ..Default::default()
5433                },
5434                stretch::style::Node {
5435                    flex_grow: 1.6,
5436                    height: stretch::style::Dimension::Points(10.0),
5437                    ..Default::default()
5438                },
5439                stretch::style::Node {
5440                    flex_grow: 1.1,
5441                    height: stretch::style::Dimension::Points(10.7),
5442                    ..Default::default()
5443                },
5444            ],
5445            ..Default::default()
5446        });
5447
5448        assert_eq!(layout.width, 87.0);
5449        assert_eq!(layout.height, 113.0);
5450        assert_eq!(layout.x, 0.0);
5451        assert_eq!(layout.y, 0.0);
5452
5453        assert_eq!(layout.children[0].width, 87.0);
5454        assert_eq!(layout.children[0].height, 59.0);
5455        assert_eq!(layout.children[0].x, 0.0);
5456        assert_eq!(layout.children[0].y, 0.0);
5457
5458        assert_eq!(layout.children[0].children[0].width, 87.0);
5459        assert_eq!(layout.children[0].children[0].height, 12.0);
5460        assert_eq!(layout.children[0].children[0].x, 0.0);
5461        assert_eq!(layout.children[0].children[0].y, -13.0);
5462
5463        assert_eq!(layout.children[0].children[1].width, 87.0);
5464        assert_eq!(layout.children[0].children[1].height, 47.0);
5465        assert_eq!(layout.children[0].children[1].x, 0.0);
5466        assert_eq!(layout.children[0].children[1].y, 25.0);
5467
5468        assert_eq!(layout.children[1].width, 87.0);
5469        assert_eq!(layout.children[1].height, 30.0);
5470        assert_eq!(layout.children[1].x, 0.0);
5471        assert_eq!(layout.children[1].y, 59.0);
5472
5473        assert_eq!(layout.children[2].width, 87.0);
5474        assert_eq!(layout.children[2].height, 24.0);
5475        assert_eq!(layout.children[2].x, 0.0);
5476        assert_eq!(layout.children[2].y, 89.0);
5477    }
5478
5479    #[test]
5480    fn min_max_percent_no_width_height() {
5481        let layout = stretch::compute(&stretch::style::Node {
5482            flex_direction: stretch::style::FlexDirection::Column,
5483            align_items: stretch::style::AlignItems::FlexStart,
5484            width: stretch::style::Dimension::Points(100.0),
5485            height: stretch::style::Dimension::Points(100.0),
5486            children: vec![stretch::style::Node {
5487                min_width: stretch::style::Dimension::Percent(0.1),
5488                max_width: stretch::style::Dimension::Percent(0.1),
5489                min_height: stretch::style::Dimension::Percent(0.1),
5490                max_height: stretch::style::Dimension::Percent(0.1),
5491                ..Default::default()
5492            }],
5493            ..Default::default()
5494        });
5495
5496        assert_eq!(layout.width, 100.0);
5497        assert_eq!(layout.height, 100.0);
5498        assert_eq!(layout.x, 0.0);
5499        assert_eq!(layout.y, 0.0);
5500
5501        assert_eq!(layout.children[0].width, 10.0);
5502        assert_eq!(layout.children[0].height, 10.0);
5503        assert_eq!(layout.children[0].x, 0.0);
5504        assert_eq!(layout.children[0].y, 0.0);
5505    }
5506
5507    #[test]
5508    fn percent_within_flex_grow() {
5509        let layout = stretch::compute(&stretch::style::Node {
5510            width: stretch::style::Dimension::Points(350.0),
5511            height: stretch::style::Dimension::Points(100.0),
5512            children: vec![
5513                stretch::style::Node {
5514                    width: stretch::style::Dimension::Points(100.0),
5515                    ..Default::default()
5516                },
5517                stretch::style::Node {
5518                    flex_direction: stretch::style::FlexDirection::Column,
5519                    flex_grow: 1.0,
5520                    children: vec![stretch::style::Node {
5521                        width: stretch::style::Dimension::Percent(1.0),
5522                        ..Default::default()
5523                    }],
5524                    ..Default::default()
5525                },
5526                stretch::style::Node {
5527                    width: stretch::style::Dimension::Points(100.0),
5528                    ..Default::default()
5529                },
5530            ],
5531            ..Default::default()
5532        });
5533
5534        assert_eq!(layout.width, 350.0);
5535        assert_eq!(layout.height, 100.0);
5536        assert_eq!(layout.x, 0.0);
5537        assert_eq!(layout.y, 0.0);
5538
5539        assert_eq!(layout.children[0].width, 100.0);
5540        assert_eq!(layout.children[0].height, 100.0);
5541        assert_eq!(layout.children[0].x, 0.0);
5542        assert_eq!(layout.children[0].y, 0.0);
5543
5544        assert_eq!(layout.children[1].width, 150.0);
5545        assert_eq!(layout.children[1].height, 100.0);
5546        assert_eq!(layout.children[1].x, 100.0);
5547        assert_eq!(layout.children[1].y, 0.0);
5548
5549        assert_eq!(layout.children[1].children[0].width, 150.0);
5550        assert_eq!(layout.children[1].children[0].height, 0.0);
5551        assert_eq!(layout.children[1].children[0].x, 0.0);
5552        assert_eq!(layout.children[1].children[0].y, 0.0);
5553
5554        assert_eq!(layout.children[2].width, 100.0);
5555        assert_eq!(layout.children[2].height, 100.0);
5556        assert_eq!(layout.children[2].x, 250.0);
5557        assert_eq!(layout.children[2].y, 0.0);
5558    }
5559
5560    #[test]
5561    fn margin_and_stretch_row() {
5562        let layout = stretch::compute(&stretch::style::Node {
5563            width: stretch::style::Dimension::Points(100.0),
5564            height: stretch::style::Dimension::Points(100.0),
5565            children: vec![stretch::style::Node {
5566                flex_grow: 1.0,
5567                margin: stretch::style::Edges {
5568                    top: stretch::style::Dimension::Points(10.0),
5569                    bottom: stretch::style::Dimension::Points(10.0),
5570                    ..Default::default()
5571                },
5572                ..Default::default()
5573            }],
5574            ..Default::default()
5575        });
5576
5577        assert_eq!(layout.width, 100.0);
5578        assert_eq!(layout.height, 100.0);
5579        assert_eq!(layout.x, 0.0);
5580        assert_eq!(layout.y, 0.0);
5581
5582        assert_eq!(layout.children[0].width, 100.0);
5583        assert_eq!(layout.children[0].height, 80.0);
5584        assert_eq!(layout.children[0].x, 0.0);
5585        assert_eq!(layout.children[0].y, 10.0);
5586    }
5587
5588    #[test]
5589    fn margin_top() {
5590        let layout = stretch::compute(&stretch::style::Node {
5591            flex_direction: stretch::style::FlexDirection::Column,
5592            width: stretch::style::Dimension::Points(100.0),
5593            height: stretch::style::Dimension::Points(100.0),
5594            children: vec![stretch::style::Node {
5595                height: stretch::style::Dimension::Points(10.0),
5596                margin: stretch::style::Edges {
5597                    top: stretch::style::Dimension::Points(10.0),
5598                    ..Default::default()
5599                },
5600                ..Default::default()
5601            }],
5602            ..Default::default()
5603        });
5604
5605        assert_eq!(layout.width, 100.0);
5606        assert_eq!(layout.height, 100.0);
5607        assert_eq!(layout.x, 0.0);
5608        assert_eq!(layout.y, 0.0);
5609
5610        assert_eq!(layout.children[0].width, 100.0);
5611        assert_eq!(layout.children[0].height, 10.0);
5612        assert_eq!(layout.children[0].x, 0.0);
5613        assert_eq!(layout.children[0].y, 10.0);
5614    }
5615
5616    #[test]
5617    fn percentage_flex_basis_main_max_height() {
5618        let layout = stretch::compute(&stretch::style::Node {
5619            width: stretch::style::Dimension::Points(200.0),
5620            height: stretch::style::Dimension::Points(200.0),
5621            children: vec![
5622                stretch::style::Node {
5623                    flex_grow: 1.0,
5624                    flex_basis: stretch::style::Dimension::Percent(0.1),
5625                    max_height: stretch::style::Dimension::Percent(0.6),
5626                    ..Default::default()
5627                },
5628                stretch::style::Node {
5629                    flex_grow: 4.0,
5630                    flex_basis: stretch::style::Dimension::Percent(0.1),
5631                    max_height: stretch::style::Dimension::Percent(0.2),
5632                    ..Default::default()
5633                },
5634            ],
5635            ..Default::default()
5636        });
5637
5638        assert_eq!(layout.width, 200.0);
5639        assert_eq!(layout.height, 200.0);
5640        assert_eq!(layout.x, 0.0);
5641        assert_eq!(layout.y, 0.0);
5642
5643        assert_eq!(layout.children[0].width, 52.0);
5644        assert_eq!(layout.children[0].height, 120.0);
5645        assert_eq!(layout.children[0].x, 0.0);
5646        assert_eq!(layout.children[0].y, 0.0);
5647
5648        assert_eq!(layout.children[1].width, 148.0);
5649        assert_eq!(layout.children[1].height, 40.0);
5650        assert_eq!(layout.children[1].x, 52.0);
5651        assert_eq!(layout.children[1].y, 0.0);
5652    }
5653
5654    #[test]
5655    fn margin_auto_left_and_right_column() {
5656        let layout = stretch::compute(&stretch::style::Node {
5657            align_items: stretch::style::AlignItems::Center,
5658            width: stretch::style::Dimension::Points(200.0),
5659            height: stretch::style::Dimension::Points(200.0),
5660            children: vec![
5661                stretch::style::Node {
5662                    width: stretch::style::Dimension::Points(50.0),
5663                    height: stretch::style::Dimension::Points(50.0),
5664                    margin: stretch::style::Edges {
5665                        start: stretch::style::Dimension::Auto,
5666                        end: stretch::style::Dimension::Auto,
5667                        ..Default::default()
5668                    },
5669                    ..Default::default()
5670                },
5671                stretch::style::Node {
5672                    width: stretch::style::Dimension::Points(50.0),
5673                    height: stretch::style::Dimension::Points(50.0),
5674                    ..Default::default()
5675                },
5676            ],
5677            ..Default::default()
5678        });
5679
5680        assert_eq!(layout.width, 200.0);
5681        assert_eq!(layout.height, 200.0);
5682        assert_eq!(layout.x, 0.0);
5683        assert_eq!(layout.y, 0.0);
5684
5685        assert_eq!(layout.children[0].width, 50.0);
5686        assert_eq!(layout.children[0].height, 50.0);
5687        assert_eq!(layout.children[0].x, 50.0);
5688        assert_eq!(layout.children[0].y, 75.0);
5689
5690        assert_eq!(layout.children[1].width, 50.0);
5691        assert_eq!(layout.children[1].height, 50.0);
5692        assert_eq!(layout.children[1].x, 150.0);
5693        assert_eq!(layout.children[1].y, 75.0);
5694    }
5695
5696    #[test]
5697    fn margin_and_flex_row() {
5698        let layout = stretch::compute(&stretch::style::Node {
5699            width: stretch::style::Dimension::Points(100.0),
5700            height: stretch::style::Dimension::Points(100.0),
5701            children: vec![stretch::style::Node {
5702                flex_grow: 1.0,
5703                margin: stretch::style::Edges {
5704                    start: stretch::style::Dimension::Points(10.0),
5705                    end: stretch::style::Dimension::Points(10.0),
5706                    ..Default::default()
5707                },
5708                ..Default::default()
5709            }],
5710            ..Default::default()
5711        });
5712
5713        assert_eq!(layout.width, 100.0);
5714        assert_eq!(layout.height, 100.0);
5715        assert_eq!(layout.x, 0.0);
5716        assert_eq!(layout.y, 0.0);
5717
5718        assert_eq!(layout.children[0].width, 80.0);
5719        assert_eq!(layout.children[0].height, 100.0);
5720        assert_eq!(layout.children[0].x, 10.0);
5721        assert_eq!(layout.children[0].y, 0.0);
5722    }
5723
5724    #[test]
5725    fn flex_wrap_children_with_min_main_overriding_flex_basis() {
5726        let layout = stretch::compute(&stretch::style::Node {
5727            width: stretch::style::Dimension::Points(100.0),
5728            children: vec![
5729                stretch::style::Node {
5730                    flex_basis: stretch::style::Dimension::Points(50.0),
5731                    min_width: stretch::style::Dimension::Points(55.0),
5732                    height: stretch::style::Dimension::Points(50.0),
5733                    ..Default::default()
5734                },
5735                stretch::style::Node {
5736                    flex_basis: stretch::style::Dimension::Points(50.0),
5737                    min_width: stretch::style::Dimension::Points(55.0),
5738                    height: stretch::style::Dimension::Points(50.0),
5739                    ..Default::default()
5740                },
5741            ],
5742            ..Default::default()
5743        });
5744
5745        assert_eq!(layout.width, 100.0);
5746        assert_eq!(layout.height, 100.0);
5747        assert_eq!(layout.x, 0.0);
5748        assert_eq!(layout.y, 0.0);
5749
5750        assert_eq!(layout.children[0].width, 55.0);
5751        assert_eq!(layout.children[0].height, 50.0);
5752        assert_eq!(layout.children[0].x, 0.0);
5753        assert_eq!(layout.children[0].y, 0.0);
5754
5755        assert_eq!(layout.children[1].width, 55.0);
5756        assert_eq!(layout.children[1].height, 50.0);
5757        assert_eq!(layout.children[1].x, 0.0);
5758        assert_eq!(layout.children[1].y, 50.0);
5759    }
5760
5761    #[test]
5762    fn wrap_row_align_items_center() {
5763        let layout = stretch::compute(&stretch::style::Node {
5764            align_items: stretch::style::AlignItems::Center,
5765            width: stretch::style::Dimension::Points(100.0),
5766            children: vec![
5767                stretch::style::Node {
5768                    width: stretch::style::Dimension::Points(30.0),
5769                    height: stretch::style::Dimension::Points(10.0),
5770                    ..Default::default()
5771                },
5772                stretch::style::Node {
5773                    width: stretch::style::Dimension::Points(30.0),
5774                    height: stretch::style::Dimension::Points(20.0),
5775                    ..Default::default()
5776                },
5777                stretch::style::Node {
5778                    width: stretch::style::Dimension::Points(30.0),
5779                    height: stretch::style::Dimension::Points(30.0),
5780                    ..Default::default()
5781                },
5782                stretch::style::Node {
5783                    width: stretch::style::Dimension::Points(30.0),
5784                    height: stretch::style::Dimension::Points(30.0),
5785                    ..Default::default()
5786                },
5787            ],
5788            ..Default::default()
5789        });
5790
5791        assert_eq!(layout.width, 100.0);
5792        assert_eq!(layout.height, 60.0);
5793        assert_eq!(layout.x, 0.0);
5794        assert_eq!(layout.y, 0.0);
5795
5796        assert_eq!(layout.children[0].width, 30.0);
5797        assert_eq!(layout.children[0].height, 10.0);
5798        assert_eq!(layout.children[0].x, 0.0);
5799        assert_eq!(layout.children[0].y, 10.0);
5800
5801        assert_eq!(layout.children[1].width, 30.0);
5802        assert_eq!(layout.children[1].height, 20.0);
5803        assert_eq!(layout.children[1].x, 30.0);
5804        assert_eq!(layout.children[1].y, 5.0);
5805
5806        assert_eq!(layout.children[2].width, 30.0);
5807        assert_eq!(layout.children[2].height, 30.0);
5808        assert_eq!(layout.children[2].x, 60.0);
5809        assert_eq!(layout.children[2].y, 0.0);
5810
5811        assert_eq!(layout.children[3].width, 30.0);
5812        assert_eq!(layout.children[3].height, 30.0);
5813        assert_eq!(layout.children[3].x, 0.0);
5814        assert_eq!(layout.children[3].y, 30.0);
5815    }
5816
5817    #[test]
5818    fn justify_content_colunn_max_height_and_margin() {
5819        let layout = stretch::compute(&stretch::style::Node {
5820            flex_direction: stretch::style::FlexDirection::Column,
5821            justify_content: stretch::style::JustifyContent::Center,
5822            height: stretch::style::Dimension::Points(100.0),
5823            max_height: stretch::style::Dimension::Points(80.0),
5824            margin: stretch::style::Edges {
5825                top: stretch::style::Dimension::Points(100.0),
5826                ..Default::default()
5827            },
5828            children: vec![stretch::style::Node {
5829                width: stretch::style::Dimension::Points(20.0),
5830                height: stretch::style::Dimension::Points(20.0),
5831                ..Default::default()
5832            }],
5833            ..Default::default()
5834        });
5835
5836        assert_eq!(layout.width, 20.0);
5837        assert_eq!(layout.height, 80.0);
5838        assert_eq!(layout.x, 0.0);
5839        assert_eq!(layout.y, 100.0);
5840
5841        assert_eq!(layout.children[0].width, 20.0);
5842        assert_eq!(layout.children[0].height, 20.0);
5843        assert_eq!(layout.children[0].x, 0.0);
5844        assert_eq!(layout.children[0].y, 30.0);
5845    }
5846
5847    #[test]
5848    fn flex_basis_flex_grow_column() {
5849        let layout = stretch::compute(&stretch::style::Node {
5850            flex_direction: stretch::style::FlexDirection::Column,
5851            width: stretch::style::Dimension::Points(100.0),
5852            height: stretch::style::Dimension::Points(100.0),
5853            children: vec![
5854                stretch::style::Node {
5855                    flex_grow: 1.0,
5856                    flex_basis: stretch::style::Dimension::Points(50.0),
5857                    ..Default::default()
5858                },
5859                stretch::style::Node {
5860                    flex_grow: 1.0,
5861                    ..Default::default()
5862                },
5863            ],
5864            ..Default::default()
5865        });
5866
5867        assert_eq!(layout.width, 100.0);
5868        assert_eq!(layout.height, 100.0);
5869        assert_eq!(layout.x, 0.0);
5870        assert_eq!(layout.y, 0.0);
5871
5872        assert_eq!(layout.children[0].width, 100.0);
5873        assert_eq!(layout.children[0].height, 75.0);
5874        assert_eq!(layout.children[0].x, 0.0);
5875        assert_eq!(layout.children[0].y, 0.0);
5876
5877        assert_eq!(layout.children[1].width, 100.0);
5878        assert_eq!(layout.children[1].height, 25.0);
5879        assert_eq!(layout.children[1].x, 0.0);
5880        assert_eq!(layout.children[1].y, 75.0);
5881    }
5882
5883    #[test]
5884    fn absolute_layout_align_items_and_justify_content_center_and_right_position() {
5885        let layout = stretch::compute(&stretch::style::Node {
5886            align_items: stretch::style::AlignItems::Center,
5887            justify_content: stretch::style::JustifyContent::Center,
5888            width: stretch::style::Dimension::Points(110.0),
5889            height: stretch::style::Dimension::Points(100.0),
5890            children: vec![stretch::style::Node {
5891                position: stretch::style::Position::Absolute,
5892                width: stretch::style::Dimension::Points(60.0),
5893                height: stretch::style::Dimension::Points(40.0),
5894                end: stretch::style::Dimension::Points(5.0),
5895                ..Default::default()
5896            }],
5897            ..Default::default()
5898        });
5899
5900        assert_eq!(layout.width, 110.0);
5901        assert_eq!(layout.height, 100.0);
5902        assert_eq!(layout.x, 0.0);
5903        assert_eq!(layout.y, 0.0);
5904
5905        assert_eq!(layout.children[0].width, 60.0);
5906        assert_eq!(layout.children[0].height, 40.0);
5907        assert_eq!(layout.children[0].x, 45.0);
5908        assert_eq!(layout.children[0].y, 30.0);
5909    }
5910
5911    #[test]
5912    fn overflow_cross_axis() {
5913        let layout = stretch::compute(&stretch::style::Node {
5914            width: stretch::style::Dimension::Points(100.0),
5915            height: stretch::style::Dimension::Points(100.0),
5916            children: vec![stretch::style::Node {
5917                width: stretch::style::Dimension::Points(100.0),
5918                height: stretch::style::Dimension::Points(200.0),
5919                ..Default::default()
5920            }],
5921            ..Default::default()
5922        });
5923
5924        assert_eq!(layout.width, 100.0);
5925        assert_eq!(layout.height, 100.0);
5926        assert_eq!(layout.x, 0.0);
5927        assert_eq!(layout.y, 0.0);
5928
5929        assert_eq!(layout.children[0].width, 100.0);
5930        assert_eq!(layout.children[0].height, 200.0);
5931        assert_eq!(layout.children[0].x, 0.0);
5932        assert_eq!(layout.children[0].y, 0.0);
5933    }
5934
5935    #[test]
5936    fn wrap_column() {
5937        let layout = stretch::compute(&stretch::style::Node {
5938            flex_direction: stretch::style::FlexDirection::Column,
5939            height: stretch::style::Dimension::Points(100.0),
5940            children: vec![
5941                stretch::style::Node {
5942                    width: stretch::style::Dimension::Points(30.0),
5943                    height: stretch::style::Dimension::Points(30.0),
5944                    ..Default::default()
5945                },
5946                stretch::style::Node {
5947                    width: stretch::style::Dimension::Points(30.0),
5948                    height: stretch::style::Dimension::Points(30.0),
5949                    ..Default::default()
5950                },
5951                stretch::style::Node {
5952                    width: stretch::style::Dimension::Points(30.0),
5953                    height: stretch::style::Dimension::Points(30.0),
5954                    ..Default::default()
5955                },
5956                stretch::style::Node {
5957                    width: stretch::style::Dimension::Points(30.0),
5958                    height: stretch::style::Dimension::Points(30.0),
5959                    ..Default::default()
5960                },
5961            ],
5962            ..Default::default()
5963        });
5964
5965        assert_eq!(layout.width, 30.0);
5966        assert_eq!(layout.height, 100.0);
5967        assert_eq!(layout.x, 0.0);
5968        assert_eq!(layout.y, 0.0);
5969
5970        assert_eq!(layout.children[0].width, 30.0);
5971        assert_eq!(layout.children[0].height, 30.0);
5972        assert_eq!(layout.children[0].x, 0.0);
5973        assert_eq!(layout.children[0].y, 0.0);
5974
5975        assert_eq!(layout.children[1].width, 30.0);
5976        assert_eq!(layout.children[1].height, 30.0);
5977        assert_eq!(layout.children[1].x, 0.0);
5978        assert_eq!(layout.children[1].y, 30.0);
5979
5980        assert_eq!(layout.children[2].width, 30.0);
5981        assert_eq!(layout.children[2].height, 30.0);
5982        assert_eq!(layout.children[2].x, 0.0);
5983        assert_eq!(layout.children[2].y, 60.0);
5984
5985        assert_eq!(layout.children[3].width, 30.0);
5986        assert_eq!(layout.children[3].height, 30.0);
5987        assert_eq!(layout.children[3].x, 30.0);
5988        assert_eq!(layout.children[3].y, 0.0);
5989    }
5990
5991    #[test]
5992    fn justify_content_column_space_evenly() {
5993        let layout = stretch::compute(&stretch::style::Node {
5994            flex_direction: stretch::style::FlexDirection::Column,
5995            justify_content: stretch::style::JustifyContent::SpaceEvenly,
5996            width: stretch::style::Dimension::Points(100.0),
5997            height: stretch::style::Dimension::Points(100.0),
5998            children: vec![
5999                stretch::style::Node {
6000                    height: stretch::style::Dimension::Points(10.0),
6001                    ..Default::default()
6002                },
6003                stretch::style::Node {
6004                    height: stretch::style::Dimension::Points(10.0),
6005                    ..Default::default()
6006                },
6007                stretch::style::Node {
6008                    height: stretch::style::Dimension::Points(10.0),
6009                    ..Default::default()
6010                },
6011            ],
6012            ..Default::default()
6013        });
6014
6015        assert_eq!(layout.width, 100.0);
6016        assert_eq!(layout.height, 100.0);
6017        assert_eq!(layout.x, 0.0);
6018        assert_eq!(layout.y, 0.0);
6019
6020        assert_eq!(layout.children[0].width, 100.0);
6021        assert_eq!(layout.children[0].height, 10.0);
6022        assert_eq!(layout.children[0].x, 0.0);
6023        assert_eq!(layout.children[0].y, 18.0);
6024
6025        assert_eq!(layout.children[1].width, 100.0);
6026        assert_eq!(layout.children[1].height, 10.0);
6027        assert_eq!(layout.children[1].x, 0.0);
6028        assert_eq!(layout.children[1].y, 45.0);
6029
6030        assert_eq!(layout.children[2].width, 100.0);
6031        assert_eq!(layout.children[2].height, 10.0);
6032        assert_eq!(layout.children[2].x, 0.0);
6033        assert_eq!(layout.children[2].y, 73.0);
6034    }
6035
6036    #[test]
6037    fn flex_grow_within_constrained_max_column() {
6038        let layout = stretch::compute(&stretch::style::Node {
6039            flex_direction: stretch::style::FlexDirection::Column,
6040            width: stretch::style::Dimension::Points(100.0),
6041            max_height: stretch::style::Dimension::Points(100.0),
6042            children: vec![
6043                stretch::style::Node {
6044                    flex_shrink: 1.0,
6045                    flex_basis: stretch::style::Dimension::Points(100.0),
6046                    ..Default::default()
6047                },
6048                stretch::style::Node {
6049                    height: stretch::style::Dimension::Points(50.0),
6050                    ..Default::default()
6051                },
6052            ],
6053            ..Default::default()
6054        });
6055
6056        assert_eq!(layout.width, 100.0);
6057        assert_eq!(layout.height, 100.0);
6058        assert_eq!(layout.x, 0.0);
6059        assert_eq!(layout.y, 0.0);
6060
6061        assert_eq!(layout.children[0].width, 100.0);
6062        assert_eq!(layout.children[0].height, 67.0);
6063        assert_eq!(layout.children[0].x, 0.0);
6064        assert_eq!(layout.children[0].y, 0.0);
6065
6066        assert_eq!(layout.children[1].width, 100.0);
6067        assert_eq!(layout.children[1].height, 33.0);
6068        assert_eq!(layout.children[1].x, 0.0);
6069        assert_eq!(layout.children[1].y, 67.0);
6070    }
6071
6072    #[test]
6073    fn justify_content_column_space_around() {
6074        let layout = stretch::compute(&stretch::style::Node {
6075            flex_direction: stretch::style::FlexDirection::Column,
6076            justify_content: stretch::style::JustifyContent::SpaceAround,
6077            width: stretch::style::Dimension::Points(100.0),
6078            height: stretch::style::Dimension::Points(100.0),
6079            children: vec![
6080                stretch::style::Node {
6081                    height: stretch::style::Dimension::Points(10.0),
6082                    ..Default::default()
6083                },
6084                stretch::style::Node {
6085                    height: stretch::style::Dimension::Points(10.0),
6086                    ..Default::default()
6087                },
6088                stretch::style::Node {
6089                    height: stretch::style::Dimension::Points(10.0),
6090                    ..Default::default()
6091                },
6092            ],
6093            ..Default::default()
6094        });
6095
6096        assert_eq!(layout.width, 100.0);
6097        assert_eq!(layout.height, 100.0);
6098        assert_eq!(layout.x, 0.0);
6099        assert_eq!(layout.y, 0.0);
6100
6101        assert_eq!(layout.children[0].width, 100.0);
6102        assert_eq!(layout.children[0].height, 10.0);
6103        assert_eq!(layout.children[0].x, 0.0);
6104        assert_eq!(layout.children[0].y, 12.0);
6105
6106        assert_eq!(layout.children[1].width, 100.0);
6107        assert_eq!(layout.children[1].height, 10.0);
6108        assert_eq!(layout.children[1].x, 0.0);
6109        assert_eq!(layout.children[1].y, 45.0);
6110
6111        assert_eq!(layout.children[2].width, 100.0);
6112        assert_eq!(layout.children[2].height, 10.0);
6113        assert_eq!(layout.children[2].x, 0.0);
6114        assert_eq!(layout.children[2].y, 78.0);
6115    }
6116
6117    #[test]
6118    fn absolute_layout_align_items_and_justify_content_center_and_left_position() {
6119        let layout = stretch::compute(&stretch::style::Node {
6120            align_items: stretch::style::AlignItems::Center,
6121            justify_content: stretch::style::JustifyContent::Center,
6122            width: stretch::style::Dimension::Points(110.0),
6123            height: stretch::style::Dimension::Points(100.0),
6124            children: vec![stretch::style::Node {
6125                position: stretch::style::Position::Absolute,
6126                width: stretch::style::Dimension::Points(60.0),
6127                height: stretch::style::Dimension::Points(40.0),
6128                start: stretch::style::Dimension::Points(5.0),
6129                ..Default::default()
6130            }],
6131            ..Default::default()
6132        });
6133
6134        assert_eq!(layout.width, 110.0);
6135        assert_eq!(layout.height, 100.0);
6136        assert_eq!(layout.x, 0.0);
6137        assert_eq!(layout.y, 0.0);
6138
6139        assert_eq!(layout.children[0].width, 60.0);
6140        assert_eq!(layout.children[0].height, 40.0);
6141        assert_eq!(layout.children[0].x, 5.0);
6142        assert_eq!(layout.children[0].y, 30.0);
6143    }
6144
6145    #[test]
6146    fn percentage_flex_basis_main_min_width() {
6147        let layout = stretch::compute(&stretch::style::Node {
6148            width: stretch::style::Dimension::Points(200.0),
6149            height: stretch::style::Dimension::Points(200.0),
6150            children: vec![
6151                stretch::style::Node {
6152                    flex_grow: 1.0,
6153                    flex_basis: stretch::style::Dimension::Percent(0.2),
6154                    min_width: stretch::style::Dimension::Percent(0.6),
6155                    ..Default::default()
6156                },
6157                stretch::style::Node {
6158                    flex_grow: 4.0,
6159                    flex_basis: stretch::style::Dimension::Percent(0.1),
6160                    min_width: stretch::style::Dimension::Percent(0.2),
6161                    ..Default::default()
6162                },
6163            ],
6164            ..Default::default()
6165        });
6166
6167        assert_eq!(layout.width, 200.0);
6168        assert_eq!(layout.height, 200.0);
6169        assert_eq!(layout.x, 0.0);
6170        assert_eq!(layout.y, 0.0);
6171
6172        assert_eq!(layout.children[0].width, 120.0);
6173        assert_eq!(layout.children[0].height, 200.0);
6174        assert_eq!(layout.children[0].x, 0.0);
6175        assert_eq!(layout.children[0].y, 0.0);
6176
6177        assert_eq!(layout.children[1].width, 80.0);
6178        assert_eq!(layout.children[1].height, 200.0);
6179        assert_eq!(layout.children[1].x, 120.0);
6180        assert_eq!(layout.children[1].y, 0.0);
6181    }
6182
6183    #[test]
6184    fn margin_auto_bottom() {
6185        let layout = stretch::compute(&stretch::style::Node {
6186            align_items: stretch::style::AlignItems::Center,
6187            width: stretch::style::Dimension::Points(200.0),
6188            height: stretch::style::Dimension::Points(200.0),
6189            children: vec![
6190                stretch::style::Node {
6191                    width: stretch::style::Dimension::Points(50.0),
6192                    height: stretch::style::Dimension::Points(50.0),
6193                    margin: stretch::style::Edges {
6194                        bottom: stretch::style::Dimension::Auto,
6195                        ..Default::default()
6196                    },
6197                    ..Default::default()
6198                },
6199                stretch::style::Node {
6200                    width: stretch::style::Dimension::Points(50.0),
6201                    height: stretch::style::Dimension::Points(50.0),
6202                    ..Default::default()
6203                },
6204            ],
6205            ..Default::default()
6206        });
6207
6208        assert_eq!(layout.width, 200.0);
6209        assert_eq!(layout.height, 200.0);
6210        assert_eq!(layout.x, 0.0);
6211        assert_eq!(layout.y, 0.0);
6212
6213        assert_eq!(layout.children[0].width, 50.0);
6214        assert_eq!(layout.children[0].height, 50.0);
6215        assert_eq!(layout.children[0].x, 0.0);
6216        assert_eq!(layout.children[0].y, 0.0);
6217
6218        assert_eq!(layout.children[1].width, 50.0);
6219        assert_eq!(layout.children[1].height, 50.0);
6220        assert_eq!(layout.children[1].x, 50.0);
6221        assert_eq!(layout.children[1].y, 75.0);
6222    }
6223
6224    #[test]
6225    fn flex_grow_shrink_at_most() {
6226        let layout = stretch::compute(&stretch::style::Node {
6227            width: stretch::style::Dimension::Points(100.0),
6228            height: stretch::style::Dimension::Points(100.0),
6229            children: vec![stretch::style::Node {
6230                children: vec![stretch::style::Node {
6231                    flex_grow: 1.0,
6232                    flex_shrink: 1.0,
6233                    ..Default::default()
6234                }],
6235                ..Default::default()
6236            }],
6237            ..Default::default()
6238        });
6239
6240        assert_eq!(layout.width, 100.0);
6241        assert_eq!(layout.height, 100.0);
6242        assert_eq!(layout.x, 0.0);
6243        assert_eq!(layout.y, 0.0);
6244
6245        assert_eq!(layout.children[0].width, 0.0);
6246        assert_eq!(layout.children[0].height, 100.0);
6247        assert_eq!(layout.children[0].x, 0.0);
6248        assert_eq!(layout.children[0].y, 0.0);
6249
6250        assert_eq!(layout.children[0].children[0].width, 0.0);
6251        assert_eq!(layout.children[0].children[0].height, 100.0);
6252        assert_eq!(layout.children[0].children[0].x, 0.0);
6253        assert_eq!(layout.children[0].children[0].y, 0.0);
6254    }
6255
6256    #[test]
6257    fn percentage_padding_should_calculate_based_only_on_width() {
6258        let layout = stretch::compute(&stretch::style::Node {
6259            flex_direction: stretch::style::FlexDirection::Column,
6260            width: stretch::style::Dimension::Points(200.0),
6261            height: stretch::style::Dimension::Points(100.0),
6262            children: vec![stretch::style::Node {
6263                flex_direction: stretch::style::FlexDirection::Column,
6264                flex_grow: 1.0,
6265                padding: stretch::style::Edges {
6266                    start: stretch::style::Dimension::Percent(0.1),
6267                    end: stretch::style::Dimension::Percent(0.1),
6268                    top: stretch::style::Dimension::Percent(0.1),
6269                    bottom: stretch::style::Dimension::Percent(0.1),
6270                    ..Default::default()
6271                },
6272                children: vec![stretch::style::Node {
6273                    width: stretch::style::Dimension::Points(10.0),
6274                    height: stretch::style::Dimension::Points(10.0),
6275                    ..Default::default()
6276                }],
6277                ..Default::default()
6278            }],
6279            ..Default::default()
6280        });
6281
6282        assert_eq!(layout.width, 200.0);
6283        assert_eq!(layout.height, 100.0);
6284        assert_eq!(layout.x, 0.0);
6285        assert_eq!(layout.y, 0.0);
6286
6287        assert_eq!(layout.children[0].width, 200.0);
6288        assert_eq!(layout.children[0].height, 100.0);
6289        assert_eq!(layout.children[0].x, 0.0);
6290        assert_eq!(layout.children[0].y, 0.0);
6291
6292        assert_eq!(layout.children[0].children[0].width, 10.0);
6293        assert_eq!(layout.children[0].children[0].height, 10.0);
6294        assert_eq!(layout.children[0].children[0].x, 20.0);
6295        assert_eq!(layout.children[0].children[0].y, 20.0);
6296    }
6297
6298    #[test]
6299    fn flex_shrink_to_zero() {
6300        let layout = stretch::compute(&stretch::style::Node {
6301            width: stretch::style::Dimension::Points(75.0),
6302            children: vec![
6303                stretch::style::Node {
6304                    flex_shrink: 0.0,
6305                    width: stretch::style::Dimension::Points(50.0),
6306                    height: stretch::style::Dimension::Points(50.0),
6307                    ..Default::default()
6308                },
6309                stretch::style::Node {
6310                    flex_shrink: 1.0,
6311                    width: stretch::style::Dimension::Points(50.0),
6312                    height: stretch::style::Dimension::Points(50.0),
6313                    ..Default::default()
6314                },
6315                stretch::style::Node {
6316                    flex_shrink: 0.0,
6317                    width: stretch::style::Dimension::Points(50.0),
6318                    height: stretch::style::Dimension::Points(50.0),
6319                    ..Default::default()
6320                },
6321            ],
6322            ..Default::default()
6323        });
6324
6325        assert_eq!(layout.width, 75.0);
6326        assert_eq!(layout.height, 50.0);
6327        assert_eq!(layout.x, 0.0);
6328        assert_eq!(layout.y, 0.0);
6329
6330        assert_eq!(layout.children[0].width, 50.0);
6331        assert_eq!(layout.children[0].height, 50.0);
6332        assert_eq!(layout.children[0].x, 0.0);
6333        assert_eq!(layout.children[0].y, 0.0);
6334
6335        assert_eq!(layout.children[1].width, 0.0);
6336        assert_eq!(layout.children[1].height, 50.0);
6337        assert_eq!(layout.children[1].x, 50.0);
6338        assert_eq!(layout.children[1].y, 0.0);
6339
6340        assert_eq!(layout.children[2].width, 50.0);
6341        assert_eq!(layout.children[2].height, 50.0);
6342        assert_eq!(layout.children[2].x, 50.0);
6343        assert_eq!(layout.children[2].y, 0.0);
6344    }
6345
6346    #[test]
6347    fn margin_auto_mutiple_children_row() {
6348        let layout = stretch::compute(&stretch::style::Node {
6349            align_items: stretch::style::AlignItems::Center,
6350            width: stretch::style::Dimension::Points(200.0),
6351            height: stretch::style::Dimension::Points(200.0),
6352            children: vec![
6353                stretch::style::Node {
6354                    width: stretch::style::Dimension::Points(50.0),
6355                    height: stretch::style::Dimension::Points(50.0),
6356                    margin: stretch::style::Edges {
6357                        end: stretch::style::Dimension::Auto,
6358                        ..Default::default()
6359                    },
6360                    ..Default::default()
6361                },
6362                stretch::style::Node {
6363                    width: stretch::style::Dimension::Points(50.0),
6364                    height: stretch::style::Dimension::Points(50.0),
6365                    margin: stretch::style::Edges {
6366                        end: stretch::style::Dimension::Auto,
6367                        ..Default::default()
6368                    },
6369                    ..Default::default()
6370                },
6371                stretch::style::Node {
6372                    width: stretch::style::Dimension::Points(50.0),
6373                    height: stretch::style::Dimension::Points(50.0),
6374                    ..Default::default()
6375                },
6376            ],
6377            ..Default::default()
6378        });
6379
6380        assert_eq!(layout.width, 200.0);
6381        assert_eq!(layout.height, 200.0);
6382        assert_eq!(layout.x, 0.0);
6383        assert_eq!(layout.y, 0.0);
6384
6385        assert_eq!(layout.children[0].width, 50.0);
6386        assert_eq!(layout.children[0].height, 50.0);
6387        assert_eq!(layout.children[0].x, 0.0);
6388        assert_eq!(layout.children[0].y, 75.0);
6389
6390        assert_eq!(layout.children[1].width, 50.0);
6391        assert_eq!(layout.children[1].height, 50.0);
6392        assert_eq!(layout.children[1].x, 75.0);
6393        assert_eq!(layout.children[1].y, 75.0);
6394
6395        assert_eq!(layout.children[2].width, 50.0);
6396        assert_eq!(layout.children[2].height, 50.0);
6397        assert_eq!(layout.children[2].x, 150.0);
6398        assert_eq!(layout.children[2].y, 75.0);
6399    }
6400
6401    #[test]
6402    fn justify_content_min_width_with_padding_child_width_lower_than_parent() {
6403        let layout = stretch::compute(&stretch::style::Node {
6404            flex_direction: stretch::style::FlexDirection::Column,
6405            width: stretch::style::Dimension::Points(1080.0),
6406            height: stretch::style::Dimension::Points(1584.0),
6407            children: vec![stretch::style::Node {
6408                children: vec![stretch::style::Node {
6409                    justify_content: stretch::style::JustifyContent::Center,
6410                    min_width: stretch::style::Dimension::Points(400.0),
6411                    padding: stretch::style::Edges {
6412                        start: stretch::style::Dimension::Points(100.0),
6413                        end: stretch::style::Dimension::Points(100.0),
6414                        ..Default::default()
6415                    },
6416                    children: vec![stretch::style::Node {
6417                        width: stretch::style::Dimension::Points(199.0),
6418                        height: stretch::style::Dimension::Points(100.0),
6419                        ..Default::default()
6420                    }],
6421                    ..Default::default()
6422                }],
6423                ..Default::default()
6424            }],
6425            ..Default::default()
6426        });
6427
6428        assert_eq!(layout.width, 1080.0);
6429        assert_eq!(layout.height, 1584.0);
6430        assert_eq!(layout.x, 0.0);
6431        assert_eq!(layout.y, 0.0);
6432
6433        assert_eq!(layout.children[0].width, 1080.0);
6434        assert_eq!(layout.children[0].height, 100.0);
6435        assert_eq!(layout.children[0].x, 0.0);
6436        assert_eq!(layout.children[0].y, 0.0);
6437
6438        assert_eq!(layout.children[0].children[0].width, 400.0);
6439        assert_eq!(layout.children[0].children[0].height, 100.0);
6440        assert_eq!(layout.children[0].children[0].x, 0.0);
6441        assert_eq!(layout.children[0].children[0].y, 0.0);
6442
6443        assert_eq!(layout.children[0].children[0].children[0].width, 199.0);
6444        assert_eq!(layout.children[0].children[0].children[0].height, 100.0);
6445        assert_eq!(layout.children[0].children[0].children[0].x, 101.0);
6446        assert_eq!(layout.children[0].children[0].children[0].y, 0.0);
6447    }
6448
6449    #[test]
6450    fn size_defined_by_grand_child() {
6451        let layout = stretch::compute(&stretch::style::Node {
6452            children: vec![stretch::style::Node {
6453                children: vec![stretch::style::Node {
6454                    width: stretch::style::Dimension::Points(100.0),
6455                    height: stretch::style::Dimension::Points(100.0),
6456                    ..Default::default()
6457                }],
6458                ..Default::default()
6459            }],
6460            ..Default::default()
6461        });
6462
6463        assert_eq!(layout.width, 100.0);
6464        assert_eq!(layout.height, 100.0);
6465        assert_eq!(layout.x, 0.0);
6466        assert_eq!(layout.y, 0.0);
6467
6468        assert_eq!(layout.children[0].width, 100.0);
6469        assert_eq!(layout.children[0].height, 100.0);
6470        assert_eq!(layout.children[0].x, 0.0);
6471        assert_eq!(layout.children[0].y, 0.0);
6472
6473        assert_eq!(layout.children[0].children[0].width, 100.0);
6474        assert_eq!(layout.children[0].children[0].height, 100.0);
6475        assert_eq!(layout.children[0].children[0].x, 0.0);
6476        assert_eq!(layout.children[0].children[0].y, 0.0);
6477    }
6478
6479    #[test]
6480    fn absolute_layout_align_items_and_justify_content_center_and_bottom_position() {
6481        let layout = stretch::compute(&stretch::style::Node {
6482            align_items: stretch::style::AlignItems::Center,
6483            justify_content: stretch::style::JustifyContent::Center,
6484            width: stretch::style::Dimension::Points(110.0),
6485            height: stretch::style::Dimension::Points(100.0),
6486            children: vec![stretch::style::Node {
6487                position: stretch::style::Position::Absolute,
6488                width: stretch::style::Dimension::Points(60.0),
6489                height: stretch::style::Dimension::Points(40.0),
6490                bottom: stretch::style::Dimension::Points(10.0),
6491                ..Default::default()
6492            }],
6493            ..Default::default()
6494        });
6495
6496        assert_eq!(layout.width, 110.0);
6497        assert_eq!(layout.height, 100.0);
6498        assert_eq!(layout.x, 0.0);
6499        assert_eq!(layout.y, 0.0);
6500
6501        assert_eq!(layout.children[0].width, 60.0);
6502        assert_eq!(layout.children[0].height, 40.0);
6503        assert_eq!(layout.children[0].x, 25.0);
6504        assert_eq!(layout.children[0].y, 50.0);
6505    }
6506
6507    #[test]
6508    fn justify_content_min_max() {
6509        let layout = stretch::compute(&stretch::style::Node {
6510            flex_direction: stretch::style::FlexDirection::Column,
6511            justify_content: stretch::style::JustifyContent::Center,
6512            width: stretch::style::Dimension::Points(100.0),
6513            min_height: stretch::style::Dimension::Points(100.0),
6514            max_height: stretch::style::Dimension::Points(200.0),
6515            children: vec![stretch::style::Node {
6516                width: stretch::style::Dimension::Points(60.0),
6517                height: stretch::style::Dimension::Points(60.0),
6518                ..Default::default()
6519            }],
6520            ..Default::default()
6521        });
6522
6523        assert_eq!(layout.width, 100.0);
6524        assert_eq!(layout.height, 100.0);
6525        assert_eq!(layout.x, 0.0);
6526        assert_eq!(layout.y, 0.0);
6527
6528        assert_eq!(layout.children[0].width, 60.0);
6529        assert_eq!(layout.children[0].height, 60.0);
6530        assert_eq!(layout.children[0].x, 0.0);
6531        assert_eq!(layout.children[0].y, 20.0);
6532    }
6533
6534    #[test]
6535    fn padding_align_end_child() {
6536        let layout = stretch::compute(&stretch::style::Node {
6537            align_items: stretch::style::AlignItems::FlexEnd,
6538            justify_content: stretch::style::JustifyContent::FlexEnd,
6539            width: stretch::style::Dimension::Points(200.0),
6540            height: stretch::style::Dimension::Points(200.0),
6541            children: vec![stretch::style::Node {
6542                width: stretch::style::Dimension::Points(100.0),
6543                height: stretch::style::Dimension::Points(100.0),
6544                padding: stretch::style::Edges {
6545                    start: stretch::style::Dimension::Points(20.0),
6546                    end: stretch::style::Dimension::Points(20.0),
6547                    top: stretch::style::Dimension::Points(20.0),
6548                    bottom: stretch::style::Dimension::Points(20.0),
6549                    ..Default::default()
6550                },
6551                ..Default::default()
6552            }],
6553            ..Default::default()
6554        });
6555
6556        assert_eq!(layout.width, 200.0);
6557        assert_eq!(layout.height, 200.0);
6558        assert_eq!(layout.x, 0.0);
6559        assert_eq!(layout.y, 0.0);
6560
6561        assert_eq!(layout.children[0].width, 100.0);
6562        assert_eq!(layout.children[0].height, 100.0);
6563        assert_eq!(layout.children[0].x, 100.0);
6564        assert_eq!(layout.children[0].y, 100.0);
6565    }
6566
6567    #[test]
6568    fn justify_content_row_space_between() {
6569        let layout = stretch::compute(&stretch::style::Node {
6570            justify_content: stretch::style::JustifyContent::SpaceBetween,
6571            width: stretch::style::Dimension::Points(100.0),
6572            height: stretch::style::Dimension::Points(100.0),
6573            children: vec![
6574                stretch::style::Node {
6575                    width: stretch::style::Dimension::Points(10.0),
6576                    ..Default::default()
6577                },
6578                stretch::style::Node {
6579                    width: stretch::style::Dimension::Points(10.0),
6580                    ..Default::default()
6581                },
6582                stretch::style::Node {
6583                    width: stretch::style::Dimension::Points(10.0),
6584                    ..Default::default()
6585                },
6586            ],
6587            ..Default::default()
6588        });
6589
6590        assert_eq!(layout.width, 100.0);
6591        assert_eq!(layout.height, 100.0);
6592        assert_eq!(layout.x, 0.0);
6593        assert_eq!(layout.y, 0.0);
6594
6595        assert_eq!(layout.children[0].width, 10.0);
6596        assert_eq!(layout.children[0].height, 100.0);
6597        assert_eq!(layout.children[0].x, 0.0);
6598        assert_eq!(layout.children[0].y, 0.0);
6599
6600        assert_eq!(layout.children[1].width, 10.0);
6601        assert_eq!(layout.children[1].height, 100.0);
6602        assert_eq!(layout.children[1].x, 45.0);
6603        assert_eq!(layout.children[1].y, 0.0);
6604
6605        assert_eq!(layout.children[2].width, 10.0);
6606        assert_eq!(layout.children[2].height, 100.0);
6607        assert_eq!(layout.children[2].x, 90.0);
6608        assert_eq!(layout.children[2].y, 0.0);
6609    }
6610
6611    #[test]
6612    fn align_self_baseline() {
6613        let layout = stretch::compute(&stretch::style::Node {
6614            width: stretch::style::Dimension::Points(100.0),
6615            height: stretch::style::Dimension::Points(100.0),
6616            children: vec![
6617                stretch::style::Node {
6618                    align_self: stretch::style::AlignSelf::Baseline,
6619                    width: stretch::style::Dimension::Points(50.0),
6620                    height: stretch::style::Dimension::Points(50.0),
6621                    ..Default::default()
6622                },
6623                stretch::style::Node {
6624                    align_self: stretch::style::AlignSelf::Baseline,
6625                    width: stretch::style::Dimension::Points(50.0),
6626                    height: stretch::style::Dimension::Points(20.0),
6627                    children: vec![stretch::style::Node {
6628                        width: stretch::style::Dimension::Points(50.0),
6629                        height: stretch::style::Dimension::Points(10.0),
6630                        ..Default::default()
6631                    }],
6632                    ..Default::default()
6633                },
6634            ],
6635            ..Default::default()
6636        });
6637
6638        assert_eq!(layout.width, 100.0);
6639        assert_eq!(layout.height, 100.0);
6640        assert_eq!(layout.x, 0.0);
6641        assert_eq!(layout.y, 0.0);
6642
6643        assert_eq!(layout.children[0].width, 50.0);
6644        assert_eq!(layout.children[0].height, 50.0);
6645        assert_eq!(layout.children[0].x, 0.0);
6646        assert_eq!(layout.children[0].y, 0.0);
6647
6648        assert_eq!(layout.children[1].width, 50.0);
6649        assert_eq!(layout.children[1].height, 20.0);
6650        assert_eq!(layout.children[1].x, 50.0);
6651        assert_eq!(layout.children[1].y, 40.0);
6652
6653        assert_eq!(layout.children[1].children[0].width, 50.0);
6654        assert_eq!(layout.children[1].children[0].height, 10.0);
6655        assert_eq!(layout.children[1].children[0].x, 0.0);
6656        assert_eq!(layout.children[1].children[0].y, 0.0);
6657    }
6658
6659    #[test]
6660    fn rounding_fractial_input_1() {
6661        let layout = stretch::compute(&stretch::style::Node {
6662            flex_direction: stretch::style::FlexDirection::Column,
6663            width: stretch::style::Dimension::Points(100.0),
6664            height: stretch::style::Dimension::Points(113.4),
6665            children: vec![
6666                stretch::style::Node {
6667                    flex_grow: 1.0,
6668                    flex_basis: stretch::style::Dimension::Points(50.0),
6669                    height: stretch::style::Dimension::Points(20.0),
6670                    ..Default::default()
6671                },
6672                stretch::style::Node {
6673                    flex_grow: 1.0,
6674                    height: stretch::style::Dimension::Points(10.0),
6675                    ..Default::default()
6676                },
6677                stretch::style::Node {
6678                    flex_grow: 1.0,
6679                    height: stretch::style::Dimension::Points(10.0),
6680                    ..Default::default()
6681                },
6682            ],
6683            ..Default::default()
6684        });
6685
6686        assert_eq!(layout.width, 100.0);
6687        assert_eq!(layout.height, 113.0);
6688        assert_eq!(layout.x, 0.0);
6689        assert_eq!(layout.y, 0.0);
6690
6691        assert_eq!(layout.children[0].width, 100.0);
6692        assert_eq!(layout.children[0].height, 64.0);
6693        assert_eq!(layout.children[0].x, 0.0);
6694        assert_eq!(layout.children[0].y, 0.0);
6695
6696        assert_eq!(layout.children[1].width, 100.0);
6697        assert_eq!(layout.children[1].height, 25.0);
6698        assert_eq!(layout.children[1].x, 0.0);
6699        assert_eq!(layout.children[1].y, 64.0);
6700
6701        assert_eq!(layout.children[2].width, 100.0);
6702        assert_eq!(layout.children[2].height, 24.0);
6703        assert_eq!(layout.children[2].x, 0.0);
6704        assert_eq!(layout.children[2].y, 89.0);
6705    }
6706
6707    #[test]
6708    fn absolute_layout_align_items_center() {
6709        let layout = stretch::compute(&stretch::style::Node {
6710            align_items: stretch::style::AlignItems::Center,
6711            width: stretch::style::Dimension::Points(110.0),
6712            height: stretch::style::Dimension::Points(100.0),
6713            children: vec![stretch::style::Node {
6714                position: stretch::style::Position::Absolute,
6715                width: stretch::style::Dimension::Points(60.0),
6716                height: stretch::style::Dimension::Points(40.0),
6717                ..Default::default()
6718            }],
6719            ..Default::default()
6720        });
6721
6722        assert_eq!(layout.width, 110.0);
6723        assert_eq!(layout.height, 100.0);
6724        assert_eq!(layout.x, 0.0);
6725        assert_eq!(layout.y, 0.0);
6726
6727        assert_eq!(layout.children[0].width, 60.0);
6728        assert_eq!(layout.children[0].height, 40.0);
6729        assert_eq!(layout.children[0].x, 0.0);
6730        assert_eq!(layout.children[0].y, 30.0);
6731    }
6732
6733    #[test]
6734    fn percentage_flex_basis_cross_min_width() {
6735        let layout = stretch::compute(&stretch::style::Node {
6736            flex_direction: stretch::style::FlexDirection::Column,
6737            width: stretch::style::Dimension::Points(200.0),
6738            height: stretch::style::Dimension::Points(200.0),
6739            children: vec![
6740                stretch::style::Node {
6741                    flex_grow: 1.0,
6742                    flex_basis: stretch::style::Dimension::Percent(0.1),
6743                    min_width: stretch::style::Dimension::Percent(0.6),
6744                    ..Default::default()
6745                },
6746                stretch::style::Node {
6747                    flex_grow: 4.0,
6748                    flex_basis: stretch::style::Dimension::Percent(0.2),
6749                    min_width: stretch::style::Dimension::Percent(0.2),
6750                    ..Default::default()
6751                },
6752            ],
6753            ..Default::default()
6754        });
6755
6756        assert_eq!(layout.width, 200.0);
6757        assert_eq!(layout.height, 200.0);
6758        assert_eq!(layout.x, 0.0);
6759        assert_eq!(layout.y, 0.0);
6760
6761        assert_eq!(layout.children[0].width, 200.0);
6762        assert_eq!(layout.children[0].height, 50.0);
6763        assert_eq!(layout.children[0].x, 0.0);
6764        assert_eq!(layout.children[0].y, 0.0);
6765
6766        assert_eq!(layout.children[1].width, 200.0);
6767        assert_eq!(layout.children[1].height, 150.0);
6768        assert_eq!(layout.children[1].x, 0.0);
6769        assert_eq!(layout.children[1].y, 50.0);
6770    }
6771
6772    #[test]
6773    fn margin_auto_left_and_right_column_and_center() {
6774        let layout = stretch::compute(&stretch::style::Node {
6775            align_items: stretch::style::AlignItems::Center,
6776            width: stretch::style::Dimension::Points(200.0),
6777            height: stretch::style::Dimension::Points(200.0),
6778            children: vec![
6779                stretch::style::Node {
6780                    width: stretch::style::Dimension::Points(50.0),
6781                    height: stretch::style::Dimension::Points(50.0),
6782                    margin: stretch::style::Edges {
6783                        start: stretch::style::Dimension::Auto,
6784                        end: stretch::style::Dimension::Auto,
6785                        ..Default::default()
6786                    },
6787                    ..Default::default()
6788                },
6789                stretch::style::Node {
6790                    width: stretch::style::Dimension::Points(50.0),
6791                    height: stretch::style::Dimension::Points(50.0),
6792                    ..Default::default()
6793                },
6794            ],
6795            ..Default::default()
6796        });
6797
6798        assert_eq!(layout.width, 200.0);
6799        assert_eq!(layout.height, 200.0);
6800        assert_eq!(layout.x, 0.0);
6801        assert_eq!(layout.y, 0.0);
6802
6803        assert_eq!(layout.children[0].width, 50.0);
6804        assert_eq!(layout.children[0].height, 50.0);
6805        assert_eq!(layout.children[0].x, 50.0);
6806        assert_eq!(layout.children[0].y, 75.0);
6807
6808        assert_eq!(layout.children[1].width, 50.0);
6809        assert_eq!(layout.children[1].height, 50.0);
6810        assert_eq!(layout.children[1].x, 150.0);
6811        assert_eq!(layout.children[1].y, 75.0);
6812    }
6813
6814    #[test]
6815    fn flex_grow_less_than_factor_one() {
6816        let layout = stretch::compute(&stretch::style::Node {
6817            width: stretch::style::Dimension::Points(500.0),
6818            height: stretch::style::Dimension::Points(200.0),
6819            children: vec![
6820                stretch::style::Node {
6821                    flex_grow: 0.2,
6822                    flex_shrink: 0.0,
6823                    flex_basis: stretch::style::Dimension::Points(40.0),
6824                    ..Default::default()
6825                },
6826                stretch::style::Node {
6827                    flex_grow: 0.2,
6828                    flex_shrink: 0.0,
6829                    ..Default::default()
6830                },
6831                stretch::style::Node {
6832                    flex_grow: 0.4,
6833                    flex_shrink: 0.0,
6834                    ..Default::default()
6835                },
6836            ],
6837            ..Default::default()
6838        });
6839
6840        assert_eq!(layout.width, 500.0);
6841        assert_eq!(layout.height, 200.0);
6842        assert_eq!(layout.x, 0.0);
6843        assert_eq!(layout.y, 0.0);
6844
6845        assert_eq!(layout.children[0].width, 132.0);
6846        assert_eq!(layout.children[0].height, 200.0);
6847        assert_eq!(layout.children[0].x, 0.0);
6848        assert_eq!(layout.children[0].y, 0.0);
6849
6850        assert_eq!(layout.children[1].width, 92.0);
6851        assert_eq!(layout.children[1].height, 200.0);
6852        assert_eq!(layout.children[1].x, 132.0);
6853        assert_eq!(layout.children[1].y, 0.0);
6854
6855        assert_eq!(layout.children[2].width, 184.0);
6856        assert_eq!(layout.children[2].height, 200.0);
6857        assert_eq!(layout.children[2].x, 224.0);
6858        assert_eq!(layout.children[2].y, 0.0);
6859    }
6860
6861    #[test]
6862    fn flex_grow_within_constrained_min_max_column() {
6863        let layout = stretch::compute(&stretch::style::Node {
6864            min_height: stretch::style::Dimension::Points(100.0),
6865            children: vec![
6866                stretch::style::Node {
6867                    flex_grow: 1.0,
6868                    ..Default::default()
6869                },
6870                stretch::style::Node {
6871                    height: stretch::style::Dimension::Points(50.0),
6872                    ..Default::default()
6873                },
6874            ],
6875            ..Default::default()
6876        });
6877
6878        assert_eq!(layout.width, 0.0);
6879        assert_eq!(layout.height, 100.0);
6880        assert_eq!(layout.x, 0.0);
6881        assert_eq!(layout.y, 0.0);
6882
6883        assert_eq!(layout.children[0].width, 0.0);
6884        assert_eq!(layout.children[0].height, 100.0);
6885        assert_eq!(layout.children[0].x, 0.0);
6886        assert_eq!(layout.children[0].y, 0.0);
6887
6888        assert_eq!(layout.children[1].width, 0.0);
6889        assert_eq!(layout.children[1].height, 50.0);
6890        assert_eq!(layout.children[1].x, 0.0);
6891        assert_eq!(layout.children[1].y, 0.0);
6892    }
6893
6894    #[test]
6895    fn percentage_flex_basis_cross_max_height() {
6896        let layout = stretch::compute(&stretch::style::Node {
6897            flex_direction: stretch::style::FlexDirection::Column,
6898            width: stretch::style::Dimension::Points(200.0),
6899            height: stretch::style::Dimension::Points(200.0),
6900            children: vec![
6901                stretch::style::Node {
6902                    flex_grow: 1.0,
6903                    flex_basis: stretch::style::Dimension::Percent(0.1),
6904                    max_height: stretch::style::Dimension::Percent(0.6),
6905                    ..Default::default()
6906                },
6907                stretch::style::Node {
6908                    flex_grow: 4.0,
6909                    flex_basis: stretch::style::Dimension::Percent(0.1),
6910                    max_height: stretch::style::Dimension::Percent(0.2),
6911                    ..Default::default()
6912                },
6913            ],
6914            ..Default::default()
6915        });
6916
6917        assert_eq!(layout.width, 200.0);
6918        assert_eq!(layout.height, 200.0);
6919        assert_eq!(layout.x, 0.0);
6920        assert_eq!(layout.y, 0.0);
6921
6922        assert_eq!(layout.children[0].width, 200.0);
6923        assert_eq!(layout.children[0].height, 120.0);
6924        assert_eq!(layout.children[0].x, 0.0);
6925        assert_eq!(layout.children[0].y, 0.0);
6926
6927        assert_eq!(layout.children[1].width, 200.0);
6928        assert_eq!(layout.children[1].height, 40.0);
6929        assert_eq!(layout.children[1].x, 0.0);
6930        assert_eq!(layout.children[1].y, 120.0);
6931    }
6932
6933    #[test]
6934    fn justify_content_column_flex_end() {
6935        let layout = stretch::compute(&stretch::style::Node {
6936            flex_direction: stretch::style::FlexDirection::Column,
6937            justify_content: stretch::style::JustifyContent::FlexEnd,
6938            width: stretch::style::Dimension::Points(100.0),
6939            height: stretch::style::Dimension::Points(100.0),
6940            children: vec![
6941                stretch::style::Node {
6942                    height: stretch::style::Dimension::Points(10.0),
6943                    ..Default::default()
6944                },
6945                stretch::style::Node {
6946                    height: stretch::style::Dimension::Points(10.0),
6947                    ..Default::default()
6948                },
6949                stretch::style::Node {
6950                    height: stretch::style::Dimension::Points(10.0),
6951                    ..Default::default()
6952                },
6953            ],
6954            ..Default::default()
6955        });
6956
6957        assert_eq!(layout.width, 100.0);
6958        assert_eq!(layout.height, 100.0);
6959        assert_eq!(layout.x, 0.0);
6960        assert_eq!(layout.y, 0.0);
6961
6962        assert_eq!(layout.children[0].width, 100.0);
6963        assert_eq!(layout.children[0].height, 10.0);
6964        assert_eq!(layout.children[0].x, 0.0);
6965        assert_eq!(layout.children[0].y, 70.0);
6966
6967        assert_eq!(layout.children[1].width, 100.0);
6968        assert_eq!(layout.children[1].height, 10.0);
6969        assert_eq!(layout.children[1].x, 0.0);
6970        assert_eq!(layout.children[1].y, 80.0);
6971
6972        assert_eq!(layout.children[2].width, 100.0);
6973        assert_eq!(layout.children[2].height, 10.0);
6974        assert_eq!(layout.children[2].x, 0.0);
6975        assert_eq!(layout.children[2].y, 90.0);
6976    }
6977
6978    #[test]
6979    fn rounding_flex_basis_flex_grow_row_width_of_100() {
6980        let layout = stretch::compute(&stretch::style::Node {
6981            width: stretch::style::Dimension::Points(100.0),
6982            height: stretch::style::Dimension::Points(100.0),
6983            children: vec![
6984                stretch::style::Node {
6985                    flex_grow: 1.0,
6986                    ..Default::default()
6987                },
6988                stretch::style::Node {
6989                    flex_grow: 1.0,
6990                    ..Default::default()
6991                },
6992                stretch::style::Node {
6993                    flex_grow: 1.0,
6994                    ..Default::default()
6995                },
6996            ],
6997            ..Default::default()
6998        });
6999
7000        assert_eq!(layout.width, 100.0);
7001        assert_eq!(layout.height, 100.0);
7002        assert_eq!(layout.x, 0.0);
7003        assert_eq!(layout.y, 0.0);
7004
7005        assert_eq!(layout.children[0].width, 33.0);
7006        assert_eq!(layout.children[0].height, 100.0);
7007        assert_eq!(layout.children[0].x, 0.0);
7008        assert_eq!(layout.children[0].y, 0.0);
7009
7010        assert_eq!(layout.children[1].width, 34.0);
7011        assert_eq!(layout.children[1].height, 100.0);
7012        assert_eq!(layout.children[1].x, 33.0);
7013        assert_eq!(layout.children[1].y, 0.0);
7014
7015        assert_eq!(layout.children[2].width, 33.0);
7016        assert_eq!(layout.children[2].height, 100.0);
7017        assert_eq!(layout.children[2].x, 67.0);
7018        assert_eq!(layout.children[2].y, 0.0);
7019    }
7020
7021    #[test]
7022    fn wrap_reverse_row_align_content_flex_start() {
7023        let layout = stretch::compute(&stretch::style::Node {
7024            align_content: stretch::style::AlignContent::FlexStart,
7025            width: stretch::style::Dimension::Points(100.0),
7026            children: vec![
7027                stretch::style::Node {
7028                    width: stretch::style::Dimension::Points(30.0),
7029                    height: stretch::style::Dimension::Points(10.0),
7030                    ..Default::default()
7031                },
7032                stretch::style::Node {
7033                    width: stretch::style::Dimension::Points(30.0),
7034                    height: stretch::style::Dimension::Points(20.0),
7035                    ..Default::default()
7036                },
7037                stretch::style::Node {
7038                    width: stretch::style::Dimension::Points(30.0),
7039                    height: stretch::style::Dimension::Points(30.0),
7040                    ..Default::default()
7041                },
7042                stretch::style::Node {
7043                    width: stretch::style::Dimension::Points(30.0),
7044                    height: stretch::style::Dimension::Points(40.0),
7045                    ..Default::default()
7046                },
7047                stretch::style::Node {
7048                    width: stretch::style::Dimension::Points(30.0),
7049                    height: stretch::style::Dimension::Points(50.0),
7050                    ..Default::default()
7051                },
7052            ],
7053            ..Default::default()
7054        });
7055
7056        assert_eq!(layout.width, 100.0);
7057        assert_eq!(layout.height, 80.0);
7058        assert_eq!(layout.x, 0.0);
7059        assert_eq!(layout.y, 0.0);
7060
7061        assert_eq!(layout.children[0].width, 30.0);
7062        assert_eq!(layout.children[0].height, 10.0);
7063        assert_eq!(layout.children[0].x, 0.0);
7064        assert_eq!(layout.children[0].y, 70.0);
7065
7066        assert_eq!(layout.children[1].width, 30.0);
7067        assert_eq!(layout.children[1].height, 20.0);
7068        assert_eq!(layout.children[1].x, 30.0);
7069        assert_eq!(layout.children[1].y, 60.0);
7070
7071        assert_eq!(layout.children[2].width, 30.0);
7072        assert_eq!(layout.children[2].height, 30.0);
7073        assert_eq!(layout.children[2].x, 60.0);
7074        assert_eq!(layout.children[2].y, 50.0);
7075
7076        assert_eq!(layout.children[3].width, 30.0);
7077        assert_eq!(layout.children[3].height, 40.0);
7078        assert_eq!(layout.children[3].x, 0.0);
7079        assert_eq!(layout.children[3].y, 10.0);
7080
7081        assert_eq!(layout.children[4].width, 30.0);
7082        assert_eq!(layout.children[4].height, 50.0);
7083        assert_eq!(layout.children[4].x, 30.0);
7084        assert_eq!(layout.children[4].y, 0.0);
7085    }
7086
7087    #[test]
7088    fn flex_shrink_flex_grow_child_flex_shrink_other_child() {
7089        let layout = stretch::compute(&stretch::style::Node {
7090            width: stretch::style::Dimension::Points(500.0),
7091            height: stretch::style::Dimension::Points(500.0),
7092            children: vec![
7093                stretch::style::Node {
7094                    flex_grow: 0.0,
7095                    flex_shrink: 1.0,
7096                    width: stretch::style::Dimension::Points(500.0),
7097                    height: stretch::style::Dimension::Points(100.0),
7098                    ..Default::default()
7099                },
7100                stretch::style::Node {
7101                    flex_grow: 1.0,
7102                    flex_shrink: 1.0,
7103                    width: stretch::style::Dimension::Points(500.0),
7104                    height: stretch::style::Dimension::Points(100.0),
7105                    ..Default::default()
7106                },
7107            ],
7108            ..Default::default()
7109        });
7110
7111        assert_eq!(layout.width, 500.0);
7112        assert_eq!(layout.height, 500.0);
7113        assert_eq!(layout.x, 0.0);
7114        assert_eq!(layout.y, 0.0);
7115
7116        assert_eq!(layout.children[0].width, 250.0);
7117        assert_eq!(layout.children[0].height, 100.0);
7118        assert_eq!(layout.children[0].x, 0.0);
7119        assert_eq!(layout.children[0].y, 0.0);
7120
7121        assert_eq!(layout.children[1].width, 250.0);
7122        assert_eq!(layout.children[1].height, 100.0);
7123        assert_eq!(layout.children[1].x, 250.0);
7124        assert_eq!(layout.children[1].y, 0.0);
7125    }
7126
7127    #[test]
7128    fn align_items_flex_end() {
7129        let layout = stretch::compute(&stretch::style::Node {
7130            align_items: stretch::style::AlignItems::FlexEnd,
7131            width: stretch::style::Dimension::Points(100.0),
7132            height: stretch::style::Dimension::Points(100.0),
7133            children: vec![stretch::style::Node {
7134                width: stretch::style::Dimension::Points(10.0),
7135                height: stretch::style::Dimension::Points(10.0),
7136                ..Default::default()
7137            }],
7138            ..Default::default()
7139        });
7140
7141        assert_eq!(layout.width, 100.0);
7142        assert_eq!(layout.height, 100.0);
7143        assert_eq!(layout.x, 0.0);
7144        assert_eq!(layout.y, 0.0);
7145
7146        assert_eq!(layout.children[0].width, 10.0);
7147        assert_eq!(layout.children[0].height, 10.0);
7148        assert_eq!(layout.children[0].x, 0.0);
7149        assert_eq!(layout.children[0].y, 90.0);
7150    }
7151
7152    #[test]
7153    fn absolute_layout_width_height_start_top() {
7154        let layout = stretch::compute(&stretch::style::Node {
7155            width: stretch::style::Dimension::Points(100.0),
7156            height: stretch::style::Dimension::Points(100.0),
7157            children: vec![stretch::style::Node {
7158                position: stretch::style::Position::Absolute,
7159                width: stretch::style::Dimension::Points(10.0),
7160                height: stretch::style::Dimension::Points(10.0),
7161                start: stretch::style::Dimension::Points(10.0),
7162                top: stretch::style::Dimension::Points(10.0),
7163                ..Default::default()
7164            }],
7165            ..Default::default()
7166        });
7167
7168        assert_eq!(layout.width, 100.0);
7169        assert_eq!(layout.height, 100.0);
7170        assert_eq!(layout.x, 0.0);
7171        assert_eq!(layout.y, 0.0);
7172
7173        assert_eq!(layout.children[0].width, 10.0);
7174        assert_eq!(layout.children[0].height, 10.0);
7175        assert_eq!(layout.children[0].x, 10.0);
7176        assert_eq!(layout.children[0].y, 10.0);
7177    }
7178
7179    #[test]
7180    fn rounding_flex_basis_flex_shrink_row() {
7181        let layout = stretch::compute(&stretch::style::Node {
7182            width: stretch::style::Dimension::Points(101.0),
7183            height: stretch::style::Dimension::Points(100.0),
7184            children: vec![
7185                stretch::style::Node {
7186                    flex_shrink: 1.0,
7187                    flex_basis: stretch::style::Dimension::Points(100.0),
7188                    ..Default::default()
7189                },
7190                stretch::style::Node {
7191                    flex_basis: stretch::style::Dimension::Points(25.0),
7192                    ..Default::default()
7193                },
7194                stretch::style::Node {
7195                    flex_basis: stretch::style::Dimension::Points(25.0),
7196                    ..Default::default()
7197                },
7198            ],
7199            ..Default::default()
7200        });
7201
7202        assert_eq!(layout.width, 101.0);
7203        assert_eq!(layout.height, 100.0);
7204        assert_eq!(layout.x, 0.0);
7205        assert_eq!(layout.y, 0.0);
7206
7207        assert_eq!(layout.children[0].width, 67.0);
7208        assert_eq!(layout.children[0].height, 100.0);
7209        assert_eq!(layout.children[0].x, 0.0);
7210        assert_eq!(layout.children[0].y, 0.0);
7211
7212        assert_eq!(layout.children[1].width, 17.0);
7213        assert_eq!(layout.children[1].height, 100.0);
7214        assert_eq!(layout.children[1].x, 67.0);
7215        assert_eq!(layout.children[1].y, 0.0);
7216
7217        assert_eq!(layout.children[2].width, 17.0);
7218        assert_eq!(layout.children[2].height, 100.0);
7219        assert_eq!(layout.children[2].x, 84.0);
7220        assert_eq!(layout.children[2].y, 0.0);
7221    }
7222
7223    #[test]
7224    fn border_center_child() {
7225        let layout = stretch::compute(&stretch::style::Node {
7226            align_items: stretch::style::AlignItems::Center,
7227            justify_content: stretch::style::JustifyContent::Center,
7228            width: stretch::style::Dimension::Points(100.0),
7229            height: stretch::style::Dimension::Points(100.0),
7230            border: stretch::style::Edges {
7231                top: stretch::style::Dimension::Points(10.0),
7232                bottom: stretch::style::Dimension::Points(20.0),
7233                ..Default::default()
7234            },
7235            children: vec![stretch::style::Node {
7236                width: stretch::style::Dimension::Points(10.0),
7237                height: stretch::style::Dimension::Points(10.0),
7238                ..Default::default()
7239            }],
7240            ..Default::default()
7241        });
7242
7243        assert_eq!(layout.width, 100.0);
7244        assert_eq!(layout.height, 100.0);
7245        assert_eq!(layout.x, 0.0);
7246        assert_eq!(layout.y, 0.0);
7247
7248        assert_eq!(layout.children[0].width, 10.0);
7249        assert_eq!(layout.children[0].height, 10.0);
7250        assert_eq!(layout.children[0].x, 45.0);
7251        assert_eq!(layout.children[0].y, 40.0);
7252    }
7253
7254    #[test]
7255    fn align_items_flex_start() {
7256        let layout = stretch::compute(&stretch::style::Node {
7257            align_items: stretch::style::AlignItems::FlexStart,
7258            width: stretch::style::Dimension::Points(100.0),
7259            height: stretch::style::Dimension::Points(100.0),
7260            children: vec![stretch::style::Node {
7261                width: stretch::style::Dimension::Points(10.0),
7262                height: stretch::style::Dimension::Points(10.0),
7263                ..Default::default()
7264            }],
7265            ..Default::default()
7266        });
7267
7268        assert_eq!(layout.width, 100.0);
7269        assert_eq!(layout.height, 100.0);
7270        assert_eq!(layout.x, 0.0);
7271        assert_eq!(layout.y, 0.0);
7272
7273        assert_eq!(layout.children[0].width, 10.0);
7274        assert_eq!(layout.children[0].height, 10.0);
7275        assert_eq!(layout.children[0].x, 0.0);
7276        assert_eq!(layout.children[0].y, 0.0);
7277    }
7278
7279    #[test]
7280    fn border_no_child() {
7281        let layout = stretch::compute(&stretch::style::Node {
7282            border: stretch::style::Edges {
7283                start: stretch::style::Dimension::Points(10.0),
7284                end: stretch::style::Dimension::Points(10.0),
7285                top: stretch::style::Dimension::Points(10.0),
7286                bottom: stretch::style::Dimension::Points(10.0),
7287                ..Default::default()
7288            },
7289            ..Default::default()
7290        });
7291
7292        assert_eq!(layout.width, 20.0);
7293        assert_eq!(layout.height, 20.0);
7294        assert_eq!(layout.x, 0.0);
7295        assert_eq!(layout.y, 0.0);
7296    }
7297
7298    #[test]
7299    fn rounding_flex_basis_flex_grow_row_prime_number_width() {
7300        let layout = stretch::compute(&stretch::style::Node {
7301            width: stretch::style::Dimension::Points(113.0),
7302            height: stretch::style::Dimension::Points(100.0),
7303            children: vec![
7304                stretch::style::Node {
7305                    flex_grow: 1.0,
7306                    ..Default::default()
7307                },
7308                stretch::style::Node {
7309                    flex_grow: 1.0,
7310                    ..Default::default()
7311                },
7312                stretch::style::Node {
7313                    flex_grow: 1.0,
7314                    ..Default::default()
7315                },
7316                stretch::style::Node {
7317                    flex_grow: 1.0,
7318                    ..Default::default()
7319                },
7320                stretch::style::Node {
7321                    flex_grow: 1.0,
7322                    ..Default::default()
7323                },
7324            ],
7325            ..Default::default()
7326        });
7327
7328        assert_eq!(layout.width, 113.0);
7329        assert_eq!(layout.height, 100.0);
7330        assert_eq!(layout.x, 0.0);
7331        assert_eq!(layout.y, 0.0);
7332
7333        assert_eq!(layout.children[0].width, 23.0);
7334        assert_eq!(layout.children[0].height, 100.0);
7335        assert_eq!(layout.children[0].x, 0.0);
7336        assert_eq!(layout.children[0].y, 0.0);
7337
7338        assert_eq!(layout.children[1].width, 22.0);
7339        assert_eq!(layout.children[1].height, 100.0);
7340        assert_eq!(layout.children[1].x, 23.0);
7341        assert_eq!(layout.children[1].y, 0.0);
7342
7343        assert_eq!(layout.children[2].width, 23.0);
7344        assert_eq!(layout.children[2].height, 100.0);
7345        assert_eq!(layout.children[2].x, 45.0);
7346        assert_eq!(layout.children[2].y, 0.0);
7347
7348        assert_eq!(layout.children[3].width, 22.0);
7349        assert_eq!(layout.children[3].height, 100.0);
7350        assert_eq!(layout.children[3].x, 68.0);
7351        assert_eq!(layout.children[3].y, 0.0);
7352
7353        assert_eq!(layout.children[4].width, 23.0);
7354        assert_eq!(layout.children[4].height, 100.0);
7355        assert_eq!(layout.children[4].x, 90.0);
7356        assert_eq!(layout.children[4].y, 0.0);
7357    }
7358
7359    #[test]
7360    fn align_items_center_with_child_top() {
7361        let layout = stretch::compute(&stretch::style::Node {
7362            align_items: stretch::style::AlignItems::Center,
7363            width: stretch::style::Dimension::Points(100.0),
7364            height: stretch::style::Dimension::Points(100.0),
7365            children: vec![stretch::style::Node {
7366                width: stretch::style::Dimension::Points(10.0),
7367                height: stretch::style::Dimension::Points(10.0),
7368                top: stretch::style::Dimension::Points(10.0),
7369                ..Default::default()
7370            }],
7371            ..Default::default()
7372        });
7373
7374        assert_eq!(layout.width, 100.0);
7375        assert_eq!(layout.height, 100.0);
7376        assert_eq!(layout.x, 0.0);
7377        assert_eq!(layout.y, 0.0);
7378
7379        assert_eq!(layout.children[0].width, 10.0);
7380        assert_eq!(layout.children[0].height, 10.0);
7381        assert_eq!(layout.children[0].x, 0.0);
7382        assert_eq!(layout.children[0].y, 55.0);
7383    }
7384
7385    #[test]
7386    fn percentage_width_height_undefined_parent_size() {
7387        let layout = stretch::compute(&stretch::style::Node {
7388            flex_direction: stretch::style::FlexDirection::Column,
7389            children: vec![stretch::style::Node {
7390                width: stretch::style::Dimension::Percent(0.5),
7391                height: stretch::style::Dimension::Percent(0.5),
7392                ..Default::default()
7393            }],
7394            ..Default::default()
7395        });
7396
7397        assert_eq!(layout.width, 0.0);
7398        assert_eq!(layout.height, 0.0);
7399        assert_eq!(layout.x, 0.0);
7400        assert_eq!(layout.y, 0.0);
7401
7402        assert_eq!(layout.children[0].width, 0.0);
7403        assert_eq!(layout.children[0].height, 0.0);
7404        assert_eq!(layout.children[0].x, 0.0);
7405        assert_eq!(layout.children[0].y, 0.0);
7406    }
7407
7408    #[test]
7409    fn flex_grow_within_max_width() {
7410        let layout = stretch::compute(&stretch::style::Node {
7411            flex_direction: stretch::style::FlexDirection::Column,
7412            width: stretch::style::Dimension::Points(200.0),
7413            height: stretch::style::Dimension::Points(100.0),
7414            children: vec![stretch::style::Node {
7415                max_width: stretch::style::Dimension::Points(100.0),
7416                children: vec![stretch::style::Node {
7417                    flex_grow: 1.0,
7418                    height: stretch::style::Dimension::Points(20.0),
7419                    ..Default::default()
7420                }],
7421                ..Default::default()
7422            }],
7423            ..Default::default()
7424        });
7425
7426        assert_eq!(layout.width, 200.0);
7427        assert_eq!(layout.height, 100.0);
7428        assert_eq!(layout.x, 0.0);
7429        assert_eq!(layout.y, 0.0);
7430
7431        assert_eq!(layout.children[0].width, 100.0);
7432        assert_eq!(layout.children[0].height, 20.0);
7433        assert_eq!(layout.children[0].x, 0.0);
7434        assert_eq!(layout.children[0].y, 0.0);
7435
7436        assert_eq!(layout.children[0].children[0].width, 100.0);
7437        assert_eq!(layout.children[0].children[0].height, 20.0);
7438        assert_eq!(layout.children[0].children[0].x, 0.0);
7439        assert_eq!(layout.children[0].children[0].y, 0.0);
7440    }
7441
7442    #[test]
7443    fn flex_grow_height_maximized() {
7444        let layout = stretch::compute(&stretch::style::Node {
7445            flex_direction: stretch::style::FlexDirection::Column,
7446            width: stretch::style::Dimension::Points(100.0),
7447            height: stretch::style::Dimension::Points(500.0),
7448            children: vec![stretch::style::Node {
7449                flex_direction: stretch::style::FlexDirection::Column,
7450                flex_grow: 1.0,
7451                min_height: stretch::style::Dimension::Points(100.0),
7452                max_height: stretch::style::Dimension::Points(500.0),
7453                children: vec![
7454                    stretch::style::Node {
7455                        flex_grow: 1.0,
7456                        flex_basis: stretch::style::Dimension::Points(200.0),
7457                        ..Default::default()
7458                    },
7459                    stretch::style::Node {
7460                        height: stretch::style::Dimension::Points(100.0),
7461                        ..Default::default()
7462                    },
7463                ],
7464                ..Default::default()
7465            }],
7466            ..Default::default()
7467        });
7468
7469        assert_eq!(layout.width, 100.0);
7470        assert_eq!(layout.height, 500.0);
7471        assert_eq!(layout.x, 0.0);
7472        assert_eq!(layout.y, 0.0);
7473
7474        assert_eq!(layout.children[0].width, 100.0);
7475        assert_eq!(layout.children[0].height, 500.0);
7476        assert_eq!(layout.children[0].x, 0.0);
7477        assert_eq!(layout.children[0].y, 0.0);
7478
7479        assert_eq!(layout.children[0].children[0].width, 100.0);
7480        assert_eq!(layout.children[0].children[0].height, 400.0);
7481        assert_eq!(layout.children[0].children[0].x, 0.0);
7482        assert_eq!(layout.children[0].children[0].y, 0.0);
7483
7484        assert_eq!(layout.children[0].children[1].width, 100.0);
7485        assert_eq!(layout.children[0].children[1].height, 100.0);
7486        assert_eq!(layout.children[0].children[1].x, 0.0);
7487        assert_eq!(layout.children[0].children[1].y, 400.0);
7488    }
7489
7490    #[test]
7491    fn max_height_overrides_height() {
7492        let layout = stretch::compute(&stretch::style::Node {
7493            children: vec![stretch::style::Node {
7494                height: stretch::style::Dimension::Points(200.0),
7495                max_height: stretch::style::Dimension::Points(100.0),
7496                ..Default::default()
7497            }],
7498            ..Default::default()
7499        });
7500
7501        assert_eq!(layout.width, 0.0);
7502        assert_eq!(layout.height, 100.0);
7503        assert_eq!(layout.x, 0.0);
7504        assert_eq!(layout.y, 0.0);
7505
7506        assert_eq!(layout.children[0].width, 0.0);
7507        assert_eq!(layout.children[0].height, 100.0);
7508        assert_eq!(layout.children[0].x, 0.0);
7509        assert_eq!(layout.children[0].y, 0.0);
7510    }
7511
7512    #[test]
7513    fn justify_content_min_width_with_padding_child_width_greater_than_parent() {
7514        let layout = stretch::compute(&stretch::style::Node {
7515            flex_direction: stretch::style::FlexDirection::Column,
7516            width: stretch::style::Dimension::Points(1000.0),
7517            height: stretch::style::Dimension::Points(1584.0),
7518            children: vec![stretch::style::Node {
7519                children: vec![stretch::style::Node {
7520                    justify_content: stretch::style::JustifyContent::Center,
7521                    min_width: stretch::style::Dimension::Points(400.0),
7522                    padding: stretch::style::Edges {
7523                        start: stretch::style::Dimension::Points(100.0),
7524                        end: stretch::style::Dimension::Points(100.0),
7525                        ..Default::default()
7526                    },
7527                    children: vec![stretch::style::Node {
7528                        width: stretch::style::Dimension::Points(300.0),
7529                        height: stretch::style::Dimension::Points(100.0),
7530                        ..Default::default()
7531                    }],
7532                    ..Default::default()
7533                }],
7534                ..Default::default()
7535            }],
7536            ..Default::default()
7537        });
7538
7539        assert_eq!(layout.width, 1000.0);
7540        assert_eq!(layout.height, 1584.0);
7541        assert_eq!(layout.x, 0.0);
7542        assert_eq!(layout.y, 0.0);
7543
7544        assert_eq!(layout.children[0].width, 1000.0);
7545        assert_eq!(layout.children[0].height, 100.0);
7546        assert_eq!(layout.children[0].x, 0.0);
7547        assert_eq!(layout.children[0].y, 0.0);
7548
7549        assert_eq!(layout.children[0].children[0].width, 500.0);
7550        assert_eq!(layout.children[0].children[0].height, 100.0);
7551        assert_eq!(layout.children[0].children[0].x, 0.0);
7552        assert_eq!(layout.children[0].children[0].y, 0.0);
7553
7554        assert_eq!(layout.children[0].children[0].children[0].width, 300.0);
7555        assert_eq!(layout.children[0].children[0].children[0].height, 100.0);
7556        assert_eq!(layout.children[0].children[0].children[0].x, 100.0);
7557        assert_eq!(layout.children[0].children[0].children[0].y, 0.0);
7558    }
7559
7560    #[test]
7561    fn percent_absolute_position() {
7562        let layout = stretch::compute(&stretch::style::Node {
7563            flex_direction: stretch::style::FlexDirection::Column,
7564            width: stretch::style::Dimension::Points(60.0),
7565            height: stretch::style::Dimension::Points(50.0),
7566            children: vec![stretch::style::Node {
7567                position: stretch::style::Position::Absolute,
7568                width: stretch::style::Dimension::Percent(1.0),
7569                height: stretch::style::Dimension::Points(50.0),
7570                start: stretch::style::Dimension::Percent(0.5),
7571                children: vec![
7572                    stretch::style::Node {
7573                        width: stretch::style::Dimension::Percent(1.0),
7574                        ..Default::default()
7575                    },
7576                    stretch::style::Node {
7577                        width: stretch::style::Dimension::Percent(1.0),
7578                        ..Default::default()
7579                    },
7580                ],
7581                ..Default::default()
7582            }],
7583            ..Default::default()
7584        });
7585
7586        assert_eq!(layout.width, 60.0);
7587        assert_eq!(layout.height, 50.0);
7588        assert_eq!(layout.x, 0.0);
7589        assert_eq!(layout.y, 0.0);
7590
7591        assert_eq!(layout.children[0].width, 60.0);
7592        assert_eq!(layout.children[0].height, 50.0);
7593        assert_eq!(layout.children[0].x, 30.0);
7594        assert_eq!(layout.children[0].y, 0.0);
7595
7596        assert_eq!(layout.children[0].children[0].width, 30.0);
7597        assert_eq!(layout.children[0].children[0].height, 50.0);
7598        assert_eq!(layout.children[0].children[0].x, 0.0);
7599        assert_eq!(layout.children[0].children[0].y, 0.0);
7600
7601        assert_eq!(layout.children[0].children[1].width, 30.0);
7602        assert_eq!(layout.children[0].children[1].height, 50.0);
7603        assert_eq!(layout.children[0].children[1].x, 30.0);
7604        assert_eq!(layout.children[0].children[1].y, 0.0);
7605    }
7606
7607    #[test]
7608    fn flex_root_ignored() {
7609        let layout = stretch::compute(&stretch::style::Node {
7610            flex_direction: stretch::style::FlexDirection::Column,
7611            width: stretch::style::Dimension::Points(100.0),
7612            min_height: stretch::style::Dimension::Points(100.0),
7613            max_height: stretch::style::Dimension::Points(500.0),
7614            children: vec![
7615                stretch::style::Node {
7616                    flex_grow: 1.0,
7617                    flex_basis: stretch::style::Dimension::Points(200.0),
7618                    ..Default::default()
7619                },
7620                stretch::style::Node {
7621                    height: stretch::style::Dimension::Points(100.0),
7622                    ..Default::default()
7623                },
7624            ],
7625            ..Default::default()
7626        });
7627
7628        assert_eq!(layout.width, 100.0);
7629        assert_eq!(layout.height, 300.0);
7630        assert_eq!(layout.x, 0.0);
7631        assert_eq!(layout.y, 0.0);
7632
7633        assert_eq!(layout.children[0].width, 100.0);
7634        assert_eq!(layout.children[0].height, 200.0);
7635        assert_eq!(layout.children[0].x, 0.0);
7636        assert_eq!(layout.children[0].y, 0.0);
7637
7638        assert_eq!(layout.children[1].width, 100.0);
7639        assert_eq!(layout.children[1].height, 100.0);
7640        assert_eq!(layout.children[1].x, 0.0);
7641        assert_eq!(layout.children[1].y, 200.0);
7642    }
7643
7644    #[test]
7645    fn justify_content_column_space_between() {
7646        let layout = stretch::compute(&stretch::style::Node {
7647            flex_direction: stretch::style::FlexDirection::Column,
7648            justify_content: stretch::style::JustifyContent::SpaceBetween,
7649            width: stretch::style::Dimension::Points(100.0),
7650            height: stretch::style::Dimension::Points(100.0),
7651            children: vec![
7652                stretch::style::Node {
7653                    height: stretch::style::Dimension::Points(10.0),
7654                    ..Default::default()
7655                },
7656                stretch::style::Node {
7657                    height: stretch::style::Dimension::Points(10.0),
7658                    ..Default::default()
7659                },
7660                stretch::style::Node {
7661                    height: stretch::style::Dimension::Points(10.0),
7662                    ..Default::default()
7663                },
7664            ],
7665            ..Default::default()
7666        });
7667
7668        assert_eq!(layout.width, 100.0);
7669        assert_eq!(layout.height, 100.0);
7670        assert_eq!(layout.x, 0.0);
7671        assert_eq!(layout.y, 0.0);
7672
7673        assert_eq!(layout.children[0].width, 100.0);
7674        assert_eq!(layout.children[0].height, 10.0);
7675        assert_eq!(layout.children[0].x, 0.0);
7676        assert_eq!(layout.children[0].y, 0.0);
7677
7678        assert_eq!(layout.children[1].width, 100.0);
7679        assert_eq!(layout.children[1].height, 10.0);
7680        assert_eq!(layout.children[1].x, 0.0);
7681        assert_eq!(layout.children[1].y, 45.0);
7682
7683        assert_eq!(layout.children[2].width, 100.0);
7684        assert_eq!(layout.children[2].height, 10.0);
7685        assert_eq!(layout.children[2].x, 0.0);
7686        assert_eq!(layout.children[2].y, 90.0);
7687    }
7688
7689    #[test]
7690    fn flex_grow_within_constrained_max_width() {
7691        let layout = stretch::compute(&stretch::style::Node {
7692            flex_direction: stretch::style::FlexDirection::Column,
7693            width: stretch::style::Dimension::Points(200.0),
7694            height: stretch::style::Dimension::Points(100.0),
7695            children: vec![stretch::style::Node {
7696                max_width: stretch::style::Dimension::Points(300.0),
7697                children: vec![stretch::style::Node {
7698                    flex_grow: 1.0,
7699                    height: stretch::style::Dimension::Points(20.0),
7700                    ..Default::default()
7701                }],
7702                ..Default::default()
7703            }],
7704            ..Default::default()
7705        });
7706
7707        assert_eq!(layout.width, 200.0);
7708        assert_eq!(layout.height, 100.0);
7709        assert_eq!(layout.x, 0.0);
7710        assert_eq!(layout.y, 0.0);
7711
7712        assert_eq!(layout.children[0].width, 200.0);
7713        assert_eq!(layout.children[0].height, 20.0);
7714        assert_eq!(layout.children[0].x, 0.0);
7715        assert_eq!(layout.children[0].y, 0.0);
7716
7717        assert_eq!(layout.children[0].children[0].width, 200.0);
7718        assert_eq!(layout.children[0].children[0].height, 20.0);
7719        assert_eq!(layout.children[0].children[0].x, 0.0);
7720        assert_eq!(layout.children[0].children[0].y, 0.0);
7721    }
7722
7723    #[test]
7724    fn max_width_overrides_width() {
7725        let layout = stretch::compute(&stretch::style::Node {
7726            children: vec![stretch::style::Node {
7727                width: stretch::style::Dimension::Points(200.0),
7728                max_width: stretch::style::Dimension::Points(100.0),
7729                ..Default::default()
7730            }],
7731            ..Default::default()
7732        });
7733
7734        assert_eq!(layout.width, 100.0);
7735        assert_eq!(layout.height, 0.0);
7736        assert_eq!(layout.x, 0.0);
7737        assert_eq!(layout.y, 0.0);
7738
7739        assert_eq!(layout.children[0].width, 100.0);
7740        assert_eq!(layout.children[0].height, 0.0);
7741        assert_eq!(layout.children[0].x, 0.0);
7742        assert_eq!(layout.children[0].y, 0.0);
7743    }
7744
7745    #[test]
7746    fn percentage_position_bottom_right() {
7747        let layout = stretch::compute(&stretch::style::Node {
7748            width: stretch::style::Dimension::Points(500.0),
7749            height: stretch::style::Dimension::Points(500.0),
7750            children: vec![stretch::style::Node {
7751                width: stretch::style::Dimension::Percent(0.6),
7752                height: stretch::style::Dimension::Percent(0.2),
7753                end: stretch::style::Dimension::Percent(0.2),
7754                bottom: stretch::style::Dimension::Percent(0.1),
7755                ..Default::default()
7756            }],
7757            ..Default::default()
7758        });
7759
7760        assert_eq!(layout.width, 500.0);
7761        assert_eq!(layout.height, 500.0);
7762        assert_eq!(layout.x, 0.0);
7763        assert_eq!(layout.y, 0.0);
7764
7765        assert_eq!(layout.children[0].width, 275.0);
7766        assert_eq!(layout.children[0].height, 75.0);
7767        assert_eq!(layout.children[0].x, -100.0);
7768        assert_eq!(layout.children[0].y, -50.0);
7769    }
7770
7771    #[test]
7772    fn margin_auto_top_stretching_child() {
7773        let layout = stretch::compute(&stretch::style::Node {
7774            align_items: stretch::style::AlignItems::Center,
7775            width: stretch::style::Dimension::Points(200.0),
7776            height: stretch::style::Dimension::Points(200.0),
7777            children: vec![
7778                stretch::style::Node {
7779                    flex_grow: 1.0,
7780                    flex_shrink: 1.0,
7781                    flex_basis: stretch::style::Dimension::Percent(0.0),
7782                    margin: stretch::style::Edges {
7783                        top: stretch::style::Dimension::Auto,
7784                        ..Default::default()
7785                    },
7786                    ..Default::default()
7787                },
7788                stretch::style::Node {
7789                    width: stretch::style::Dimension::Points(50.0),
7790                    height: stretch::style::Dimension::Points(50.0),
7791                    ..Default::default()
7792                },
7793            ],
7794            ..Default::default()
7795        });
7796
7797        assert_eq!(layout.width, 200.0);
7798        assert_eq!(layout.height, 200.0);
7799        assert_eq!(layout.x, 0.0);
7800        assert_eq!(layout.y, 0.0);
7801
7802        assert_eq!(layout.children[0].width, 150.0);
7803        assert_eq!(layout.children[0].height, 0.0);
7804        assert_eq!(layout.children[0].x, 0.0);
7805        assert_eq!(layout.children[0].y, 200.0);
7806
7807        assert_eq!(layout.children[1].width, 50.0);
7808        assert_eq!(layout.children[1].height, 50.0);
7809        assert_eq!(layout.children[1].x, 150.0);
7810        assert_eq!(layout.children[1].y, 75.0);
7811    }
7812
7813    #[test]
7814    fn justify_content_column_min_height_and_margin() {
7815        let layout = stretch::compute(&stretch::style::Node {
7816            flex_direction: stretch::style::FlexDirection::Column,
7817            justify_content: stretch::style::JustifyContent::Center,
7818            min_height: stretch::style::Dimension::Points(50.0),
7819            margin: stretch::style::Edges {
7820                top: stretch::style::Dimension::Points(100.0),
7821                ..Default::default()
7822            },
7823            children: vec![stretch::style::Node {
7824                width: stretch::style::Dimension::Points(20.0),
7825                height: stretch::style::Dimension::Points(20.0),
7826                ..Default::default()
7827            }],
7828            ..Default::default()
7829        });
7830
7831        assert_eq!(layout.width, 20.0);
7832        assert_eq!(layout.height, 50.0);
7833        assert_eq!(layout.x, 0.0);
7834        assert_eq!(layout.y, 100.0);
7835
7836        assert_eq!(layout.children[0].width, 20.0);
7837        assert_eq!(layout.children[0].height, 20.0);
7838        assert_eq!(layout.children[0].x, 0.0);
7839        assert_eq!(layout.children[0].y, 15.0);
7840    }
7841
7842    #[test]
7843    fn align_flex_start_with_shrinking_children() {
7844        let layout = stretch::compute(&stretch::style::Node {
7845            width: stretch::style::Dimension::Points(500.0),
7846            height: stretch::style::Dimension::Points(500.0),
7847            children: vec![stretch::style::Node {
7848                align_items: stretch::style::AlignItems::FlexStart,
7849                children: vec![stretch::style::Node {
7850                    flex_grow: 1.0,
7851                    flex_shrink: 1.0,
7852                    children: vec![stretch::style::Node {
7853                        flex_grow: 1.0,
7854                        flex_shrink: 1.0,
7855                        ..Default::default()
7856                    }],
7857                    ..Default::default()
7858                }],
7859                ..Default::default()
7860            }],
7861            ..Default::default()
7862        });
7863
7864        assert_eq!(layout.width, 500.0);
7865        assert_eq!(layout.height, 500.0);
7866        assert_eq!(layout.x, 0.0);
7867        assert_eq!(layout.y, 0.0);
7868
7869        assert_eq!(layout.children[0].width, 0.0);
7870        assert_eq!(layout.children[0].height, 500.0);
7871        assert_eq!(layout.children[0].x, 0.0);
7872        assert_eq!(layout.children[0].y, 0.0);
7873
7874        assert_eq!(layout.children[0].children[0].width, 0.0);
7875        assert_eq!(layout.children[0].children[0].height, 0.0);
7876        assert_eq!(layout.children[0].children[0].x, 0.0);
7877        assert_eq!(layout.children[0].children[0].y, 0.0);
7878
7879        assert_eq!(layout.children[0].children[0].children[0].width, 0.0);
7880        assert_eq!(layout.children[0].children[0].children[0].height, 0.0);
7881        assert_eq!(layout.children[0].children[0].children[0].x, 0.0);
7882        assert_eq!(layout.children[0].children[0].children[0].y, 0.0);
7883    }
7884
7885}