tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1085HTML 1017Markdown 12TOML 83230 Definitions

⎇ c3eff87967f17e831fe09488d3206b363e4e9efa tests/generated.rs Rust · 12161 lines · 516.4 KB History Who touched what raw

Add error handling to custom measure functions c3eff8796 · Emil Sjölander ·

1#[cfg(test)]
2mod generated {
3    #[test]
4    fn justify_content_row_space_around() {
5        let layout = stretch::compute(
6            &stretch::style::Node {
7                justify_content: stretch::style::JustifyContent::SpaceAround,
8                size: stretch::geometry::Size {
9                    width: stretch::style::Dimension::Points(100.0000),
10                    height: stretch::style::Dimension::Points(100.0000),
11                    ..Default::default()
12                },
13                children: vec![
14                    stretch::style::Node {
15                        size: stretch::geometry::Size {
16                            width: stretch::style::Dimension::Points(10.0000),
17                            ..Default::default()
18                        },
19                        ..Default::default()
20                    },
21                    stretch::style::Node {
22                        size: stretch::geometry::Size {
23                            width: stretch::style::Dimension::Points(10.0000),
24                            ..Default::default()
25                        },
26                        ..Default::default()
27                    },
28                    stretch::style::Node {
29                        size: stretch::geometry::Size {
30                            width: stretch::style::Dimension::Points(10.0000),
31                            ..Default::default()
32                        },
33                        ..Default::default()
34                    },
35                ],
36                ..Default::default()
37            },
38            stretch::geometry::Size::undefined(),
39        )
40        .unwrap();
41
42        assert_eq!(layout.size.width, 100.0000);
43        assert_eq!(layout.size.height, 100.0000);
44        assert_eq!(layout.location.x, 0.0000);
45        assert_eq!(layout.location.y, 0.0000);
46
47        assert_eq!(layout.children[0].size.width, 10.0000);
48        assert_eq!(layout.children[0].size.height, 100.0000);
49        assert_eq!(layout.children[0].location.x, 12.0000);
50        assert_eq!(layout.children[0].location.y, 0.0000);
51
52        assert_eq!(layout.children[1].size.width, 10.0000);
53        assert_eq!(layout.children[1].size.height, 100.0000);
54        assert_eq!(layout.children[1].location.x, 45.0000);
55        assert_eq!(layout.children[1].location.y, 0.0000);
56
57        assert_eq!(layout.children[2].size.width, 10.0000);
58        assert_eq!(layout.children[2].size.height, 100.0000);
59        assert_eq!(layout.children[2].location.x, 78.0000);
60        assert_eq!(layout.children[2].location.y, 0.0000);
61    }
62
63    #[test]
64    fn align_items_center() {
65        let layout = stretch::compute(
66            &stretch::style::Node {
67                align_items: stretch::style::AlignItems::Center,
68                size: stretch::geometry::Size {
69                    width: stretch::style::Dimension::Points(100.0000),
70                    height: stretch::style::Dimension::Points(100.0000),
71                    ..Default::default()
72                },
73                children: vec![stretch::style::Node {
74                    size: stretch::geometry::Size {
75                        width: stretch::style::Dimension::Points(10.0000),
76                        height: stretch::style::Dimension::Points(10.0000),
77                        ..Default::default()
78                    },
79                    ..Default::default()
80                }],
81                ..Default::default()
82            },
83            stretch::geometry::Size::undefined(),
84        )
85        .unwrap();
86
87        assert_eq!(layout.size.width, 100.0000);
88        assert_eq!(layout.size.height, 100.0000);
89        assert_eq!(layout.location.x, 0.0000);
90        assert_eq!(layout.location.y, 0.0000);
91
92        assert_eq!(layout.children[0].size.width, 10.0000);
93        assert_eq!(layout.children[0].size.height, 10.0000);
94        assert_eq!(layout.children[0].location.x, 0.0000);
95        assert_eq!(layout.children[0].location.y, 45.0000);
96    }
97
98    #[test]
99    fn absolute_layout_justify_content_center() {
100        let layout = stretch::compute(
101            &stretch::style::Node {
102                justify_content: stretch::style::JustifyContent::Center,
103                size: stretch::geometry::Size {
104                    width: stretch::style::Dimension::Points(110.0000),
105                    height: stretch::style::Dimension::Points(100.0000),
106                    ..Default::default()
107                },
108                children: vec![stretch::style::Node {
109                    position_type: stretch::style::PositionType::Absolute,
110                    size: stretch::geometry::Size {
111                        width: stretch::style::Dimension::Points(60.0000),
112                        height: stretch::style::Dimension::Points(40.0000),
113                        ..Default::default()
114                    },
115                    ..Default::default()
116                }],
117                ..Default::default()
118            },
119            stretch::geometry::Size::undefined(),
120        )
121        .unwrap();
122
123        assert_eq!(layout.size.width, 110.0000);
124        assert_eq!(layout.size.height, 100.0000);
125        assert_eq!(layout.location.x, 0.0000);
126        assert_eq!(layout.location.y, 0.0000);
127
128        assert_eq!(layout.children[0].size.width, 60.0000);
129        assert_eq!(layout.children[0].size.height, 40.0000);
130        assert_eq!(layout.children[0].location.x, 25.0000);
131        assert_eq!(layout.children[0].location.y, 0.0000);
132    }
133
134    #[test]
135    fn margin_auto_bottom_and_top() {
136        let layout = stretch::compute(
137            &stretch::style::Node {
138                align_items: stretch::style::AlignItems::Center,
139                size: stretch::geometry::Size {
140                    width: stretch::style::Dimension::Points(200.0000),
141                    height: stretch::style::Dimension::Points(200.0000),
142                    ..Default::default()
143                },
144                children: vec![
145                    stretch::style::Node {
146                        size: stretch::geometry::Size {
147                            width: stretch::style::Dimension::Points(50.0000),
148                            height: stretch::style::Dimension::Points(50.0000),
149                            ..Default::default()
150                        },
151                        margin: stretch::geometry::Rect {
152                            top: stretch::style::Dimension::Auto,
153                            bottom: stretch::style::Dimension::Auto,
154                            ..Default::default()
155                        },
156                        ..Default::default()
157                    },
158                    stretch::style::Node {
159                        size: stretch::geometry::Size {
160                            width: stretch::style::Dimension::Points(50.0000),
161                            height: stretch::style::Dimension::Points(50.0000),
162                            ..Default::default()
163                        },
164                        ..Default::default()
165                    },
166                ],
167                ..Default::default()
168            },
169            stretch::geometry::Size::undefined(),
170        )
171        .unwrap();
172
173        assert_eq!(layout.size.width, 200.0000);
174        assert_eq!(layout.size.height, 200.0000);
175        assert_eq!(layout.location.x, 0.0000);
176        assert_eq!(layout.location.y, 0.0000);
177
178        assert_eq!(layout.children[0].size.width, 50.0000);
179        assert_eq!(layout.children[0].size.height, 50.0000);
180        assert_eq!(layout.children[0].location.x, 0.0000);
181        assert_eq!(layout.children[0].location.y, 75.0000);
182
183        assert_eq!(layout.children[1].size.width, 50.0000);
184        assert_eq!(layout.children[1].size.height, 50.0000);
185        assert_eq!(layout.children[1].location.x, 50.0000);
186        assert_eq!(layout.children[1].location.y, 75.0000);
187    }
188
189    #[test]
190    fn margin_auto_left_and_right_strech() {
191        let layout = stretch::compute(
192            &stretch::style::Node {
193                size: stretch::geometry::Size {
194                    width: stretch::style::Dimension::Points(200.0000),
195                    height: stretch::style::Dimension::Points(200.0000),
196                    ..Default::default()
197                },
198                children: vec![
199                    stretch::style::Node {
200                        size: stretch::geometry::Size {
201                            width: stretch::style::Dimension::Points(50.0000),
202                            height: stretch::style::Dimension::Points(50.0000),
203                            ..Default::default()
204                        },
205                        margin: stretch::geometry::Rect {
206                            start: stretch::style::Dimension::Auto,
207                            end: stretch::style::Dimension::Auto,
208                            ..Default::default()
209                        },
210                        ..Default::default()
211                    },
212                    stretch::style::Node {
213                        size: stretch::geometry::Size {
214                            width: stretch::style::Dimension::Points(50.0000),
215                            height: stretch::style::Dimension::Points(50.0000),
216                            ..Default::default()
217                        },
218                        ..Default::default()
219                    },
220                ],
221                ..Default::default()
222            },
223            stretch::geometry::Size::undefined(),
224        )
225        .unwrap();
226
227        assert_eq!(layout.size.width, 200.0000);
228        assert_eq!(layout.size.height, 200.0000);
229        assert_eq!(layout.location.x, 0.0000);
230        assert_eq!(layout.location.y, 0.0000);
231
232        assert_eq!(layout.children[0].size.width, 50.0000);
233        assert_eq!(layout.children[0].size.height, 50.0000);
234        assert_eq!(layout.children[0].location.x, 50.0000);
235        assert_eq!(layout.children[0].location.y, 0.0000);
236
237        assert_eq!(layout.children[1].size.width, 50.0000);
238        assert_eq!(layout.children[1].size.height, 50.0000);
239        assert_eq!(layout.children[1].location.x, 150.0000);
240        assert_eq!(layout.children[1].location.y, 0.0000);
241    }
242
243    #[test]
244    fn rounding_flex_basis_overrides_main_size() {
245        let layout = stretch::compute(
246            &stretch::style::Node {
247                flex_direction: stretch::style::FlexDirection::Column,
248                size: stretch::geometry::Size {
249                    width: stretch::style::Dimension::Points(100.0000),
250                    height: stretch::style::Dimension::Points(113.0000),
251                    ..Default::default()
252                },
253                children: vec![
254                    stretch::style::Node {
255                        flex_grow: 1.0000,
256                        flex_basis: stretch::style::Dimension::Points(50.0000),
257                        size: stretch::geometry::Size {
258                            height: stretch::style::Dimension::Points(20.0000),
259                            ..Default::default()
260                        },
261                        ..Default::default()
262                    },
263                    stretch::style::Node {
264                        flex_grow: 1.0000,
265                        size: stretch::geometry::Size {
266                            height: stretch::style::Dimension::Points(10.0000),
267                            ..Default::default()
268                        },
269                        ..Default::default()
270                    },
271                    stretch::style::Node {
272                        flex_grow: 1.0000,
273                        size: stretch::geometry::Size {
274                            height: stretch::style::Dimension::Points(10.0000),
275                            ..Default::default()
276                        },
277                        ..Default::default()
278                    },
279                ],
280                ..Default::default()
281            },
282            stretch::geometry::Size::undefined(),
283        )
284        .unwrap();
285
286        assert_eq!(layout.size.width, 100.0000);
287        assert_eq!(layout.size.height, 113.0000);
288        assert_eq!(layout.location.x, 0.0000);
289        assert_eq!(layout.location.y, 0.0000);
290
291        assert_eq!(layout.children[0].size.width, 100.0000);
292        assert_eq!(layout.children[0].size.height, 64.0000);
293        assert_eq!(layout.children[0].location.x, 0.0000);
294        assert_eq!(layout.children[0].location.y, 0.0000);
295
296        assert_eq!(layout.children[1].size.width, 100.0000);
297        assert_eq!(layout.children[1].size.height, 25.0000);
298        assert_eq!(layout.children[1].location.x, 0.0000);
299        assert_eq!(layout.children[1].location.y, 64.0000);
300
301        assert_eq!(layout.children[2].size.width, 100.0000);
302        assert_eq!(layout.children[2].size.height, 24.0000);
303        assert_eq!(layout.children[2].location.x, 0.0000);
304        assert_eq!(layout.children[2].location.y, 89.0000);
305    }
306
307    #[test]
308    fn percentage_flex_basis() {
309        let layout = stretch::compute(
310            &stretch::style::Node {
311                size: stretch::geometry::Size {
312                    width: stretch::style::Dimension::Points(200.0000),
313                    height: stretch::style::Dimension::Points(200.0000),
314                    ..Default::default()
315                },
316                children: vec![
317                    stretch::style::Node {
318                        flex_grow: 1.0000,
319                        flex_basis: stretch::style::Dimension::Percent(0.5000),
320                        ..Default::default()
321                    },
322                    stretch::style::Node {
323                        flex_grow: 1.0000,
324                        flex_basis: stretch::style::Dimension::Percent(0.2500),
325                        ..Default::default()
326                    },
327                ],
328                ..Default::default()
329            },
330            stretch::geometry::Size::undefined(),
331        )
332        .unwrap();
333
334        assert_eq!(layout.size.width, 200.0000);
335        assert_eq!(layout.size.height, 200.0000);
336        assert_eq!(layout.location.x, 0.0000);
337        assert_eq!(layout.location.y, 0.0000);
338
339        assert_eq!(layout.children[0].size.width, 125.0000);
340        assert_eq!(layout.children[0].size.height, 200.0000);
341        assert_eq!(layout.children[0].location.x, 0.0000);
342        assert_eq!(layout.children[0].location.y, 0.0000);
343
344        assert_eq!(layout.children[1].size.width, 75.0000);
345        assert_eq!(layout.children[1].size.height, 200.0000);
346        assert_eq!(layout.children[1].location.x, 125.0000);
347        assert_eq!(layout.children[1].location.y, 0.0000);
348    }
349
350    #[test]
351    fn rounding_fractial_input_3() {
352        let layout = stretch::compute(
353            &stretch::style::Node {
354                flex_direction: stretch::style::FlexDirection::Column,
355                size: stretch::geometry::Size {
356                    width: stretch::style::Dimension::Points(100.0000),
357                    height: stretch::style::Dimension::Points(113.4000),
358                    ..Default::default()
359                },
360                children: vec![
361                    stretch::style::Node {
362                        flex_grow: 1.0000,
363                        flex_basis: stretch::style::Dimension::Points(50.0000),
364                        size: stretch::geometry::Size {
365                            height: stretch::style::Dimension::Points(20.0000),
366                            ..Default::default()
367                        },
368                        ..Default::default()
369                    },
370                    stretch::style::Node {
371                        flex_grow: 1.0000,
372                        size: stretch::geometry::Size {
373                            height: stretch::style::Dimension::Points(10.0000),
374                            ..Default::default()
375                        },
376                        ..Default::default()
377                    },
378                    stretch::style::Node {
379                        flex_grow: 1.0000,
380                        size: stretch::geometry::Size {
381                            height: stretch::style::Dimension::Points(10.0000),
382                            ..Default::default()
383                        },
384                        ..Default::default()
385                    },
386                ],
387                ..Default::default()
388            },
389            stretch::geometry::Size::undefined(),
390        )
391        .unwrap();
392
393        assert_eq!(layout.size.width, 100.0000);
394        assert_eq!(layout.size.height, 113.0000);
395        assert_eq!(layout.location.x, 0.0000);
396        assert_eq!(layout.location.y, 0.0000);
397
398        assert_eq!(layout.children[0].size.width, 100.0000);
399        assert_eq!(layout.children[0].size.height, 64.0000);
400        assert_eq!(layout.children[0].location.x, 0.0000);
401        assert_eq!(layout.children[0].location.y, 0.0000);
402
403        assert_eq!(layout.children[1].size.width, 100.0000);
404        assert_eq!(layout.children[1].size.height, 25.0000);
405        assert_eq!(layout.children[1].location.x, 0.0000);
406        assert_eq!(layout.children[1].location.y, 64.0000);
407
408        assert_eq!(layout.children[2].size.width, 100.0000);
409        assert_eq!(layout.children[2].size.height, 24.0000);
410        assert_eq!(layout.children[2].location.x, 0.0000);
411        assert_eq!(layout.children[2].location.y, 89.0000);
412    }
413
414    #[test]
415    fn margin_and_stretch_column() {
416        let layout = stretch::compute(
417            &stretch::style::Node {
418                flex_direction: stretch::style::FlexDirection::Column,
419                size: stretch::geometry::Size {
420                    width: stretch::style::Dimension::Points(100.0000),
421                    height: stretch::style::Dimension::Points(100.0000),
422                    ..Default::default()
423                },
424                children: vec![stretch::style::Node {
425                    flex_grow: 1.0000,
426                    margin: stretch::geometry::Rect {
427                        start: stretch::style::Dimension::Points(10.0000),
428                        end: stretch::style::Dimension::Points(10.0000),
429                        ..Default::default()
430                    },
431                    ..Default::default()
432                }],
433                ..Default::default()
434            },
435            stretch::geometry::Size::undefined(),
436        )
437        .unwrap();
438
439        assert_eq!(layout.size.width, 100.0000);
440        assert_eq!(layout.size.height, 100.0000);
441        assert_eq!(layout.location.x, 0.0000);
442        assert_eq!(layout.location.y, 0.0000);
443
444        assert_eq!(layout.children[0].size.width, 80.0000);
445        assert_eq!(layout.children[0].size.height, 100.0000);
446        assert_eq!(layout.children[0].location.x, 10.0000);
447        assert_eq!(layout.children[0].location.y, 0.0000);
448    }
449
450    #[test]
451    fn wrapped_column_max_height_flex() {
452        let layout = stretch::compute(
453            &stretch::style::Node {
454                flex_direction: stretch::style::FlexDirection::Column,
455                flex_wrap: stretch::style::FlexWrap::Wrap,
456                align_items: stretch::style::AlignItems::Center,
457                align_content: stretch::style::AlignContent::Center,
458                justify_content: stretch::style::JustifyContent::Center,
459                size: stretch::geometry::Size {
460                    width: stretch::style::Dimension::Points(700.0000),
461                    height: stretch::style::Dimension::Points(500.0000),
462                    ..Default::default()
463                },
464                children: vec![
465                    stretch::style::Node {
466                        flex_grow: 1.0000,
467                        flex_shrink: 1.0000,
468                        flex_basis: stretch::style::Dimension::Percent(0.0000),
469                        size: stretch::geometry::Size {
470                            width: stretch::style::Dimension::Points(100.0000),
471                            height: stretch::style::Dimension::Points(500.0000),
472                            ..Default::default()
473                        },
474                        max_size: stretch::geometry::Size {
475                            height: stretch::style::Dimension::Points(200.0000),
476                            ..Default::default()
477                        },
478                        ..Default::default()
479                    },
480                    stretch::style::Node {
481                        flex_grow: 1.0000,
482                        flex_shrink: 1.0000,
483                        flex_basis: stretch::style::Dimension::Percent(0.0000),
484                        size: stretch::geometry::Size {
485                            width: stretch::style::Dimension::Points(200.0000),
486                            height: stretch::style::Dimension::Points(200.0000),
487                            ..Default::default()
488                        },
489                        margin: stretch::geometry::Rect {
490                            start: stretch::style::Dimension::Points(20.0000),
491                            end: stretch::style::Dimension::Points(20.0000),
492                            top: stretch::style::Dimension::Points(20.0000),
493                            bottom: stretch::style::Dimension::Points(20.0000),
494                            ..Default::default()
495                        },
496                        ..Default::default()
497                    },
498                    stretch::style::Node {
499                        size: stretch::geometry::Size {
500                            width: stretch::style::Dimension::Points(100.0000),
501                            height: stretch::style::Dimension::Points(100.0000),
502                            ..Default::default()
503                        },
504                        ..Default::default()
505                    },
506                ],
507                ..Default::default()
508            },
509            stretch::geometry::Size::undefined(),
510        )
511        .unwrap();
512
513        assert_eq!(layout.size.width, 700.0000);
514        assert_eq!(layout.size.height, 500.0000);
515        assert_eq!(layout.location.x, 0.0000);
516        assert_eq!(layout.location.y, 0.0000);
517
518        assert_eq!(layout.children[0].size.width, 100.0000);
519        assert_eq!(layout.children[0].size.height, 180.0000);
520        assert_eq!(layout.children[0].location.x, 300.0000);
521        assert_eq!(layout.children[0].location.y, 0.0000);
522
523        assert_eq!(layout.children[1].size.width, 200.0000);
524        assert_eq!(layout.children[1].size.height, 180.0000);
525        assert_eq!(layout.children[1].location.x, 250.0000);
526        assert_eq!(layout.children[1].location.y, 200.0000);
527
528        assert_eq!(layout.children[2].size.width, 100.0000);
529        assert_eq!(layout.children[2].size.height, 100.0000);
530        assert_eq!(layout.children[2].location.x, 300.0000);
531        assert_eq!(layout.children[2].location.y, 400.0000);
532    }
533
534    #[test]
535    fn align_baseline_nested_child() {
536        let layout = stretch::compute(
537            &stretch::style::Node {
538                align_items: stretch::style::AlignItems::Baseline,
539                size: stretch::geometry::Size {
540                    width: stretch::style::Dimension::Points(100.0000),
541                    height: stretch::style::Dimension::Points(100.0000),
542                    ..Default::default()
543                },
544                children: vec![
545                    stretch::style::Node {
546                        size: stretch::geometry::Size {
547                            width: stretch::style::Dimension::Points(50.0000),
548                            height: stretch::style::Dimension::Points(50.0000),
549                            ..Default::default()
550                        },
551                        ..Default::default()
552                    },
553                    stretch::style::Node {
554                        flex_direction: stretch::style::FlexDirection::Column,
555                        size: stretch::geometry::Size {
556                            width: stretch::style::Dimension::Points(50.0000),
557                            height: stretch::style::Dimension::Points(20.0000),
558                            ..Default::default()
559                        },
560                        children: vec![stretch::style::Node {
561                            size: stretch::geometry::Size {
562                                width: stretch::style::Dimension::Points(50.0000),
563                                height: stretch::style::Dimension::Points(10.0000),
564                                ..Default::default()
565                            },
566                            ..Default::default()
567                        }],
568                        ..Default::default()
569                    },
570                ],
571                ..Default::default()
572            },
573            stretch::geometry::Size::undefined(),
574        )
575        .unwrap();
576
577        assert_eq!(layout.size.width, 100.0000);
578        assert_eq!(layout.size.height, 100.0000);
579        assert_eq!(layout.location.x, 0.0000);
580        assert_eq!(layout.location.y, 0.0000);
581
582        assert_eq!(layout.children[0].size.width, 50.0000);
583        assert_eq!(layout.children[0].size.height, 50.0000);
584        assert_eq!(layout.children[0].location.x, 0.0000);
585        assert_eq!(layout.children[0].location.y, 0.0000);
586
587        assert_eq!(layout.children[1].size.width, 50.0000);
588        assert_eq!(layout.children[1].size.height, 20.0000);
589        assert_eq!(layout.children[1].location.x, 50.0000);
590        assert_eq!(layout.children[1].location.y, 40.0000);
591
592        assert_eq!(layout.children[1].children[0].size.width, 50.0000);
593        assert_eq!(layout.children[1].children[0].size.height, 10.0000);
594        assert_eq!(layout.children[1].children[0].location.x, 0.0000);
595        assert_eq!(layout.children[1].children[0].location.y, 0.0000);
596    }
597
598    #[test]
599    fn max_height_overrides_height_on_root() {
600        let layout = stretch::compute(
601            &stretch::style::Node {
602                size: stretch::geometry::Size {
603                    height: stretch::style::Dimension::Points(200.0000),
604                    ..Default::default()
605                },
606                max_size: stretch::geometry::Size {
607                    height: stretch::style::Dimension::Points(100.0000),
608                    ..Default::default()
609                },
610                ..Default::default()
611            },
612            stretch::geometry::Size::undefined(),
613        )
614        .unwrap();
615
616        assert_eq!(layout.size.width, 0.0000);
617        assert_eq!(layout.size.height, 100.0000);
618        assert_eq!(layout.location.x, 0.0000);
619        assert_eq!(layout.location.y, 0.0000);
620    }
621
622    #[test]
623    fn padding_center_child() {
624        let layout = stretch::compute(
625            &stretch::style::Node {
626                align_items: stretch::style::AlignItems::Center,
627                justify_content: stretch::style::JustifyContent::Center,
628                size: stretch::geometry::Size {
629                    width: stretch::style::Dimension::Points(100.0000),
630                    height: stretch::style::Dimension::Points(100.0000),
631                    ..Default::default()
632                },
633                padding: stretch::geometry::Rect {
634                    start: stretch::style::Dimension::Points(10.0000),
635                    end: stretch::style::Dimension::Points(20.0000),
636                    top: stretch::style::Dimension::Points(10.0000),
637                    bottom: stretch::style::Dimension::Points(20.0000),
638                    ..Default::default()
639                },
640                children: vec![stretch::style::Node {
641                    size: stretch::geometry::Size {
642                        width: stretch::style::Dimension::Points(10.0000),
643                        height: stretch::style::Dimension::Points(10.0000),
644                        ..Default::default()
645                    },
646                    ..Default::default()
647                }],
648                ..Default::default()
649            },
650            stretch::geometry::Size::undefined(),
651        )
652        .unwrap();
653
654        assert_eq!(layout.size.width, 100.0000);
655        assert_eq!(layout.size.height, 100.0000);
656        assert_eq!(layout.location.x, 0.0000);
657        assert_eq!(layout.location.y, 0.0000);
658
659        assert_eq!(layout.children[0].size.width, 10.0000);
660        assert_eq!(layout.children[0].size.height, 10.0000);
661        assert_eq!(layout.children[0].location.x, 40.0000);
662        assert_eq!(layout.children[0].location.y, 40.0000);
663    }
664
665    #[test]
666    fn align_flex_start_with_stretching_children() {
667        let layout = stretch::compute(
668            &stretch::style::Node {
669                size: stretch::geometry::Size {
670                    width: stretch::style::Dimension::Points(500.0000),
671                    height: stretch::style::Dimension::Points(500.0000),
672                    ..Default::default()
673                },
674                children: vec![stretch::style::Node {
675                    children: vec![stretch::style::Node {
676                        flex_grow: 1.0000,
677                        flex_shrink: 1.0000,
678                        children: vec![stretch::style::Node {
679                            flex_grow: 1.0000,
680                            flex_shrink: 1.0000,
681                            ..Default::default()
682                        }],
683                        ..Default::default()
684                    }],
685                    ..Default::default()
686                }],
687                ..Default::default()
688            },
689            stretch::geometry::Size::undefined(),
690        )
691        .unwrap();
692
693        assert_eq!(layout.size.width, 500.0000);
694        assert_eq!(layout.size.height, 500.0000);
695        assert_eq!(layout.location.x, 0.0000);
696        assert_eq!(layout.location.y, 0.0000);
697
698        assert_eq!(layout.children[0].size.width, 0.0000);
699        assert_eq!(layout.children[0].size.height, 500.0000);
700        assert_eq!(layout.children[0].location.x, 0.0000);
701        assert_eq!(layout.children[0].location.y, 0.0000);
702
703        assert_eq!(layout.children[0].children[0].size.width, 0.0000);
704        assert_eq!(layout.children[0].children[0].size.height, 500.0000);
705        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
706        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
707
708        assert_eq!(layout.children[0].children[0].children[0].size.width, 0.0000);
709        assert_eq!(layout.children[0].children[0].children[0].size.height, 500.0000);
710        assert_eq!(layout.children[0].children[0].children[0].location.x, 0.0000);
711        assert_eq!(layout.children[0].children[0].children[0].location.y, 0.0000);
712    }
713
714    #[test]
715    fn min_width_overrides_width() {
716        let layout = stretch::compute(
717            &stretch::style::Node {
718                children: vec![stretch::style::Node {
719                    size: stretch::geometry::Size {
720                        width: stretch::style::Dimension::Points(50.0000),
721                        ..Default::default()
722                    },
723                    min_size: stretch::geometry::Size {
724                        width: stretch::style::Dimension::Points(100.0000),
725                        ..Default::default()
726                    },
727                    ..Default::default()
728                }],
729                ..Default::default()
730            },
731            stretch::geometry::Size::undefined(),
732        )
733        .unwrap();
734
735        assert_eq!(layout.size.width, 100.0000);
736        assert_eq!(layout.size.height, 0.0000);
737        assert_eq!(layout.location.x, 0.0000);
738        assert_eq!(layout.location.y, 0.0000);
739
740        assert_eq!(layout.children[0].size.width, 100.0000);
741        assert_eq!(layout.children[0].size.height, 0.0000);
742        assert_eq!(layout.children[0].location.x, 0.0000);
743        assert_eq!(layout.children[0].location.y, 0.0000);
744    }
745
746    #[test]
747    fn flex_wrap_align_stretch_fits_one_row() {
748        let layout = stretch::compute(
749            &stretch::style::Node {
750                flex_wrap: stretch::style::FlexWrap::Wrap,
751                size: stretch::geometry::Size {
752                    width: stretch::style::Dimension::Points(150.0000),
753                    height: stretch::style::Dimension::Points(100.0000),
754                    ..Default::default()
755                },
756                children: vec![
757                    stretch::style::Node {
758                        size: stretch::geometry::Size {
759                            width: stretch::style::Dimension::Points(50.0000),
760                            ..Default::default()
761                        },
762                        ..Default::default()
763                    },
764                    stretch::style::Node {
765                        size: stretch::geometry::Size {
766                            width: stretch::style::Dimension::Points(50.0000),
767                            ..Default::default()
768                        },
769                        ..Default::default()
770                    },
771                ],
772                ..Default::default()
773            },
774            stretch::geometry::Size::undefined(),
775        )
776        .unwrap();
777
778        assert_eq!(layout.size.width, 150.0000);
779        assert_eq!(layout.size.height, 100.0000);
780        assert_eq!(layout.location.x, 0.0000);
781        assert_eq!(layout.location.y, 0.0000);
782
783        assert_eq!(layout.children[0].size.width, 50.0000);
784        assert_eq!(layout.children[0].size.height, 100.0000);
785        assert_eq!(layout.children[0].location.x, 0.0000);
786        assert_eq!(layout.children[0].location.y, 0.0000);
787
788        assert_eq!(layout.children[1].size.width, 50.0000);
789        assert_eq!(layout.children[1].size.height, 100.0000);
790        assert_eq!(layout.children[1].location.x, 50.0000);
791        assert_eq!(layout.children[1].location.y, 0.0000);
792    }
793
794    #[test]
795    fn justify_content_row_space_evenly() {
796        let layout = stretch::compute(
797            &stretch::style::Node {
798                justify_content: stretch::style::JustifyContent::SpaceEvenly,
799                size: stretch::geometry::Size {
800                    width: stretch::style::Dimension::Points(100.0000),
801                    height: stretch::style::Dimension::Points(100.0000),
802                    ..Default::default()
803                },
804                children: vec![
805                    stretch::style::Node {
806                        size: stretch::geometry::Size {
807                            height: stretch::style::Dimension::Points(10.0000),
808                            ..Default::default()
809                        },
810                        ..Default::default()
811                    },
812                    stretch::style::Node {
813                        size: stretch::geometry::Size {
814                            height: stretch::style::Dimension::Points(10.0000),
815                            ..Default::default()
816                        },
817                        ..Default::default()
818                    },
819                    stretch::style::Node {
820                        size: stretch::geometry::Size {
821                            height: stretch::style::Dimension::Points(10.0000),
822                            ..Default::default()
823                        },
824                        ..Default::default()
825                    },
826                ],
827                ..Default::default()
828            },
829            stretch::geometry::Size::undefined(),
830        )
831        .unwrap();
832
833        assert_eq!(layout.size.width, 100.0000);
834        assert_eq!(layout.size.height, 100.0000);
835        assert_eq!(layout.location.x, 0.0000);
836        assert_eq!(layout.location.y, 0.0000);
837
838        assert_eq!(layout.children[0].size.width, 0.0000);
839        assert_eq!(layout.children[0].size.height, 10.0000);
840        assert_eq!(layout.children[0].location.x, 25.0000);
841        assert_eq!(layout.children[0].location.y, 0.0000);
842
843        assert_eq!(layout.children[1].size.width, 0.0000);
844        assert_eq!(layout.children[1].size.height, 10.0000);
845        assert_eq!(layout.children[1].location.x, 50.0000);
846        assert_eq!(layout.children[1].location.y, 0.0000);
847
848        assert_eq!(layout.children[2].size.width, 0.0000);
849        assert_eq!(layout.children[2].size.height, 10.0000);
850        assert_eq!(layout.children[2].location.x, 75.0000);
851        assert_eq!(layout.children[2].location.y, 0.0000);
852    }
853
854    #[test]
855    fn absolute_layout_child_order() {
856        let layout = stretch::compute(
857            &stretch::style::Node {
858                align_items: stretch::style::AlignItems::Center,
859                justify_content: stretch::style::JustifyContent::Center,
860                size: stretch::geometry::Size {
861                    width: stretch::style::Dimension::Points(110.0000),
862                    height: stretch::style::Dimension::Points(100.0000),
863                    ..Default::default()
864                },
865                children: vec![
866                    stretch::style::Node {
867                        size: stretch::geometry::Size {
868                            width: stretch::style::Dimension::Points(60.0000),
869                            height: stretch::style::Dimension::Points(40.0000),
870                            ..Default::default()
871                        },
872                        ..Default::default()
873                    },
874                    stretch::style::Node {
875                        position_type: stretch::style::PositionType::Absolute,
876                        size: stretch::geometry::Size {
877                            width: stretch::style::Dimension::Points(60.0000),
878                            height: stretch::style::Dimension::Points(40.0000),
879                            ..Default::default()
880                        },
881                        ..Default::default()
882                    },
883                    stretch::style::Node {
884                        size: stretch::geometry::Size {
885                            width: stretch::style::Dimension::Points(60.0000),
886                            height: stretch::style::Dimension::Points(40.0000),
887                            ..Default::default()
888                        },
889                        ..Default::default()
890                    },
891                ],
892                ..Default::default()
893            },
894            stretch::geometry::Size::undefined(),
895        )
896        .unwrap();
897
898        assert_eq!(layout.size.width, 110.0000);
899        assert_eq!(layout.size.height, 100.0000);
900        assert_eq!(layout.location.x, 0.0000);
901        assert_eq!(layout.location.y, 0.0000);
902
903        assert_eq!(layout.children[0].size.width, 55.0000);
904        assert_eq!(layout.children[0].size.height, 40.0000);
905        assert_eq!(layout.children[0].location.x, 0.0000);
906        assert_eq!(layout.children[0].location.y, 30.0000);
907
908        assert_eq!(layout.children[1].size.width, 60.0000);
909        assert_eq!(layout.children[1].size.height, 40.0000);
910        assert_eq!(layout.children[1].location.x, 25.0000);
911        assert_eq!(layout.children[1].location.y, 30.0000);
912
913        assert_eq!(layout.children[2].size.width, 55.0000);
914        assert_eq!(layout.children[2].size.height, 40.0000);
915        assert_eq!(layout.children[2].location.x, 55.0000);
916        assert_eq!(layout.children[2].location.y, 30.0000);
917    }
918
919    #[test]
920    fn absolute_layout_percentage_bottom_based_on_parent_height() {
921        let layout = stretch::compute(
922            &stretch::style::Node {
923                size: stretch::geometry::Size {
924                    width: stretch::style::Dimension::Points(100.0000),
925                    height: stretch::style::Dimension::Points(200.0000),
926                    ..Default::default()
927                },
928                children: vec![
929                    stretch::style::Node {
930                        position_type: stretch::style::PositionType::Absolute,
931                        size: stretch::geometry::Size {
932                            width: stretch::style::Dimension::Points(10.0000),
933                            height: stretch::style::Dimension::Points(10.0000),
934                            ..Default::default()
935                        },
936                        position: stretch::geometry::Rect {
937                            top: stretch::style::Dimension::Percent(0.5000),
938                            ..Default::default()
939                        },
940                        ..Default::default()
941                    },
942                    stretch::style::Node {
943                        position_type: stretch::style::PositionType::Absolute,
944                        size: stretch::geometry::Size {
945                            width: stretch::style::Dimension::Points(10.0000),
946                            height: stretch::style::Dimension::Points(10.0000),
947                            ..Default::default()
948                        },
949                        position: stretch::geometry::Rect {
950                            bottom: stretch::style::Dimension::Percent(0.5000),
951                            ..Default::default()
952                        },
953                        ..Default::default()
954                    },
955                    stretch::style::Node {
956                        position_type: stretch::style::PositionType::Absolute,
957                        size: stretch::geometry::Size {
958                            width: stretch::style::Dimension::Points(10.0000),
959                            ..Default::default()
960                        },
961                        position: stretch::geometry::Rect {
962                            top: stretch::style::Dimension::Percent(0.1000),
963                            bottom: stretch::style::Dimension::Percent(0.1000),
964                            ..Default::default()
965                        },
966                        ..Default::default()
967                    },
968                ],
969                ..Default::default()
970            },
971            stretch::geometry::Size::undefined(),
972        )
973        .unwrap();
974
975        assert_eq!(layout.size.width, 100.0000);
976        assert_eq!(layout.size.height, 200.0000);
977        assert_eq!(layout.location.x, 0.0000);
978        assert_eq!(layout.location.y, 0.0000);
979
980        assert_eq!(layout.children[0].size.width, 10.0000);
981        assert_eq!(layout.children[0].size.height, 10.0000);
982        assert_eq!(layout.children[0].location.x, 0.0000);
983        assert_eq!(layout.children[0].location.y, 100.0000);
984
985        assert_eq!(layout.children[1].size.width, 10.0000);
986        assert_eq!(layout.children[1].size.height, 10.0000);
987        assert_eq!(layout.children[1].location.x, 0.0000);
988        assert_eq!(layout.children[1].location.y, 90.0000);
989
990        assert_eq!(layout.children[2].size.width, 10.0000);
991        assert_eq!(layout.children[2].size.height, 160.0000);
992        assert_eq!(layout.children[2].location.x, 0.0000);
993        assert_eq!(layout.children[2].location.y, 20.0000);
994    }
995
996    #[test]
997    fn absolute_layout_align_items_and_justify_content_flex_end() {
998        let layout = stretch::compute(
999            &stretch::style::Node {
1000                align_items: stretch::style::AlignItems::FlexEnd,
1001                justify_content: stretch::style::JustifyContent::FlexEnd,
1002                size: stretch::geometry::Size {
1003                    width: stretch::style::Dimension::Points(110.0000),
1004                    height: stretch::style::Dimension::Points(100.0000),
1005                    ..Default::default()
1006                },
1007                children: vec![stretch::style::Node {
1008                    position_type: stretch::style::PositionType::Absolute,
1009                    size: stretch::geometry::Size {
1010                        width: stretch::style::Dimension::Points(60.0000),
1011                        height: stretch::style::Dimension::Points(40.0000),
1012                        ..Default::default()
1013                    },
1014                    ..Default::default()
1015                }],
1016                ..Default::default()
1017            },
1018            stretch::geometry::Size::undefined(),
1019        )
1020        .unwrap();
1021
1022        assert_eq!(layout.size.width, 110.0000);
1023        assert_eq!(layout.size.height, 100.0000);
1024        assert_eq!(layout.location.x, 0.0000);
1025        assert_eq!(layout.location.y, 0.0000);
1026
1027        assert_eq!(layout.children[0].size.width, 60.0000);
1028        assert_eq!(layout.children[0].size.height, 40.0000);
1029        assert_eq!(layout.children[0].location.x, 50.0000);
1030        assert_eq!(layout.children[0].location.y, 60.0000);
1031    }
1032
1033    #[test]
1034    fn nested_overflowing_child() {
1035        let layout = stretch::compute(
1036            &stretch::style::Node {
1037                size: stretch::geometry::Size {
1038                    width: stretch::style::Dimension::Points(100.0000),
1039                    height: stretch::style::Dimension::Points(100.0000),
1040                    ..Default::default()
1041                },
1042                children: vec![stretch::style::Node {
1043                    children: vec![stretch::style::Node {
1044                        size: stretch::geometry::Size {
1045                            width: stretch::style::Dimension::Points(200.0000),
1046                            height: stretch::style::Dimension::Points(200.0000),
1047                            ..Default::default()
1048                        },
1049                        ..Default::default()
1050                    }],
1051                    ..Default::default()
1052                }],
1053                ..Default::default()
1054            },
1055            stretch::geometry::Size::undefined(),
1056        )
1057        .unwrap();
1058
1059        assert_eq!(layout.size.width, 100.0000);
1060        assert_eq!(layout.size.height, 100.0000);
1061        assert_eq!(layout.location.x, 0.0000);
1062        assert_eq!(layout.location.y, 0.0000);
1063
1064        assert_eq!(layout.children[0].size.width, 200.0000);
1065        assert_eq!(layout.children[0].size.height, 100.0000);
1066        assert_eq!(layout.children[0].location.x, 0.0000);
1067        assert_eq!(layout.children[0].location.y, 0.0000);
1068
1069        assert_eq!(layout.children[0].children[0].size.width, 200.0000);
1070        assert_eq!(layout.children[0].children[0].size.height, 200.0000);
1071        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
1072        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
1073    }
1074
1075    #[test]
1076    fn flex_direction_row() {
1077        let layout = stretch::compute(
1078            &stretch::style::Node {
1079                size: stretch::geometry::Size {
1080                    width: stretch::style::Dimension::Points(100.0000),
1081                    height: stretch::style::Dimension::Points(100.0000),
1082                    ..Default::default()
1083                },
1084                children: vec![
1085                    stretch::style::Node {
1086                        size: stretch::geometry::Size {
1087                            width: stretch::style::Dimension::Points(10.0000),
1088                            ..Default::default()
1089                        },
1090                        ..Default::default()
1091                    },
1092                    stretch::style::Node {
1093                        size: stretch::geometry::Size {
1094                            width: stretch::style::Dimension::Points(10.0000),
1095                            ..Default::default()
1096                        },
1097                        ..Default::default()
1098                    },
1099                    stretch::style::Node {
1100                        size: stretch::geometry::Size {
1101                            width: stretch::style::Dimension::Points(10.0000),
1102                            ..Default::default()
1103                        },
1104                        ..Default::default()
1105                    },
1106                ],
1107                ..Default::default()
1108            },
1109            stretch::geometry::Size::undefined(),
1110        )
1111        .unwrap();
1112
1113        assert_eq!(layout.size.width, 100.0000);
1114        assert_eq!(layout.size.height, 100.0000);
1115        assert_eq!(layout.location.x, 0.0000);
1116        assert_eq!(layout.location.y, 0.0000);
1117
1118        assert_eq!(layout.children[0].size.width, 10.0000);
1119        assert_eq!(layout.children[0].size.height, 100.0000);
1120        assert_eq!(layout.children[0].location.x, 0.0000);
1121        assert_eq!(layout.children[0].location.y, 0.0000);
1122
1123        assert_eq!(layout.children[1].size.width, 10.0000);
1124        assert_eq!(layout.children[1].size.height, 100.0000);
1125        assert_eq!(layout.children[1].location.x, 10.0000);
1126        assert_eq!(layout.children[1].location.y, 0.0000);
1127
1128        assert_eq!(layout.children[2].size.width, 10.0000);
1129        assert_eq!(layout.children[2].size.height, 100.0000);
1130        assert_eq!(layout.children[2].location.x, 20.0000);
1131        assert_eq!(layout.children[2].location.y, 0.0000);
1132    }
1133
1134    #[test]
1135    fn child_min_max_width_flexing() {
1136        let layout = stretch::compute(
1137            &stretch::style::Node {
1138                size: stretch::geometry::Size {
1139                    width: stretch::style::Dimension::Points(120.0000),
1140                    height: stretch::style::Dimension::Points(50.0000),
1141                    ..Default::default()
1142                },
1143                children: vec![
1144                    stretch::style::Node {
1145                        flex_grow: 1.0000,
1146                        flex_shrink: 0.0000,
1147                        flex_basis: stretch::style::Dimension::Points(0.0000),
1148                        min_size: stretch::geometry::Size {
1149                            width: stretch::style::Dimension::Points(60.0000),
1150                            ..Default::default()
1151                        },
1152                        ..Default::default()
1153                    },
1154                    stretch::style::Node {
1155                        flex_grow: 1.0000,
1156                        flex_shrink: 0.0000,
1157                        flex_basis: stretch::style::Dimension::Percent(0.5000),
1158                        max_size: stretch::geometry::Size {
1159                            width: stretch::style::Dimension::Points(20.0000),
1160                            ..Default::default()
1161                        },
1162                        ..Default::default()
1163                    },
1164                ],
1165                ..Default::default()
1166            },
1167            stretch::geometry::Size::undefined(),
1168        )
1169        .unwrap();
1170
1171        assert_eq!(layout.size.width, 120.0000);
1172        assert_eq!(layout.size.height, 50.0000);
1173        assert_eq!(layout.location.x, 0.0000);
1174        assert_eq!(layout.location.y, 0.0000);
1175
1176        assert_eq!(layout.children[0].size.width, 100.0000);
1177        assert_eq!(layout.children[0].size.height, 50.0000);
1178        assert_eq!(layout.children[0].location.x, 0.0000);
1179        assert_eq!(layout.children[0].location.y, 0.0000);
1180
1181        assert_eq!(layout.children[1].size.width, 20.0000);
1182        assert_eq!(layout.children[1].size.height, 50.0000);
1183        assert_eq!(layout.children[1].location.x, 100.0000);
1184        assert_eq!(layout.children[1].location.y, 0.0000);
1185    }
1186
1187    #[test]
1188    fn absolute_layout_in_wrap_reverse_row_container_flex_end() {
1189        let layout = stretch::compute(
1190            &stretch::style::Node {
1191                flex_wrap: stretch::style::FlexWrap::WrapReverse,
1192                size: stretch::geometry::Size {
1193                    width: stretch::style::Dimension::Points(100.0000),
1194                    height: stretch::style::Dimension::Points(100.0000),
1195                    ..Default::default()
1196                },
1197                children: vec![stretch::style::Node {
1198                    position_type: stretch::style::PositionType::Absolute,
1199                    align_self: stretch::style::AlignSelf::FlexEnd,
1200                    size: stretch::geometry::Size {
1201                        width: stretch::style::Dimension::Points(20.0000),
1202                        height: stretch::style::Dimension::Points(20.0000),
1203                        ..Default::default()
1204                    },
1205                    ..Default::default()
1206                }],
1207                ..Default::default()
1208            },
1209            stretch::geometry::Size::undefined(),
1210        )
1211        .unwrap();
1212
1213        assert_eq!(layout.size.width, 100.0000);
1214        assert_eq!(layout.size.height, 100.0000);
1215        assert_eq!(layout.location.x, 0.0000);
1216        assert_eq!(layout.location.y, 0.0000);
1217
1218        assert_eq!(layout.children[0].size.width, 20.0000);
1219        assert_eq!(layout.children[0].size.height, 20.0000);
1220        assert_eq!(layout.children[0].location.x, 0.0000);
1221        assert_eq!(layout.children[0].location.y, 0.0000);
1222    }
1223
1224    #[test]
1225    fn margin_and_flex_column() {
1226        let layout = stretch::compute(
1227            &stretch::style::Node {
1228                flex_direction: stretch::style::FlexDirection::Column,
1229                size: stretch::geometry::Size {
1230                    width: stretch::style::Dimension::Points(100.0000),
1231                    height: stretch::style::Dimension::Points(100.0000),
1232                    ..Default::default()
1233                },
1234                children: vec![stretch::style::Node {
1235                    flex_grow: 1.0000,
1236                    margin: stretch::geometry::Rect {
1237                        top: stretch::style::Dimension::Points(10.0000),
1238                        bottom: stretch::style::Dimension::Points(10.0000),
1239                        ..Default::default()
1240                    },
1241                    ..Default::default()
1242                }],
1243                ..Default::default()
1244            },
1245            stretch::geometry::Size::undefined(),
1246        )
1247        .unwrap();
1248
1249        assert_eq!(layout.size.width, 100.0000);
1250        assert_eq!(layout.size.height, 100.0000);
1251        assert_eq!(layout.location.x, 0.0000);
1252        assert_eq!(layout.location.y, 0.0000);
1253
1254        assert_eq!(layout.children[0].size.width, 100.0000);
1255        assert_eq!(layout.children[0].size.height, 80.0000);
1256        assert_eq!(layout.children[0].location.x, 0.0000);
1257        assert_eq!(layout.children[0].location.y, 10.0000);
1258    }
1259
1260    #[test]
1261    fn flex_basis_flex_shrink_row() {
1262        let layout = stretch::compute(
1263            &stretch::style::Node {
1264                size: stretch::geometry::Size {
1265                    width: stretch::style::Dimension::Points(100.0000),
1266                    height: stretch::style::Dimension::Points(100.0000),
1267                    ..Default::default()
1268                },
1269                children: vec![
1270                    stretch::style::Node {
1271                        flex_basis: stretch::style::Dimension::Points(100.0000),
1272                        ..Default::default()
1273                    },
1274                    stretch::style::Node {
1275                        flex_basis: stretch::style::Dimension::Points(50.0000),
1276                        ..Default::default()
1277                    },
1278                ],
1279                ..Default::default()
1280            },
1281            stretch::geometry::Size::undefined(),
1282        )
1283        .unwrap();
1284
1285        assert_eq!(layout.size.width, 100.0000);
1286        assert_eq!(layout.size.height, 100.0000);
1287        assert_eq!(layout.location.x, 0.0000);
1288        assert_eq!(layout.location.y, 0.0000);
1289
1290        assert_eq!(layout.children[0].size.width, 67.0000);
1291        assert_eq!(layout.children[0].size.height, 100.0000);
1292        assert_eq!(layout.children[0].location.x, 0.0000);
1293        assert_eq!(layout.children[0].location.y, 0.0000);
1294
1295        assert_eq!(layout.children[1].size.width, 33.0000);
1296        assert_eq!(layout.children[1].size.height, 100.0000);
1297        assert_eq!(layout.children[1].location.x, 67.0000);
1298        assert_eq!(layout.children[1].location.y, 0.0000);
1299    }
1300
1301    #[test]
1302    fn justify_content_column_min_height_and_margin_top() {
1303        let layout = stretch::compute(
1304            &stretch::style::Node {
1305                flex_direction: stretch::style::FlexDirection::Column,
1306                justify_content: stretch::style::JustifyContent::Center,
1307                min_size: stretch::geometry::Size {
1308                    height: stretch::style::Dimension::Points(50.0000),
1309                    ..Default::default()
1310                },
1311                children: vec![stretch::style::Node {
1312                    size: stretch::geometry::Size {
1313                        width: stretch::style::Dimension::Points(20.0000),
1314                        height: stretch::style::Dimension::Points(20.0000),
1315                        ..Default::default()
1316                    },
1317                    margin: stretch::geometry::Rect {
1318                        top: stretch::style::Dimension::Points(10.0000),
1319                        ..Default::default()
1320                    },
1321                    ..Default::default()
1322                }],
1323                ..Default::default()
1324            },
1325            stretch::geometry::Size::undefined(),
1326        )
1327        .unwrap();
1328
1329        assert_eq!(layout.size.width, 20.0000);
1330        assert_eq!(layout.size.height, 50.0000);
1331        assert_eq!(layout.location.x, 0.0000);
1332        assert_eq!(layout.location.y, 0.0000);
1333
1334        assert_eq!(layout.children[0].size.width, 20.0000);
1335        assert_eq!(layout.children[0].size.height, 20.0000);
1336        assert_eq!(layout.children[0].location.x, 0.0000);
1337        assert_eq!(layout.children[0].location.y, 20.0000);
1338    }
1339
1340    #[test]
1341    fn justify_content_overflow_min_max() {
1342        let layout = stretch::compute(
1343            &stretch::style::Node {
1344                flex_direction: stretch::style::FlexDirection::Column,
1345                justify_content: stretch::style::JustifyContent::Center,
1346                min_size: stretch::geometry::Size {
1347                    height: stretch::style::Dimension::Points(100.0000),
1348                    ..Default::default()
1349                },
1350                max_size: stretch::geometry::Size {
1351                    height: stretch::style::Dimension::Points(110.0000),
1352                    ..Default::default()
1353                },
1354                children: vec![
1355                    stretch::style::Node {
1356                        flex_shrink: 0.0000,
1357                        size: stretch::geometry::Size {
1358                            width: stretch::style::Dimension::Points(50.0000),
1359                            height: stretch::style::Dimension::Points(50.0000),
1360                            ..Default::default()
1361                        },
1362                        ..Default::default()
1363                    },
1364                    stretch::style::Node {
1365                        flex_shrink: 0.0000,
1366                        size: stretch::geometry::Size {
1367                            width: stretch::style::Dimension::Points(50.0000),
1368                            height: stretch::style::Dimension::Points(50.0000),
1369                            ..Default::default()
1370                        },
1371                        ..Default::default()
1372                    },
1373                    stretch::style::Node {
1374                        flex_shrink: 0.0000,
1375                        size: stretch::geometry::Size {
1376                            width: stretch::style::Dimension::Points(50.0000),
1377                            height: stretch::style::Dimension::Points(50.0000),
1378                            ..Default::default()
1379                        },
1380                        ..Default::default()
1381                    },
1382                ],
1383                ..Default::default()
1384            },
1385            stretch::geometry::Size::undefined(),
1386        )
1387        .unwrap();
1388
1389        assert_eq!(layout.size.width, 50.0000);
1390        assert_eq!(layout.size.height, 110.0000);
1391        assert_eq!(layout.location.x, 0.0000);
1392        assert_eq!(layout.location.y, 0.0000);
1393
1394        assert_eq!(layout.children[0].size.width, 50.0000);
1395        assert_eq!(layout.children[0].size.height, 50.0000);
1396        assert_eq!(layout.children[0].location.x, 0.0000);
1397        assert_eq!(layout.children[0].location.y, -20.0000);
1398
1399        assert_eq!(layout.children[1].size.width, 50.0000);
1400        assert_eq!(layout.children[1].size.height, 50.0000);
1401        assert_eq!(layout.children[1].location.x, 0.0000);
1402        assert_eq!(layout.children[1].location.y, 30.0000);
1403
1404        assert_eq!(layout.children[2].size.width, 50.0000);
1405        assert_eq!(layout.children[2].size.height, 50.0000);
1406        assert_eq!(layout.children[2].location.x, 0.0000);
1407        assert_eq!(layout.children[2].location.y, 80.0000);
1408    }
1409
1410    #[test]
1411    fn wrap_reverse_column_fixed_size() {
1412        let layout = stretch::compute(
1413            &stretch::style::Node {
1414                flex_direction: stretch::style::FlexDirection::Column,
1415                flex_wrap: stretch::style::FlexWrap::WrapReverse,
1416                align_items: stretch::style::AlignItems::Center,
1417                size: stretch::geometry::Size {
1418                    width: stretch::style::Dimension::Points(200.0000),
1419                    height: stretch::style::Dimension::Points(100.0000),
1420                    ..Default::default()
1421                },
1422                children: vec![
1423                    stretch::style::Node {
1424                        size: stretch::geometry::Size {
1425                            width: stretch::style::Dimension::Points(30.0000),
1426                            height: stretch::style::Dimension::Points(10.0000),
1427                            ..Default::default()
1428                        },
1429                        ..Default::default()
1430                    },
1431                    stretch::style::Node {
1432                        size: stretch::geometry::Size {
1433                            width: stretch::style::Dimension::Points(30.0000),
1434                            height: stretch::style::Dimension::Points(20.0000),
1435                            ..Default::default()
1436                        },
1437                        ..Default::default()
1438                    },
1439                    stretch::style::Node {
1440                        size: stretch::geometry::Size {
1441                            width: stretch::style::Dimension::Points(30.0000),
1442                            height: stretch::style::Dimension::Points(30.0000),
1443                            ..Default::default()
1444                        },
1445                        ..Default::default()
1446                    },
1447                    stretch::style::Node {
1448                        size: stretch::geometry::Size {
1449                            width: stretch::style::Dimension::Points(30.0000),
1450                            height: stretch::style::Dimension::Points(40.0000),
1451                            ..Default::default()
1452                        },
1453                        ..Default::default()
1454                    },
1455                    stretch::style::Node {
1456                        size: stretch::geometry::Size {
1457                            width: stretch::style::Dimension::Points(30.0000),
1458                            height: stretch::style::Dimension::Points(50.0000),
1459                            ..Default::default()
1460                        },
1461                        ..Default::default()
1462                    },
1463                ],
1464                ..Default::default()
1465            },
1466            stretch::geometry::Size::undefined(),
1467        )
1468        .unwrap();
1469
1470        assert_eq!(layout.size.width, 200.0000);
1471        assert_eq!(layout.size.height, 100.0000);
1472        assert_eq!(layout.location.x, 0.0000);
1473        assert_eq!(layout.location.y, 0.0000);
1474
1475        assert_eq!(layout.children[0].size.width, 30.0000);
1476        assert_eq!(layout.children[0].size.height, 10.0000);
1477        assert_eq!(layout.children[0].location.x, 135.0000);
1478        assert_eq!(layout.children[0].location.y, 0.0000);
1479
1480        assert_eq!(layout.children[1].size.width, 30.0000);
1481        assert_eq!(layout.children[1].size.height, 20.0000);
1482        assert_eq!(layout.children[1].location.x, 135.0000);
1483        assert_eq!(layout.children[1].location.y, 10.0000);
1484
1485        assert_eq!(layout.children[2].size.width, 30.0000);
1486        assert_eq!(layout.children[2].size.height, 30.0000);
1487        assert_eq!(layout.children[2].location.x, 135.0000);
1488        assert_eq!(layout.children[2].location.y, 30.0000);
1489
1490        assert_eq!(layout.children[3].size.width, 30.0000);
1491        assert_eq!(layout.children[3].size.height, 40.0000);
1492        assert_eq!(layout.children[3].location.x, 135.0000);
1493        assert_eq!(layout.children[3].location.y, 60.0000);
1494
1495        assert_eq!(layout.children[4].size.width, 30.0000);
1496        assert_eq!(layout.children[4].size.height, 50.0000);
1497        assert_eq!(layout.children[4].location.x, 35.0000);
1498        assert_eq!(layout.children[4].location.y, 0.0000);
1499    }
1500
1501    #[test]
1502    fn max_width() {
1503        let layout = stretch::compute(
1504            &stretch::style::Node {
1505                flex_direction: stretch::style::FlexDirection::Column,
1506                size: stretch::geometry::Size {
1507                    width: stretch::style::Dimension::Points(100.0000),
1508                    height: stretch::style::Dimension::Points(100.0000),
1509                    ..Default::default()
1510                },
1511                children: vec![stretch::style::Node {
1512                    size: stretch::geometry::Size {
1513                        height: stretch::style::Dimension::Points(10.0000),
1514                        ..Default::default()
1515                    },
1516                    max_size: stretch::geometry::Size {
1517                        width: stretch::style::Dimension::Points(50.0000),
1518                        ..Default::default()
1519                    },
1520                    ..Default::default()
1521                }],
1522                ..Default::default()
1523            },
1524            stretch::geometry::Size::undefined(),
1525        )
1526        .unwrap();
1527
1528        assert_eq!(layout.size.width, 100.0000);
1529        assert_eq!(layout.size.height, 100.0000);
1530        assert_eq!(layout.location.x, 0.0000);
1531        assert_eq!(layout.location.y, 0.0000);
1532
1533        assert_eq!(layout.children[0].size.width, 50.0000);
1534        assert_eq!(layout.children[0].size.height, 10.0000);
1535        assert_eq!(layout.children[0].location.x, 0.0000);
1536        assert_eq!(layout.children[0].location.y, 0.0000);
1537    }
1538
1539    #[test]
1540    fn justify_content_row_center() {
1541        let layout = stretch::compute(
1542            &stretch::style::Node {
1543                justify_content: stretch::style::JustifyContent::Center,
1544                size: stretch::geometry::Size {
1545                    width: stretch::style::Dimension::Points(100.0000),
1546                    height: stretch::style::Dimension::Points(100.0000),
1547                    ..Default::default()
1548                },
1549                children: vec![
1550                    stretch::style::Node {
1551                        size: stretch::geometry::Size {
1552                            width: stretch::style::Dimension::Points(10.0000),
1553                            ..Default::default()
1554                        },
1555                        ..Default::default()
1556                    },
1557                    stretch::style::Node {
1558                        size: stretch::geometry::Size {
1559                            width: stretch::style::Dimension::Points(10.0000),
1560                            ..Default::default()
1561                        },
1562                        ..Default::default()
1563                    },
1564                    stretch::style::Node {
1565                        size: stretch::geometry::Size {
1566                            width: stretch::style::Dimension::Points(10.0000),
1567                            ..Default::default()
1568                        },
1569                        ..Default::default()
1570                    },
1571                ],
1572                ..Default::default()
1573            },
1574            stretch::geometry::Size::undefined(),
1575        )
1576        .unwrap();
1577
1578        assert_eq!(layout.size.width, 100.0000);
1579        assert_eq!(layout.size.height, 100.0000);
1580        assert_eq!(layout.location.x, 0.0000);
1581        assert_eq!(layout.location.y, 0.0000);
1582
1583        assert_eq!(layout.children[0].size.width, 10.0000);
1584        assert_eq!(layout.children[0].size.height, 100.0000);
1585        assert_eq!(layout.children[0].location.x, 35.0000);
1586        assert_eq!(layout.children[0].location.y, 0.0000);
1587
1588        assert_eq!(layout.children[1].size.width, 10.0000);
1589        assert_eq!(layout.children[1].size.height, 100.0000);
1590        assert_eq!(layout.children[1].location.x, 45.0000);
1591        assert_eq!(layout.children[1].location.y, 0.0000);
1592
1593        assert_eq!(layout.children[2].size.width, 10.0000);
1594        assert_eq!(layout.children[2].size.height, 100.0000);
1595        assert_eq!(layout.children[2].location.x, 55.0000);
1596        assert_eq!(layout.children[2].location.y, 0.0000);
1597    }
1598
1599    #[test]
1600    fn flex_grow_root_minimized() {
1601        let layout = stretch::compute(
1602            &stretch::style::Node {
1603                flex_direction: stretch::style::FlexDirection::Column,
1604                size: stretch::geometry::Size {
1605                    width: stretch::style::Dimension::Points(100.0000),
1606                    ..Default::default()
1607                },
1608                min_size: stretch::geometry::Size {
1609                    height: stretch::style::Dimension::Points(100.0000),
1610                    ..Default::default()
1611                },
1612                max_size: stretch::geometry::Size {
1613                    height: stretch::style::Dimension::Points(500.0000),
1614                    ..Default::default()
1615                },
1616                children: vec![stretch::style::Node {
1617                    flex_direction: stretch::style::FlexDirection::Column,
1618                    flex_grow: 1.0000,
1619                    min_size: stretch::geometry::Size {
1620                        height: stretch::style::Dimension::Points(100.0000),
1621                        ..Default::default()
1622                    },
1623                    max_size: stretch::geometry::Size {
1624                        height: stretch::style::Dimension::Points(500.0000),
1625                        ..Default::default()
1626                    },
1627                    children: vec![
1628                        stretch::style::Node {
1629                            flex_grow: 1.0000,
1630                            flex_basis: stretch::style::Dimension::Points(200.0000),
1631                            ..Default::default()
1632                        },
1633                        stretch::style::Node {
1634                            size: stretch::geometry::Size {
1635                                height: stretch::style::Dimension::Points(100.0000),
1636                                ..Default::default()
1637                            },
1638                            ..Default::default()
1639                        },
1640                    ],
1641                    ..Default::default()
1642                }],
1643                ..Default::default()
1644            },
1645            stretch::geometry::Size::undefined(),
1646        )
1647        .unwrap();
1648
1649        assert_eq!(layout.size.width, 100.0000);
1650        assert_eq!(layout.size.height, 300.0000);
1651        assert_eq!(layout.location.x, 0.0000);
1652        assert_eq!(layout.location.y, 0.0000);
1653
1654        assert_eq!(layout.children[0].size.width, 100.0000);
1655        assert_eq!(layout.children[0].size.height, 300.0000);
1656        assert_eq!(layout.children[0].location.x, 0.0000);
1657        assert_eq!(layout.children[0].location.y, 0.0000);
1658
1659        assert_eq!(layout.children[0].children[0].size.width, 100.0000);
1660        assert_eq!(layout.children[0].children[0].size.height, 200.0000);
1661        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
1662        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
1663
1664        assert_eq!(layout.children[0].children[1].size.width, 100.0000);
1665        assert_eq!(layout.children[0].children[1].size.height, 100.0000);
1666        assert_eq!(layout.children[0].children[1].location.x, 0.0000);
1667        assert_eq!(layout.children[0].children[1].location.y, 200.0000);
1668    }
1669
1670    #[test]
1671    fn container_with_unsized_child() {
1672        let layout = stretch::compute(
1673            &stretch::style::Node {
1674                size: stretch::geometry::Size {
1675                    width: stretch::style::Dimension::Points(100.0000),
1676                    height: stretch::style::Dimension::Points(100.0000),
1677                    ..Default::default()
1678                },
1679                children: vec![stretch::style::Node { ..Default::default() }],
1680                ..Default::default()
1681            },
1682            stretch::geometry::Size::undefined(),
1683        )
1684        .unwrap();
1685
1686        assert_eq!(layout.size.width, 100.0000);
1687        assert_eq!(layout.size.height, 100.0000);
1688        assert_eq!(layout.location.x, 0.0000);
1689        assert_eq!(layout.location.y, 0.0000);
1690
1691        assert_eq!(layout.children[0].size.width, 0.0000);
1692        assert_eq!(layout.children[0].size.height, 100.0000);
1693        assert_eq!(layout.children[0].location.x, 0.0000);
1694        assert_eq!(layout.children[0].location.y, 0.0000);
1695    }
1696
1697    #[test]
1698    fn flex_grow_within_constrained_min_row() {
1699        let layout = stretch::compute(
1700            &stretch::style::Node {
1701                size: stretch::geometry::Size {
1702                    height: stretch::style::Dimension::Points(100.0000),
1703                    ..Default::default()
1704                },
1705                min_size: stretch::geometry::Size {
1706                    width: stretch::style::Dimension::Points(100.0000),
1707                    ..Default::default()
1708                },
1709                children: vec![
1710                    stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
1711                    stretch::style::Node {
1712                        size: stretch::geometry::Size {
1713                            width: stretch::style::Dimension::Points(50.0000),
1714                            ..Default::default()
1715                        },
1716                        ..Default::default()
1717                    },
1718                ],
1719                ..Default::default()
1720            },
1721            stretch::geometry::Size::undefined(),
1722        )
1723        .unwrap();
1724
1725        assert_eq!(layout.size.width, 100.0000);
1726        assert_eq!(layout.size.height, 100.0000);
1727        assert_eq!(layout.location.x, 0.0000);
1728        assert_eq!(layout.location.y, 0.0000);
1729
1730        assert_eq!(layout.children[0].size.width, 50.0000);
1731        assert_eq!(layout.children[0].size.height, 100.0000);
1732        assert_eq!(layout.children[0].location.x, 0.0000);
1733        assert_eq!(layout.children[0].location.y, 0.0000);
1734
1735        assert_eq!(layout.children[1].size.width, 50.0000);
1736        assert_eq!(layout.children[1].size.height, 100.0000);
1737        assert_eq!(layout.children[1].location.x, 50.0000);
1738        assert_eq!(layout.children[1].location.y, 0.0000);
1739    }
1740
1741    #[test]
1742    fn flex_shrink_by_outer_margin_with_max_size() {
1743        let layout = stretch::compute(
1744            &stretch::style::Node {
1745                flex_direction: stretch::style::FlexDirection::Column,
1746                size: stretch::geometry::Size {
1747                    height: stretch::style::Dimension::Points(100.0000),
1748                    ..Default::default()
1749                },
1750                max_size: stretch::geometry::Size {
1751                    height: stretch::style::Dimension::Points(80.0000),
1752                    ..Default::default()
1753                },
1754                children: vec![stretch::style::Node {
1755                    size: stretch::geometry::Size {
1756                        width: stretch::style::Dimension::Points(20.0000),
1757                        height: stretch::style::Dimension::Points(20.0000),
1758                        ..Default::default()
1759                    },
1760                    margin: stretch::geometry::Rect {
1761                        top: stretch::style::Dimension::Points(100.0000),
1762                        ..Default::default()
1763                    },
1764                    ..Default::default()
1765                }],
1766                ..Default::default()
1767            },
1768            stretch::geometry::Size::undefined(),
1769        )
1770        .unwrap();
1771
1772        assert_eq!(layout.size.width, 20.0000);
1773        assert_eq!(layout.size.height, 80.0000);
1774        assert_eq!(layout.location.x, 0.0000);
1775        assert_eq!(layout.location.y, 0.0000);
1776
1777        assert_eq!(layout.children[0].size.width, 20.0000);
1778        assert_eq!(layout.children[0].size.height, 0.0000);
1779        assert_eq!(layout.children[0].location.x, 0.0000);
1780        assert_eq!(layout.children[0].location.y, 100.0000);
1781    }
1782
1783    #[test]
1784    fn absolute_layout_width_height_start_top_end_bottom() {
1785        let layout = stretch::compute(
1786            &stretch::style::Node {
1787                size: stretch::geometry::Size {
1788                    width: stretch::style::Dimension::Points(100.0000),
1789                    height: stretch::style::Dimension::Points(100.0000),
1790                    ..Default::default()
1791                },
1792                children: vec![stretch::style::Node {
1793                    position_type: stretch::style::PositionType::Absolute,
1794                    size: stretch::geometry::Size {
1795                        width: stretch::style::Dimension::Points(10.0000),
1796                        height: stretch::style::Dimension::Points(10.0000),
1797                        ..Default::default()
1798                    },
1799                    position: stretch::geometry::Rect {
1800                        start: stretch::style::Dimension::Points(10.0000),
1801                        end: stretch::style::Dimension::Points(10.0000),
1802                        top: stretch::style::Dimension::Points(10.0000),
1803                        bottom: stretch::style::Dimension::Points(10.0000),
1804                        ..Default::default()
1805                    },
1806                    ..Default::default()
1807                }],
1808                ..Default::default()
1809            },
1810            stretch::geometry::Size::undefined(),
1811        )
1812        .unwrap();
1813
1814        assert_eq!(layout.size.width, 100.0000);
1815        assert_eq!(layout.size.height, 100.0000);
1816        assert_eq!(layout.location.x, 0.0000);
1817        assert_eq!(layout.location.y, 0.0000);
1818
1819        assert_eq!(layout.children[0].size.width, 10.0000);
1820        assert_eq!(layout.children[0].size.height, 10.0000);
1821        assert_eq!(layout.children[0].location.x, 10.0000);
1822        assert_eq!(layout.children[0].location.y, 10.0000);
1823    }
1824
1825    #[test]
1826    fn overflow_main_axis() {
1827        let layout = stretch::compute(
1828            &stretch::style::Node {
1829                size: stretch::geometry::Size {
1830                    width: stretch::style::Dimension::Points(100.0000),
1831                    height: stretch::style::Dimension::Points(100.0000),
1832                    ..Default::default()
1833                },
1834                children: vec![stretch::style::Node {
1835                    flex_shrink: 0.0000,
1836                    size: stretch::geometry::Size {
1837                        width: stretch::style::Dimension::Points(200.0000),
1838                        ..Default::default()
1839                    },
1840                    ..Default::default()
1841                }],
1842                ..Default::default()
1843            },
1844            stretch::geometry::Size::undefined(),
1845        )
1846        .unwrap();
1847
1848        assert_eq!(layout.size.width, 100.0000);
1849        assert_eq!(layout.size.height, 100.0000);
1850        assert_eq!(layout.location.x, 0.0000);
1851        assert_eq!(layout.location.y, 0.0000);
1852
1853        assert_eq!(layout.children[0].size.width, 200.0000);
1854        assert_eq!(layout.children[0].size.height, 100.0000);
1855        assert_eq!(layout.children[0].location.x, 0.0000);
1856        assert_eq!(layout.children[0].location.y, 0.0000);
1857    }
1858
1859    #[test]
1860    fn flex_grow_to_min() {
1861        let layout = stretch::compute(
1862            &stretch::style::Node {
1863                flex_direction: stretch::style::FlexDirection::Column,
1864                size: stretch::geometry::Size {
1865                    width: stretch::style::Dimension::Points(100.0000),
1866                    ..Default::default()
1867                },
1868                min_size: stretch::geometry::Size {
1869                    height: stretch::style::Dimension::Points(100.0000),
1870                    ..Default::default()
1871                },
1872                max_size: stretch::geometry::Size {
1873                    height: stretch::style::Dimension::Points(500.0000),
1874                    ..Default::default()
1875                },
1876                children: vec![
1877                    stretch::style::Node { flex_grow: 1.0000, flex_shrink: 1.0000, ..Default::default() },
1878                    stretch::style::Node {
1879                        size: stretch::geometry::Size {
1880                            height: stretch::style::Dimension::Points(50.0000),
1881                            ..Default::default()
1882                        },
1883                        ..Default::default()
1884                    },
1885                ],
1886                ..Default::default()
1887            },
1888            stretch::geometry::Size::undefined(),
1889        )
1890        .unwrap();
1891
1892        assert_eq!(layout.size.width, 100.0000);
1893        assert_eq!(layout.size.height, 100.0000);
1894        assert_eq!(layout.location.x, 0.0000);
1895        assert_eq!(layout.location.y, 0.0000);
1896
1897        assert_eq!(layout.children[0].size.width, 100.0000);
1898        assert_eq!(layout.children[0].size.height, 50.0000);
1899        assert_eq!(layout.children[0].location.x, 0.0000);
1900        assert_eq!(layout.children[0].location.y, 0.0000);
1901
1902        assert_eq!(layout.children[1].size.width, 100.0000);
1903        assert_eq!(layout.children[1].size.height, 50.0000);
1904        assert_eq!(layout.children[1].location.x, 0.0000);
1905        assert_eq!(layout.children[1].location.y, 50.0000);
1906    }
1907
1908    #[test]
1909    fn absolute_layout_align_items_and_justify_content_center_and_top_position() {
1910        let layout = stretch::compute(
1911            &stretch::style::Node {
1912                align_items: stretch::style::AlignItems::Center,
1913                justify_content: stretch::style::JustifyContent::Center,
1914                size: stretch::geometry::Size {
1915                    width: stretch::style::Dimension::Points(110.0000),
1916                    height: stretch::style::Dimension::Points(100.0000),
1917                    ..Default::default()
1918                },
1919                children: vec![stretch::style::Node {
1920                    position_type: stretch::style::PositionType::Absolute,
1921                    size: stretch::geometry::Size {
1922                        width: stretch::style::Dimension::Points(60.0000),
1923                        height: stretch::style::Dimension::Points(40.0000),
1924                        ..Default::default()
1925                    },
1926                    position: stretch::geometry::Rect {
1927                        top: stretch::style::Dimension::Points(10.0000),
1928                        ..Default::default()
1929                    },
1930                    ..Default::default()
1931                }],
1932                ..Default::default()
1933            },
1934            stretch::geometry::Size::undefined(),
1935        )
1936        .unwrap();
1937
1938        assert_eq!(layout.size.width, 110.0000);
1939        assert_eq!(layout.size.height, 100.0000);
1940        assert_eq!(layout.location.x, 0.0000);
1941        assert_eq!(layout.location.y, 0.0000);
1942
1943        assert_eq!(layout.children[0].size.width, 60.0000);
1944        assert_eq!(layout.children[0].size.height, 40.0000);
1945        assert_eq!(layout.children[0].location.x, 25.0000);
1946        assert_eq!(layout.children[0].location.y, 10.0000);
1947    }
1948
1949    #[test]
1950    fn min_height() {
1951        let layout = stretch::compute(
1952            &stretch::style::Node {
1953                flex_direction: stretch::style::FlexDirection::Column,
1954                size: stretch::geometry::Size {
1955                    width: stretch::style::Dimension::Points(100.0000),
1956                    height: stretch::style::Dimension::Points(100.0000),
1957                    ..Default::default()
1958                },
1959                children: vec![
1960                    stretch::style::Node {
1961                        flex_grow: 1.0000,
1962                        min_size: stretch::geometry::Size {
1963                            height: stretch::style::Dimension::Points(60.0000),
1964                            ..Default::default()
1965                        },
1966                        ..Default::default()
1967                    },
1968                    stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
1969                ],
1970                ..Default::default()
1971            },
1972            stretch::geometry::Size::undefined(),
1973        )
1974        .unwrap();
1975
1976        assert_eq!(layout.size.width, 100.0000);
1977        assert_eq!(layout.size.height, 100.0000);
1978        assert_eq!(layout.location.x, 0.0000);
1979        assert_eq!(layout.location.y, 0.0000);
1980
1981        assert_eq!(layout.children[0].size.width, 100.0000);
1982        assert_eq!(layout.children[0].size.height, 80.0000);
1983        assert_eq!(layout.children[0].location.x, 0.0000);
1984        assert_eq!(layout.children[0].location.y, 0.0000);
1985
1986        assert_eq!(layout.children[1].size.width, 100.0000);
1987        assert_eq!(layout.children[1].size.height, 20.0000);
1988        assert_eq!(layout.children[1].location.x, 0.0000);
1989        assert_eq!(layout.children[1].location.y, 80.0000);
1990    }
1991
1992    #[test]
1993    fn justify_content_column_flex_start() {
1994        let layout = stretch::compute(
1995            &stretch::style::Node {
1996                flex_direction: stretch::style::FlexDirection::Column,
1997                size: stretch::geometry::Size {
1998                    width: stretch::style::Dimension::Points(100.0000),
1999                    height: stretch::style::Dimension::Points(100.0000),
2000                    ..Default::default()
2001                },
2002                children: vec![
2003                    stretch::style::Node {
2004                        size: stretch::geometry::Size {
2005                            height: stretch::style::Dimension::Points(10.0000),
2006                            ..Default::default()
2007                        },
2008                        ..Default::default()
2009                    },
2010                    stretch::style::Node {
2011                        size: stretch::geometry::Size {
2012                            height: stretch::style::Dimension::Points(10.0000),
2013                            ..Default::default()
2014                        },
2015                        ..Default::default()
2016                    },
2017                    stretch::style::Node {
2018                        size: stretch::geometry::Size {
2019                            height: stretch::style::Dimension::Points(10.0000),
2020                            ..Default::default()
2021                        },
2022                        ..Default::default()
2023                    },
2024                ],
2025                ..Default::default()
2026            },
2027            stretch::geometry::Size::undefined(),
2028        )
2029        .unwrap();
2030
2031        assert_eq!(layout.size.width, 100.0000);
2032        assert_eq!(layout.size.height, 100.0000);
2033        assert_eq!(layout.location.x, 0.0000);
2034        assert_eq!(layout.location.y, 0.0000);
2035
2036        assert_eq!(layout.children[0].size.width, 100.0000);
2037        assert_eq!(layout.children[0].size.height, 10.0000);
2038        assert_eq!(layout.children[0].location.x, 0.0000);
2039        assert_eq!(layout.children[0].location.y, 0.0000);
2040
2041        assert_eq!(layout.children[1].size.width, 100.0000);
2042        assert_eq!(layout.children[1].size.height, 10.0000);
2043        assert_eq!(layout.children[1].location.x, 0.0000);
2044        assert_eq!(layout.children[1].location.y, 10.0000);
2045
2046        assert_eq!(layout.children[2].size.width, 100.0000);
2047        assert_eq!(layout.children[2].size.height, 10.0000);
2048        assert_eq!(layout.children[2].location.x, 0.0000);
2049        assert_eq!(layout.children[2].location.y, 20.0000);
2050    }
2051
2052    #[test]
2053    fn absolute_layout_in_wrap_reverse_column_container() {
2054        let layout = stretch::compute(
2055            &stretch::style::Node {
2056                flex_direction: stretch::style::FlexDirection::Column,
2057                flex_wrap: stretch::style::FlexWrap::WrapReverse,
2058                size: stretch::geometry::Size {
2059                    width: stretch::style::Dimension::Points(100.0000),
2060                    height: stretch::style::Dimension::Points(100.0000),
2061                    ..Default::default()
2062                },
2063                children: vec![stretch::style::Node {
2064                    position_type: stretch::style::PositionType::Absolute,
2065                    size: stretch::geometry::Size {
2066                        width: stretch::style::Dimension::Points(20.0000),
2067                        height: stretch::style::Dimension::Points(20.0000),
2068                        ..Default::default()
2069                    },
2070                    ..Default::default()
2071                }],
2072                ..Default::default()
2073            },
2074            stretch::geometry::Size::undefined(),
2075        )
2076        .unwrap();
2077
2078        assert_eq!(layout.size.width, 100.0000);
2079        assert_eq!(layout.size.height, 100.0000);
2080        assert_eq!(layout.location.x, 0.0000);
2081        assert_eq!(layout.location.y, 0.0000);
2082
2083        assert_eq!(layout.children[0].size.width, 20.0000);
2084        assert_eq!(layout.children[0].size.height, 20.0000);
2085        assert_eq!(layout.children[0].location.x, 80.0000);
2086        assert_eq!(layout.children[0].location.y, 0.0000);
2087    }
2088
2089    #[test]
2090    fn margin_should_not_be_part_of_max_width() {
2091        let layout = stretch::compute(
2092            &stretch::style::Node {
2093                size: stretch::geometry::Size {
2094                    width: stretch::style::Dimension::Points(250.0000),
2095                    height: stretch::style::Dimension::Points(250.0000),
2096                    ..Default::default()
2097                },
2098                children: vec![stretch::style::Node {
2099                    size: stretch::geometry::Size {
2100                        width: stretch::style::Dimension::Points(100.0000),
2101                        height: stretch::style::Dimension::Points(100.0000),
2102                        ..Default::default()
2103                    },
2104                    max_size: stretch::geometry::Size {
2105                        width: stretch::style::Dimension::Points(100.0000),
2106                        ..Default::default()
2107                    },
2108                    margin: stretch::geometry::Rect {
2109                        start: stretch::style::Dimension::Points(20.0000),
2110                        ..Default::default()
2111                    },
2112                    ..Default::default()
2113                }],
2114                ..Default::default()
2115            },
2116            stretch::geometry::Size::undefined(),
2117        )
2118        .unwrap();
2119
2120        assert_eq!(layout.size.width, 250.0000);
2121        assert_eq!(layout.size.height, 250.0000);
2122        assert_eq!(layout.location.x, 0.0000);
2123        assert_eq!(layout.location.y, 0.0000);
2124
2125        assert_eq!(layout.children[0].size.width, 100.0000);
2126        assert_eq!(layout.children[0].size.height, 100.0000);
2127        assert_eq!(layout.children[0].location.x, 20.0000);
2128        assert_eq!(layout.children[0].location.y, 0.0000);
2129    }
2130
2131    #[test]
2132    fn absolute_layout_no_size() {
2133        let layout = stretch::compute(
2134            &stretch::style::Node {
2135                size: stretch::geometry::Size {
2136                    width: stretch::style::Dimension::Points(100.0000),
2137                    height: stretch::style::Dimension::Points(100.0000),
2138                    ..Default::default()
2139                },
2140                children: vec![stretch::style::Node {
2141                    position_type: stretch::style::PositionType::Absolute,
2142                    ..Default::default()
2143                }],
2144                ..Default::default()
2145            },
2146            stretch::geometry::Size::undefined(),
2147        )
2148        .unwrap();
2149
2150        assert_eq!(layout.size.width, 100.0000);
2151        assert_eq!(layout.size.height, 100.0000);
2152        assert_eq!(layout.location.x, 0.0000);
2153        assert_eq!(layout.location.y, 0.0000);
2154
2155        assert_eq!(layout.children[0].size.width, 0.0000);
2156        assert_eq!(layout.children[0].size.height, 0.0000);
2157        assert_eq!(layout.children[0].location.x, 0.0000);
2158        assert_eq!(layout.children[0].location.y, 0.0000);
2159    }
2160
2161    #[test]
2162    fn border_flex_child() {
2163        let layout = stretch::compute(
2164            &stretch::style::Node {
2165                size: stretch::geometry::Size {
2166                    width: stretch::style::Dimension::Points(100.0000),
2167                    height: stretch::style::Dimension::Points(100.0000),
2168                    ..Default::default()
2169                },
2170                border: stretch::geometry::Rect {
2171                    start: stretch::style::Dimension::Points(10.0000),
2172                    end: stretch::style::Dimension::Points(10.0000),
2173                    top: stretch::style::Dimension::Points(10.0000),
2174                    bottom: stretch::style::Dimension::Points(10.0000),
2175                    ..Default::default()
2176                },
2177                children: vec![stretch::style::Node {
2178                    flex_grow: 1.0000,
2179                    size: stretch::geometry::Size {
2180                        width: stretch::style::Dimension::Points(10.0000),
2181                        ..Default::default()
2182                    },
2183                    ..Default::default()
2184                }],
2185                ..Default::default()
2186            },
2187            stretch::geometry::Size::undefined(),
2188        )
2189        .unwrap();
2190
2191        assert_eq!(layout.size.width, 100.0000);
2192        assert_eq!(layout.size.height, 100.0000);
2193        assert_eq!(layout.location.x, 0.0000);
2194        assert_eq!(layout.location.y, 0.0000);
2195
2196        assert_eq!(layout.children[0].size.width, 80.0000);
2197        assert_eq!(layout.children[0].size.height, 80.0000);
2198        assert_eq!(layout.children[0].location.x, 10.0000);
2199        assert_eq!(layout.children[0].location.y, 10.0000);
2200    }
2201
2202    #[test]
2203    fn wrap_reverse_row() {
2204        let layout = stretch::compute(
2205            &stretch::style::Node {
2206                flex_wrap: stretch::style::FlexWrap::WrapReverse,
2207                size: stretch::geometry::Size {
2208                    width: stretch::style::Dimension::Points(100.0000),
2209                    ..Default::default()
2210                },
2211                children: vec![
2212                    stretch::style::Node {
2213                        size: stretch::geometry::Size {
2214                            width: stretch::style::Dimension::Points(31.0000),
2215                            height: stretch::style::Dimension::Points(30.0000),
2216                            ..Default::default()
2217                        },
2218                        ..Default::default()
2219                    },
2220                    stretch::style::Node {
2221                        size: stretch::geometry::Size {
2222                            width: stretch::style::Dimension::Points(32.0000),
2223                            height: stretch::style::Dimension::Points(30.0000),
2224                            ..Default::default()
2225                        },
2226                        ..Default::default()
2227                    },
2228                    stretch::style::Node {
2229                        size: stretch::geometry::Size {
2230                            width: stretch::style::Dimension::Points(33.0000),
2231                            height: stretch::style::Dimension::Points(30.0000),
2232                            ..Default::default()
2233                        },
2234                        ..Default::default()
2235                    },
2236                    stretch::style::Node {
2237                        size: stretch::geometry::Size {
2238                            width: stretch::style::Dimension::Points(34.0000),
2239                            height: stretch::style::Dimension::Points(30.0000),
2240                            ..Default::default()
2241                        },
2242                        ..Default::default()
2243                    },
2244                ],
2245                ..Default::default()
2246            },
2247            stretch::geometry::Size::undefined(),
2248        )
2249        .unwrap();
2250
2251        assert_eq!(layout.size.width, 100.0000);
2252        assert_eq!(layout.size.height, 60.0000);
2253        assert_eq!(layout.location.x, 0.0000);
2254        assert_eq!(layout.location.y, 0.0000);
2255
2256        assert_eq!(layout.children[0].size.width, 31.0000);
2257        assert_eq!(layout.children[0].size.height, 30.0000);
2258        assert_eq!(layout.children[0].location.x, 0.0000);
2259        assert_eq!(layout.children[0].location.y, 30.0000);
2260
2261        assert_eq!(layout.children[1].size.width, 32.0000);
2262        assert_eq!(layout.children[1].size.height, 30.0000);
2263        assert_eq!(layout.children[1].location.x, 31.0000);
2264        assert_eq!(layout.children[1].location.y, 30.0000);
2265
2266        assert_eq!(layout.children[2].size.width, 33.0000);
2267        assert_eq!(layout.children[2].size.height, 30.0000);
2268        assert_eq!(layout.children[2].location.x, 63.0000);
2269        assert_eq!(layout.children[2].location.y, 30.0000);
2270
2271        assert_eq!(layout.children[3].size.width, 34.0000);
2272        assert_eq!(layout.children[3].size.height, 30.0000);
2273        assert_eq!(layout.children[3].location.x, 0.0000);
2274        assert_eq!(layout.children[3].location.y, 0.0000);
2275    }
2276
2277    #[test]
2278    fn margin_right() {
2279        let layout = stretch::compute(
2280            &stretch::style::Node {
2281                justify_content: stretch::style::JustifyContent::FlexEnd,
2282                size: stretch::geometry::Size {
2283                    width: stretch::style::Dimension::Points(100.0000),
2284                    height: stretch::style::Dimension::Points(100.0000),
2285                    ..Default::default()
2286                },
2287                children: vec![stretch::style::Node {
2288                    size: stretch::geometry::Size {
2289                        width: stretch::style::Dimension::Points(10.0000),
2290                        ..Default::default()
2291                    },
2292                    margin: stretch::geometry::Rect {
2293                        end: stretch::style::Dimension::Points(10.0000),
2294                        ..Default::default()
2295                    },
2296                    ..Default::default()
2297                }],
2298                ..Default::default()
2299            },
2300            stretch::geometry::Size::undefined(),
2301        )
2302        .unwrap();
2303
2304        assert_eq!(layout.size.width, 100.0000);
2305        assert_eq!(layout.size.height, 100.0000);
2306        assert_eq!(layout.location.x, 0.0000);
2307        assert_eq!(layout.location.y, 0.0000);
2308
2309        assert_eq!(layout.children[0].size.width, 10.0000);
2310        assert_eq!(layout.children[0].size.height, 100.0000);
2311        assert_eq!(layout.children[0].location.x, 80.0000);
2312        assert_eq!(layout.children[0].location.y, 0.0000);
2313    }
2314
2315    #[test]
2316    fn display_none_with_child() {
2317        let layout = stretch::compute(
2318            &stretch::style::Node {
2319                size: stretch::geometry::Size {
2320                    width: stretch::style::Dimension::Points(100.0000),
2321                    height: stretch::style::Dimension::Points(100.0000),
2322                    ..Default::default()
2323                },
2324                children: vec![
2325                    stretch::style::Node {
2326                        flex_grow: 1.0000,
2327                        flex_shrink: 1.0000,
2328                        flex_basis: stretch::style::Dimension::Percent(0.0000),
2329                        ..Default::default()
2330                    },
2331                    stretch::style::Node {
2332                        display: stretch::style::Display::None,
2333                        flex_direction: stretch::style::FlexDirection::Column,
2334                        flex_grow: 1.0000,
2335                        flex_shrink: 1.0000,
2336                        flex_basis: stretch::style::Dimension::Percent(0.0000),
2337                        children: vec![stretch::style::Node {
2338                            flex_grow: 1.0000,
2339                            flex_shrink: 1.0000,
2340                            flex_basis: stretch::style::Dimension::Percent(0.0000),
2341                            size: stretch::geometry::Size {
2342                                width: stretch::style::Dimension::Points(20.0000),
2343                                ..Default::default()
2344                            },
2345                            ..Default::default()
2346                        }],
2347                        ..Default::default()
2348                    },
2349                    stretch::style::Node {
2350                        flex_grow: 1.0000,
2351                        flex_shrink: 1.0000,
2352                        flex_basis: stretch::style::Dimension::Percent(0.0000),
2353                        ..Default::default()
2354                    },
2355                ],
2356                ..Default::default()
2357            },
2358            stretch::geometry::Size::undefined(),
2359        )
2360        .unwrap();
2361
2362        assert_eq!(layout.size.width, 100.0000);
2363        assert_eq!(layout.size.height, 100.0000);
2364        assert_eq!(layout.location.x, 0.0000);
2365        assert_eq!(layout.location.y, 0.0000);
2366
2367        assert_eq!(layout.children[0].size.width, 50.0000);
2368        assert_eq!(layout.children[0].size.height, 100.0000);
2369        assert_eq!(layout.children[0].location.x, 0.0000);
2370        assert_eq!(layout.children[0].location.y, 0.0000);
2371
2372        assert_eq!(layout.children[1].size.width, 0.0000);
2373        assert_eq!(layout.children[1].size.height, 0.0000);
2374        assert_eq!(layout.children[1].location.x, 0.0000);
2375        assert_eq!(layout.children[1].location.y, 0.0000);
2376
2377        assert_eq!(layout.children[1].children[0].size.width, 0.0000);
2378        assert_eq!(layout.children[1].children[0].size.height, 0.0000);
2379        assert_eq!(layout.children[1].children[0].location.x, 0.0000);
2380        assert_eq!(layout.children[1].children[0].location.y, 0.0000);
2381
2382        assert_eq!(layout.children[2].size.width, 50.0000);
2383        assert_eq!(layout.children[2].size.height, 100.0000);
2384        assert_eq!(layout.children[2].location.x, 50.0000);
2385        assert_eq!(layout.children[2].location.y, 0.0000);
2386    }
2387
2388    #[test]
2389    fn align_flex_start_with_shrinking_children_with_stretch() {
2390        let layout = stretch::compute(
2391            &stretch::style::Node {
2392                size: stretch::geometry::Size {
2393                    width: stretch::style::Dimension::Points(500.0000),
2394                    height: stretch::style::Dimension::Points(500.0000),
2395                    ..Default::default()
2396                },
2397                children: vec![stretch::style::Node {
2398                    align_items: stretch::style::AlignItems::FlexStart,
2399                    children: vec![stretch::style::Node {
2400                        flex_grow: 1.0000,
2401                        flex_shrink: 1.0000,
2402                        children: vec![stretch::style::Node {
2403                            flex_grow: 1.0000,
2404                            flex_shrink: 1.0000,
2405                            ..Default::default()
2406                        }],
2407                        ..Default::default()
2408                    }],
2409                    ..Default::default()
2410                }],
2411                ..Default::default()
2412            },
2413            stretch::geometry::Size::undefined(),
2414        )
2415        .unwrap();
2416
2417        assert_eq!(layout.size.width, 500.0000);
2418        assert_eq!(layout.size.height, 500.0000);
2419        assert_eq!(layout.location.x, 0.0000);
2420        assert_eq!(layout.location.y, 0.0000);
2421
2422        assert_eq!(layout.children[0].size.width, 0.0000);
2423        assert_eq!(layout.children[0].size.height, 500.0000);
2424        assert_eq!(layout.children[0].location.x, 0.0000);
2425        assert_eq!(layout.children[0].location.y, 0.0000);
2426
2427        assert_eq!(layout.children[0].children[0].size.width, 0.0000);
2428        assert_eq!(layout.children[0].children[0].size.height, 0.0000);
2429        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
2430        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
2431
2432        assert_eq!(layout.children[0].children[0].children[0].size.width, 0.0000);
2433        assert_eq!(layout.children[0].children[0].children[0].size.height, 0.0000);
2434        assert_eq!(layout.children[0].children[0].children[0].location.x, 0.0000);
2435        assert_eq!(layout.children[0].children[0].children[0].location.y, 0.0000);
2436    }
2437
2438    #[test]
2439    fn flex_basis_smaller_then_content_with_flex_grow_large_size() {
2440        let layout = stretch::compute(
2441            &stretch::style::Node {
2442                size: stretch::geometry::Size {
2443                    width: stretch::style::Dimension::Points(100.0000),
2444                    ..Default::default()
2445                },
2446                children: vec![
2447                    stretch::style::Node {
2448                        flex_direction: stretch::style::FlexDirection::Column,
2449                        flex_grow: 1.0000,
2450                        flex_basis: stretch::style::Dimension::Points(0.0000),
2451                        children: vec![stretch::style::Node {
2452                            size: stretch::geometry::Size {
2453                                width: stretch::style::Dimension::Points(70.0000),
2454                                height: stretch::style::Dimension::Points(100.0000),
2455                                ..Default::default()
2456                            },
2457                            ..Default::default()
2458                        }],
2459                        ..Default::default()
2460                    },
2461                    stretch::style::Node {
2462                        flex_direction: stretch::style::FlexDirection::Column,
2463                        flex_grow: 1.0000,
2464                        flex_basis: stretch::style::Dimension::Points(0.0000),
2465                        children: vec![stretch::style::Node {
2466                            size: stretch::geometry::Size {
2467                                width: stretch::style::Dimension::Points(20.0000),
2468                                height: stretch::style::Dimension::Points(100.0000),
2469                                ..Default::default()
2470                            },
2471                            ..Default::default()
2472                        }],
2473                        ..Default::default()
2474                    },
2475                ],
2476                ..Default::default()
2477            },
2478            stretch::geometry::Size::undefined(),
2479        )
2480        .unwrap();
2481
2482        assert_eq!(layout.size.width, 100.0000);
2483        assert_eq!(layout.size.height, 100.0000);
2484        assert_eq!(layout.location.x, 0.0000);
2485        assert_eq!(layout.location.y, 0.0000);
2486
2487        assert_eq!(layout.children[0].size.width, 70.0000);
2488        assert_eq!(layout.children[0].size.height, 100.0000);
2489        assert_eq!(layout.children[0].location.x, 0.0000);
2490        assert_eq!(layout.children[0].location.y, 0.0000);
2491
2492        assert_eq!(layout.children[0].children[0].size.width, 70.0000);
2493        assert_eq!(layout.children[0].children[0].size.height, 100.0000);
2494        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
2495        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
2496
2497        assert_eq!(layout.children[1].size.width, 30.0000);
2498        assert_eq!(layout.children[1].size.height, 100.0000);
2499        assert_eq!(layout.children[1].location.x, 70.0000);
2500        assert_eq!(layout.children[1].location.y, 0.0000);
2501
2502        assert_eq!(layout.children[1].children[0].size.width, 20.0000);
2503        assert_eq!(layout.children[1].children[0].size.height, 100.0000);
2504        assert_eq!(layout.children[1].children[0].location.x, 0.0000);
2505        assert_eq!(layout.children[1].children[0].location.y, 0.0000);
2506    }
2507
2508    #[test]
2509    fn align_items_stretch() {
2510        let layout = stretch::compute(
2511            &stretch::style::Node {
2512                size: stretch::geometry::Size {
2513                    width: stretch::style::Dimension::Points(100.0000),
2514                    height: stretch::style::Dimension::Points(100.0000),
2515                    ..Default::default()
2516                },
2517                children: vec![stretch::style::Node {
2518                    size: stretch::geometry::Size {
2519                        width: stretch::style::Dimension::Points(10.0000),
2520                        ..Default::default()
2521                    },
2522                    ..Default::default()
2523                }],
2524                ..Default::default()
2525            },
2526            stretch::geometry::Size::undefined(),
2527        )
2528        .unwrap();
2529
2530        assert_eq!(layout.size.width, 100.0000);
2531        assert_eq!(layout.size.height, 100.0000);
2532        assert_eq!(layout.location.x, 0.0000);
2533        assert_eq!(layout.location.y, 0.0000);
2534
2535        assert_eq!(layout.children[0].size.width, 10.0000);
2536        assert_eq!(layout.children[0].size.height, 100.0000);
2537        assert_eq!(layout.children[0].location.x, 0.0000);
2538        assert_eq!(layout.children[0].location.y, 0.0000);
2539    }
2540
2541    #[test]
2542    fn parent_wrap_child_size_overflowing_parent() {
2543        let layout = stretch::compute(
2544            &stretch::style::Node {
2545                size: stretch::geometry::Size {
2546                    width: stretch::style::Dimension::Points(100.0000),
2547                    height: stretch::style::Dimension::Points(100.0000),
2548                    ..Default::default()
2549                },
2550                children: vec![stretch::style::Node {
2551                    size: stretch::geometry::Size {
2552                        width: stretch::style::Dimension::Points(100.0000),
2553                        ..Default::default()
2554                    },
2555                    children: vec![stretch::style::Node {
2556                        size: stretch::geometry::Size {
2557                            width: stretch::style::Dimension::Points(100.0000),
2558                            height: stretch::style::Dimension::Points(200.0000),
2559                            ..Default::default()
2560                        },
2561                        ..Default::default()
2562                    }],
2563                    ..Default::default()
2564                }],
2565                ..Default::default()
2566            },
2567            stretch::geometry::Size::undefined(),
2568        )
2569        .unwrap();
2570
2571        assert_eq!(layout.size.width, 100.0000);
2572        assert_eq!(layout.size.height, 100.0000);
2573        assert_eq!(layout.location.x, 0.0000);
2574        assert_eq!(layout.location.y, 0.0000);
2575
2576        assert_eq!(layout.children[0].size.width, 100.0000);
2577        assert_eq!(layout.children[0].size.height, 100.0000);
2578        assert_eq!(layout.children[0].location.x, 0.0000);
2579        assert_eq!(layout.children[0].location.y, 0.0000);
2580
2581        assert_eq!(layout.children[0].children[0].size.width, 100.0000);
2582        assert_eq!(layout.children[0].children[0].size.height, 200.0000);
2583        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
2584        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
2585    }
2586
2587    #[test]
2588    fn padding_stretch_child() {
2589        let layout = stretch::compute(
2590            &stretch::style::Node {
2591                size: stretch::geometry::Size {
2592                    width: stretch::style::Dimension::Points(100.0000),
2593                    height: stretch::style::Dimension::Points(100.0000),
2594                    ..Default::default()
2595                },
2596                padding: stretch::geometry::Rect {
2597                    start: stretch::style::Dimension::Points(10.0000),
2598                    end: stretch::style::Dimension::Points(10.0000),
2599                    top: stretch::style::Dimension::Points(10.0000),
2600                    bottom: stretch::style::Dimension::Points(10.0000),
2601                    ..Default::default()
2602                },
2603                children: vec![stretch::style::Node {
2604                    size: stretch::geometry::Size {
2605                        height: stretch::style::Dimension::Points(10.0000),
2606                        ..Default::default()
2607                    },
2608                    ..Default::default()
2609                }],
2610                ..Default::default()
2611            },
2612            stretch::geometry::Size::undefined(),
2613        )
2614        .unwrap();
2615
2616        assert_eq!(layout.size.width, 100.0000);
2617        assert_eq!(layout.size.height, 100.0000);
2618        assert_eq!(layout.location.x, 0.0000);
2619        assert_eq!(layout.location.y, 0.0000);
2620
2621        assert_eq!(layout.children[0].size.width, 0.0000);
2622        assert_eq!(layout.children[0].size.height, 10.0000);
2623        assert_eq!(layout.children[0].location.x, 10.0000);
2624        assert_eq!(layout.children[0].location.y, 10.0000);
2625    }
2626
2627    #[test]
2628    fn wrap_nodes_with_content_sizing_overflowing_margin() {
2629        let layout = stretch::compute(
2630            &stretch::style::Node {
2631                flex_direction: stretch::style::FlexDirection::Column,
2632                size: stretch::geometry::Size {
2633                    width: stretch::style::Dimension::Points(500.0000),
2634                    height: stretch::style::Dimension::Points(500.0000),
2635                    ..Default::default()
2636                },
2637                children: vec![stretch::style::Node {
2638                    flex_wrap: stretch::style::FlexWrap::Wrap,
2639                    size: stretch::geometry::Size {
2640                        width: stretch::style::Dimension::Points(85.0000),
2641                        ..Default::default()
2642                    },
2643                    children: vec![
2644                        stretch::style::Node {
2645                            flex_direction: stretch::style::FlexDirection::Column,
2646                            children: vec![stretch::style::Node {
2647                                size: stretch::geometry::Size {
2648                                    width: stretch::style::Dimension::Points(40.0000),
2649                                    height: stretch::style::Dimension::Points(40.0000),
2650                                    ..Default::default()
2651                                },
2652                                ..Default::default()
2653                            }],
2654                            ..Default::default()
2655                        },
2656                        stretch::style::Node {
2657                            flex_direction: stretch::style::FlexDirection::Column,
2658                            margin: stretch::geometry::Rect {
2659                                end: stretch::style::Dimension::Points(10.0000),
2660                                ..Default::default()
2661                            },
2662                            children: vec![stretch::style::Node {
2663                                size: stretch::geometry::Size {
2664                                    width: stretch::style::Dimension::Points(40.0000),
2665                                    height: stretch::style::Dimension::Points(40.0000),
2666                                    ..Default::default()
2667                                },
2668                                ..Default::default()
2669                            }],
2670                            ..Default::default()
2671                        },
2672                    ],
2673                    ..Default::default()
2674                }],
2675                ..Default::default()
2676            },
2677            stretch::geometry::Size::undefined(),
2678        )
2679        .unwrap();
2680
2681        assert_eq!(layout.size.width, 500.0000);
2682        assert_eq!(layout.size.height, 500.0000);
2683        assert_eq!(layout.location.x, 0.0000);
2684        assert_eq!(layout.location.y, 0.0000);
2685
2686        assert_eq!(layout.children[0].size.width, 85.0000);
2687        assert_eq!(layout.children[0].size.height, 80.0000);
2688        assert_eq!(layout.children[0].location.x, 0.0000);
2689        assert_eq!(layout.children[0].location.y, 0.0000);
2690
2691        assert_eq!(layout.children[0].children[0].size.width, 40.0000);
2692        assert_eq!(layout.children[0].children[0].size.height, 40.0000);
2693        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
2694        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
2695
2696        assert_eq!(layout.children[0].children[0].children[0].size.width, 40.0000);
2697        assert_eq!(layout.children[0].children[0].children[0].size.height, 40.0000);
2698        assert_eq!(layout.children[0].children[0].children[0].location.x, 0.0000);
2699        assert_eq!(layout.children[0].children[0].children[0].location.y, 0.0000);
2700
2701        assert_eq!(layout.children[0].children[1].size.width, 40.0000);
2702        assert_eq!(layout.children[0].children[1].size.height, 40.0000);
2703        assert_eq!(layout.children[0].children[1].location.x, 0.0000);
2704        assert_eq!(layout.children[0].children[1].location.y, 40.0000);
2705
2706        assert_eq!(layout.children[0].children[1].children[0].size.width, 40.0000);
2707        assert_eq!(layout.children[0].children[1].children[0].size.height, 40.0000);
2708        assert_eq!(layout.children[0].children[1].children[0].location.x, 0.0000);
2709        assert_eq!(layout.children[0].children[1].children[0].location.y, 0.0000);
2710    }
2711
2712    #[test]
2713    fn flex_shrink_flex_grow_row() {
2714        let layout = stretch::compute(
2715            &stretch::style::Node {
2716                size: stretch::geometry::Size {
2717                    width: stretch::style::Dimension::Points(500.0000),
2718                    height: stretch::style::Dimension::Points(500.0000),
2719                    ..Default::default()
2720                },
2721                children: vec![
2722                    stretch::style::Node {
2723                        flex_grow: 0.0000,
2724                        flex_shrink: 1.0000,
2725                        size: stretch::geometry::Size {
2726                            width: stretch::style::Dimension::Points(500.0000),
2727                            height: stretch::style::Dimension::Points(100.0000),
2728                            ..Default::default()
2729                        },
2730                        ..Default::default()
2731                    },
2732                    stretch::style::Node {
2733                        flex_grow: 0.0000,
2734                        flex_shrink: 1.0000,
2735                        size: stretch::geometry::Size {
2736                            width: stretch::style::Dimension::Points(500.0000),
2737                            height: stretch::style::Dimension::Points(100.0000),
2738                            ..Default::default()
2739                        },
2740                        ..Default::default()
2741                    },
2742                ],
2743                ..Default::default()
2744            },
2745            stretch::geometry::Size::undefined(),
2746        )
2747        .unwrap();
2748
2749        assert_eq!(layout.size.width, 500.0000);
2750        assert_eq!(layout.size.height, 500.0000);
2751        assert_eq!(layout.location.x, 0.0000);
2752        assert_eq!(layout.location.y, 0.0000);
2753
2754        assert_eq!(layout.children[0].size.width, 250.0000);
2755        assert_eq!(layout.children[0].size.height, 100.0000);
2756        assert_eq!(layout.children[0].location.x, 0.0000);
2757        assert_eq!(layout.children[0].location.y, 0.0000);
2758
2759        assert_eq!(layout.children[1].size.width, 250.0000);
2760        assert_eq!(layout.children[1].size.height, 100.0000);
2761        assert_eq!(layout.children[1].location.x, 250.0000);
2762        assert_eq!(layout.children[1].location.y, 0.0000);
2763    }
2764
2765    #[test]
2766    fn flex_basis_flex_shrink_column() {
2767        let layout = stretch::compute(
2768            &stretch::style::Node {
2769                flex_direction: stretch::style::FlexDirection::Column,
2770                size: stretch::geometry::Size {
2771                    width: stretch::style::Dimension::Points(100.0000),
2772                    height: stretch::style::Dimension::Points(100.0000),
2773                    ..Default::default()
2774                },
2775                children: vec![
2776                    stretch::style::Node {
2777                        flex_basis: stretch::style::Dimension::Points(100.0000),
2778                        ..Default::default()
2779                    },
2780                    stretch::style::Node {
2781                        flex_basis: stretch::style::Dimension::Points(50.0000),
2782                        ..Default::default()
2783                    },
2784                ],
2785                ..Default::default()
2786            },
2787            stretch::geometry::Size::undefined(),
2788        )
2789        .unwrap();
2790
2791        assert_eq!(layout.size.width, 100.0000);
2792        assert_eq!(layout.size.height, 100.0000);
2793        assert_eq!(layout.location.x, 0.0000);
2794        assert_eq!(layout.location.y, 0.0000);
2795
2796        assert_eq!(layout.children[0].size.width, 100.0000);
2797        assert_eq!(layout.children[0].size.height, 67.0000);
2798        assert_eq!(layout.children[0].location.x, 0.0000);
2799        assert_eq!(layout.children[0].location.y, 0.0000);
2800
2801        assert_eq!(layout.children[1].size.width, 100.0000);
2802        assert_eq!(layout.children[1].size.height, 33.0000);
2803        assert_eq!(layout.children[1].location.x, 0.0000);
2804        assert_eq!(layout.children[1].location.y, 67.0000);
2805    }
2806
2807    #[test]
2808    fn align_items_min_max() {
2809        let layout = stretch::compute(
2810            &stretch::style::Node {
2811                flex_direction: stretch::style::FlexDirection::Column,
2812                align_items: stretch::style::AlignItems::Center,
2813                size: stretch::geometry::Size {
2814                    height: stretch::style::Dimension::Points(100.0000),
2815                    ..Default::default()
2816                },
2817                min_size: stretch::geometry::Size {
2818                    width: stretch::style::Dimension::Points(100.0000),
2819                    ..Default::default()
2820                },
2821                max_size: stretch::geometry::Size {
2822                    width: stretch::style::Dimension::Points(200.0000),
2823                    ..Default::default()
2824                },
2825                children: vec![stretch::style::Node {
2826                    size: stretch::geometry::Size {
2827                        width: stretch::style::Dimension::Points(60.0000),
2828                        height: stretch::style::Dimension::Points(60.0000),
2829                        ..Default::default()
2830                    },
2831                    ..Default::default()
2832                }],
2833                ..Default::default()
2834            },
2835            stretch::geometry::Size::undefined(),
2836        )
2837        .unwrap();
2838
2839        assert_eq!(layout.size.width, 100.0000);
2840        assert_eq!(layout.size.height, 100.0000);
2841        assert_eq!(layout.location.x, 0.0000);
2842        assert_eq!(layout.location.y, 0.0000);
2843
2844        assert_eq!(layout.children[0].size.width, 60.0000);
2845        assert_eq!(layout.children[0].size.height, 60.0000);
2846        assert_eq!(layout.children[0].location.x, 20.0000);
2847        assert_eq!(layout.children[0].location.y, 0.0000);
2848    }
2849
2850    #[test]
2851    fn flex_basis_smaller_then_content_with_flex_grow_unconstraint_size() {
2852        let layout = stretch::compute(
2853            &stretch::style::Node {
2854                children: vec![
2855                    stretch::style::Node {
2856                        flex_direction: stretch::style::FlexDirection::Column,
2857                        flex_grow: 1.0000,
2858                        flex_basis: stretch::style::Dimension::Points(0.0000),
2859                        children: vec![stretch::style::Node {
2860                            size: stretch::geometry::Size {
2861                                width: stretch::style::Dimension::Points(70.0000),
2862                                height: stretch::style::Dimension::Points(100.0000),
2863                                ..Default::default()
2864                            },
2865                            ..Default::default()
2866                        }],
2867                        ..Default::default()
2868                    },
2869                    stretch::style::Node {
2870                        flex_direction: stretch::style::FlexDirection::Column,
2871                        flex_grow: 1.0000,
2872                        flex_basis: stretch::style::Dimension::Points(0.0000),
2873                        children: vec![stretch::style::Node {
2874                            size: stretch::geometry::Size {
2875                                width: stretch::style::Dimension::Points(20.0000),
2876                                height: stretch::style::Dimension::Points(100.0000),
2877                                ..Default::default()
2878                            },
2879                            ..Default::default()
2880                        }],
2881                        ..Default::default()
2882                    },
2883                ],
2884                ..Default::default()
2885            },
2886            stretch::geometry::Size::undefined(),
2887        )
2888        .unwrap();
2889
2890        assert_eq!(layout.size.width, 90.0000);
2891        assert_eq!(layout.size.height, 100.0000);
2892        assert_eq!(layout.location.x, 0.0000);
2893        assert_eq!(layout.location.y, 0.0000);
2894
2895        assert_eq!(layout.children[0].size.width, 70.0000);
2896        assert_eq!(layout.children[0].size.height, 100.0000);
2897        assert_eq!(layout.children[0].location.x, 0.0000);
2898        assert_eq!(layout.children[0].location.y, 0.0000);
2899
2900        assert_eq!(layout.children[0].children[0].size.width, 70.0000);
2901        assert_eq!(layout.children[0].children[0].size.height, 100.0000);
2902        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
2903        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
2904
2905        assert_eq!(layout.children[1].size.width, 20.0000);
2906        assert_eq!(layout.children[1].size.height, 100.0000);
2907        assert_eq!(layout.children[1].location.x, 70.0000);
2908        assert_eq!(layout.children[1].location.y, 0.0000);
2909
2910        assert_eq!(layout.children[1].children[0].size.width, 20.0000);
2911        assert_eq!(layout.children[1].children[0].size.height, 100.0000);
2912        assert_eq!(layout.children[1].children[0].location.x, 0.0000);
2913        assert_eq!(layout.children[1].children[0].location.y, 0.0000);
2914    }
2915
2916    #[test]
2917    fn justify_content_row_min_width_and_margin() {
2918        let layout = stretch::compute(
2919            &stretch::style::Node {
2920                justify_content: stretch::style::JustifyContent::Center,
2921                min_size: stretch::geometry::Size {
2922                    width: stretch::style::Dimension::Points(50.0000),
2923                    ..Default::default()
2924                },
2925                children: vec![stretch::style::Node {
2926                    size: stretch::geometry::Size {
2927                        width: stretch::style::Dimension::Points(20.0000),
2928                        height: stretch::style::Dimension::Points(20.0000),
2929                        ..Default::default()
2930                    },
2931                    margin: stretch::geometry::Rect {
2932                        start: stretch::style::Dimension::Points(10.0000),
2933                        ..Default::default()
2934                    },
2935                    ..Default::default()
2936                }],
2937                ..Default::default()
2938            },
2939            stretch::geometry::Size::undefined(),
2940        )
2941        .unwrap();
2942
2943        assert_eq!(layout.size.width, 50.0000);
2944        assert_eq!(layout.size.height, 20.0000);
2945        assert_eq!(layout.location.x, 0.0000);
2946        assert_eq!(layout.location.y, 0.0000);
2947
2948        assert_eq!(layout.children[0].size.width, 20.0000);
2949        assert_eq!(layout.children[0].size.height, 20.0000);
2950        assert_eq!(layout.children[0].location.x, 20.0000);
2951        assert_eq!(layout.children[0].location.y, 0.0000);
2952    }
2953
2954    #[test]
2955    fn align_self_flex_start() {
2956        let layout = stretch::compute(
2957            &stretch::style::Node {
2958                size: stretch::geometry::Size {
2959                    width: stretch::style::Dimension::Points(100.0000),
2960                    height: stretch::style::Dimension::Points(100.0000),
2961                    ..Default::default()
2962                },
2963                children: vec![stretch::style::Node {
2964                    align_self: stretch::style::AlignSelf::FlexStart,
2965                    size: stretch::geometry::Size {
2966                        width: stretch::style::Dimension::Points(10.0000),
2967                        height: stretch::style::Dimension::Points(10.0000),
2968                        ..Default::default()
2969                    },
2970                    ..Default::default()
2971                }],
2972                ..Default::default()
2973            },
2974            stretch::geometry::Size::undefined(),
2975        )
2976        .unwrap();
2977
2978        assert_eq!(layout.size.width, 100.0000);
2979        assert_eq!(layout.size.height, 100.0000);
2980        assert_eq!(layout.location.x, 0.0000);
2981        assert_eq!(layout.location.y, 0.0000);
2982
2983        assert_eq!(layout.children[0].size.width, 10.0000);
2984        assert_eq!(layout.children[0].size.height, 10.0000);
2985        assert_eq!(layout.children[0].location.x, 0.0000);
2986        assert_eq!(layout.children[0].location.y, 0.0000);
2987    }
2988
2989    #[test]
2990    fn percentage_position_left_top() {
2991        let layout = stretch::compute(
2992            &stretch::style::Node {
2993                size: stretch::geometry::Size {
2994                    width: stretch::style::Dimension::Points(400.0000),
2995                    height: stretch::style::Dimension::Points(400.0000),
2996                    ..Default::default()
2997                },
2998                children: vec![stretch::style::Node {
2999                    size: stretch::geometry::Size {
3000                        width: stretch::style::Dimension::Percent(0.4500),
3001                        height: stretch::style::Dimension::Percent(0.5500),
3002                        ..Default::default()
3003                    },
3004                    position: stretch::geometry::Rect {
3005                        start: stretch::style::Dimension::Percent(0.1000),
3006                        top: stretch::style::Dimension::Percent(0.2000),
3007                        ..Default::default()
3008                    },
3009                    ..Default::default()
3010                }],
3011                ..Default::default()
3012            },
3013            stretch::geometry::Size::undefined(),
3014        )
3015        .unwrap();
3016
3017        assert_eq!(layout.size.width, 400.0000);
3018        assert_eq!(layout.size.height, 400.0000);
3019        assert_eq!(layout.location.x, 0.0000);
3020        assert_eq!(layout.location.y, 0.0000);
3021
3022        assert_eq!(layout.children[0].size.width, 180.0000);
3023        assert_eq!(layout.children[0].size.height, 220.0000);
3024        assert_eq!(layout.children[0].location.x, 40.0000);
3025        assert_eq!(layout.children[0].location.y, 80.0000);
3026    }
3027
3028    #[test]
3029    fn border_stretch_child() {
3030        let layout = stretch::compute(
3031            &stretch::style::Node {
3032                size: stretch::geometry::Size {
3033                    width: stretch::style::Dimension::Points(100.0000),
3034                    height: stretch::style::Dimension::Points(100.0000),
3035                    ..Default::default()
3036                },
3037                border: stretch::geometry::Rect {
3038                    start: stretch::style::Dimension::Points(10.0000),
3039                    end: stretch::style::Dimension::Points(10.0000),
3040                    top: stretch::style::Dimension::Points(10.0000),
3041                    bottom: stretch::style::Dimension::Points(10.0000),
3042                    ..Default::default()
3043                },
3044                children: vec![stretch::style::Node {
3045                    size: stretch::geometry::Size {
3046                        width: stretch::style::Dimension::Points(10.0000),
3047                        ..Default::default()
3048                    },
3049                    ..Default::default()
3050                }],
3051                ..Default::default()
3052            },
3053            stretch::geometry::Size::undefined(),
3054        )
3055        .unwrap();
3056
3057        assert_eq!(layout.size.width, 100.0000);
3058        assert_eq!(layout.size.height, 100.0000);
3059        assert_eq!(layout.location.x, 0.0000);
3060        assert_eq!(layout.location.y, 0.0000);
3061
3062        assert_eq!(layout.children[0].size.width, 10.0000);
3063        assert_eq!(layout.children[0].size.height, 80.0000);
3064        assert_eq!(layout.children[0].location.x, 10.0000);
3065        assert_eq!(layout.children[0].location.y, 10.0000);
3066    }
3067
3068    #[test]
3069    fn rounding_fractial_input_2() {
3070        let layout = stretch::compute(
3071            &stretch::style::Node {
3072                flex_direction: stretch::style::FlexDirection::Column,
3073                size: stretch::geometry::Size {
3074                    width: stretch::style::Dimension::Points(100.0000),
3075                    height: stretch::style::Dimension::Points(113.6000),
3076                    ..Default::default()
3077                },
3078                children: vec![
3079                    stretch::style::Node {
3080                        flex_grow: 1.0000,
3081                        flex_basis: stretch::style::Dimension::Points(50.0000),
3082                        size: stretch::geometry::Size {
3083                            height: stretch::style::Dimension::Points(20.0000),
3084                            ..Default::default()
3085                        },
3086                        ..Default::default()
3087                    },
3088                    stretch::style::Node {
3089                        flex_grow: 1.0000,
3090                        size: stretch::geometry::Size {
3091                            height: stretch::style::Dimension::Points(10.0000),
3092                            ..Default::default()
3093                        },
3094                        ..Default::default()
3095                    },
3096                    stretch::style::Node {
3097                        flex_grow: 1.0000,
3098                        size: stretch::geometry::Size {
3099                            height: stretch::style::Dimension::Points(10.0000),
3100                            ..Default::default()
3101                        },
3102                        ..Default::default()
3103                    },
3104                ],
3105                ..Default::default()
3106            },
3107            stretch::geometry::Size::undefined(),
3108        )
3109        .unwrap();
3110
3111        assert_eq!(layout.size.width, 100.0000);
3112        assert_eq!(layout.size.height, 114.0000);
3113        assert_eq!(layout.location.x, 0.0000);
3114        assert_eq!(layout.location.y, 0.0000);
3115
3116        assert_eq!(layout.children[0].size.width, 100.0000);
3117        assert_eq!(layout.children[0].size.height, 65.0000);
3118        assert_eq!(layout.children[0].location.x, 0.0000);
3119        assert_eq!(layout.children[0].location.y, 0.0000);
3120
3121        assert_eq!(layout.children[1].size.width, 100.0000);
3122        assert_eq!(layout.children[1].size.height, 24.0000);
3123        assert_eq!(layout.children[1].location.x, 0.0000);
3124        assert_eq!(layout.children[1].location.y, 65.0000);
3125
3126        assert_eq!(layout.children[2].size.width, 100.0000);
3127        assert_eq!(layout.children[2].size.height, 25.0000);
3128        assert_eq!(layout.children[2].location.x, 0.0000);
3129        assert_eq!(layout.children[2].location.y, 89.0000);
3130    }
3131
3132    #[test]
3133    fn percentage_flex_basis_main_max_width() {
3134        let layout = stretch::compute(
3135            &stretch::style::Node {
3136                size: stretch::geometry::Size {
3137                    width: stretch::style::Dimension::Points(200.0000),
3138                    height: stretch::style::Dimension::Points(400.0000),
3139                    ..Default::default()
3140                },
3141                children: vec![
3142                    stretch::style::Node {
3143                        flex_grow: 1.0000,
3144                        flex_basis: stretch::style::Dimension::Percent(0.1500),
3145                        max_size: stretch::geometry::Size {
3146                            width: stretch::style::Dimension::Percent(0.6000),
3147                            ..Default::default()
3148                        },
3149                        ..Default::default()
3150                    },
3151                    stretch::style::Node {
3152                        flex_grow: 4.0000,
3153                        flex_basis: stretch::style::Dimension::Percent(0.1000),
3154                        max_size: stretch::geometry::Size {
3155                            width: stretch::style::Dimension::Percent(0.2000),
3156                            ..Default::default()
3157                        },
3158                        ..Default::default()
3159                    },
3160                ],
3161                ..Default::default()
3162            },
3163            stretch::geometry::Size::undefined(),
3164        )
3165        .unwrap();
3166
3167        assert_eq!(layout.size.width, 200.0000);
3168        assert_eq!(layout.size.height, 400.0000);
3169        assert_eq!(layout.location.x, 0.0000);
3170        assert_eq!(layout.location.y, 0.0000);
3171
3172        assert_eq!(layout.children[0].size.width, 120.0000);
3173        assert_eq!(layout.children[0].size.height, 400.0000);
3174        assert_eq!(layout.children[0].location.x, 0.0000);
3175        assert_eq!(layout.children[0].location.y, 0.0000);
3176
3177        assert_eq!(layout.children[1].size.width, 40.0000);
3178        assert_eq!(layout.children[1].size.height, 400.0000);
3179        assert_eq!(layout.children[1].location.x, 120.0000);
3180        assert_eq!(layout.children[1].location.y, 0.0000);
3181    }
3182
3183    #[test]
3184    fn margin_auto_top_and_bottom_strech() {
3185        let layout = stretch::compute(
3186            &stretch::style::Node {
3187                flex_direction: stretch::style::FlexDirection::Column,
3188                size: stretch::geometry::Size {
3189                    width: stretch::style::Dimension::Points(200.0000),
3190                    height: stretch::style::Dimension::Points(200.0000),
3191                    ..Default::default()
3192                },
3193                children: vec![
3194                    stretch::style::Node {
3195                        size: stretch::geometry::Size {
3196                            width: stretch::style::Dimension::Points(50.0000),
3197                            height: stretch::style::Dimension::Points(50.0000),
3198                            ..Default::default()
3199                        },
3200                        margin: stretch::geometry::Rect {
3201                            top: stretch::style::Dimension::Auto,
3202                            bottom: stretch::style::Dimension::Auto,
3203                            ..Default::default()
3204                        },
3205                        ..Default::default()
3206                    },
3207                    stretch::style::Node {
3208                        size: stretch::geometry::Size {
3209                            width: stretch::style::Dimension::Points(50.0000),
3210                            height: stretch::style::Dimension::Points(50.0000),
3211                            ..Default::default()
3212                        },
3213                        ..Default::default()
3214                    },
3215                ],
3216                ..Default::default()
3217            },
3218            stretch::geometry::Size::undefined(),
3219        )
3220        .unwrap();
3221
3222        assert_eq!(layout.size.width, 200.0000);
3223        assert_eq!(layout.size.height, 200.0000);
3224        assert_eq!(layout.location.x, 0.0000);
3225        assert_eq!(layout.location.y, 0.0000);
3226
3227        assert_eq!(layout.children[0].size.width, 50.0000);
3228        assert_eq!(layout.children[0].size.height, 50.0000);
3229        assert_eq!(layout.children[0].location.x, 0.0000);
3230        assert_eq!(layout.children[0].location.y, 50.0000);
3231
3232        assert_eq!(layout.children[1].size.width, 50.0000);
3233        assert_eq!(layout.children[1].size.height, 50.0000);
3234        assert_eq!(layout.children[1].location.x, 0.0000);
3235        assert_eq!(layout.children[1].location.y, 150.0000);
3236    }
3237
3238    #[test]
3239    fn percentage_multiple_nested_with_padding_margin_and_percentage_values() {
3240        let layout = stretch::compute(
3241            &stretch::style::Node {
3242                flex_direction: stretch::style::FlexDirection::Column,
3243                size: stretch::geometry::Size {
3244                    width: stretch::style::Dimension::Points(200.0000),
3245                    height: stretch::style::Dimension::Points(200.0000),
3246                    ..Default::default()
3247                },
3248                children: vec![
3249                    stretch::style::Node {
3250                        flex_direction: stretch::style::FlexDirection::Column,
3251                        flex_grow: 1.0000,
3252                        flex_basis: stretch::style::Dimension::Percent(0.1000),
3253                        min_size: stretch::geometry::Size {
3254                            width: stretch::style::Dimension::Percent(0.6000),
3255                            ..Default::default()
3256                        },
3257                        margin: stretch::geometry::Rect {
3258                            start: stretch::style::Dimension::Points(5.0000),
3259                            end: stretch::style::Dimension::Points(5.0000),
3260                            top: stretch::style::Dimension::Points(5.0000),
3261                            bottom: stretch::style::Dimension::Points(5.0000),
3262                            ..Default::default()
3263                        },
3264                        padding: stretch::geometry::Rect {
3265                            start: stretch::style::Dimension::Points(3.0000),
3266                            end: stretch::style::Dimension::Points(3.0000),
3267                            top: stretch::style::Dimension::Points(3.0000),
3268                            bottom: stretch::style::Dimension::Points(3.0000),
3269                            ..Default::default()
3270                        },
3271                        children: vec![stretch::style::Node {
3272                            flex_direction: stretch::style::FlexDirection::Column,
3273                            size: stretch::geometry::Size {
3274                                width: stretch::style::Dimension::Percent(0.5000),
3275                                ..Default::default()
3276                            },
3277                            margin: stretch::geometry::Rect {
3278                                start: stretch::style::Dimension::Points(5.0000),
3279                                end: stretch::style::Dimension::Points(5.0000),
3280                                top: stretch::style::Dimension::Points(5.0000),
3281                                bottom: stretch::style::Dimension::Points(5.0000),
3282                                ..Default::default()
3283                            },
3284                            padding: stretch::geometry::Rect {
3285                                start: stretch::style::Dimension::Percent(0.0300),
3286                                end: stretch::style::Dimension::Percent(0.0300),
3287                                top: stretch::style::Dimension::Percent(0.0300),
3288                                bottom: stretch::style::Dimension::Percent(0.0300),
3289                                ..Default::default()
3290                            },
3291                            children: vec![stretch::style::Node {
3292                                size: stretch::geometry::Size {
3293                                    width: stretch::style::Dimension::Percent(0.4500),
3294                                    ..Default::default()
3295                                },
3296                                margin: stretch::geometry::Rect {
3297                                    start: stretch::style::Dimension::Percent(0.0500),
3298                                    end: stretch::style::Dimension::Percent(0.0500),
3299                                    top: stretch::style::Dimension::Percent(0.0500),
3300                                    bottom: stretch::style::Dimension::Percent(0.0500),
3301                                    ..Default::default()
3302                                },
3303                                padding: stretch::geometry::Rect {
3304                                    start: stretch::style::Dimension::Points(3.0000),
3305                                    end: stretch::style::Dimension::Points(3.0000),
3306                                    top: stretch::style::Dimension::Points(3.0000),
3307                                    bottom: stretch::style::Dimension::Points(3.0000),
3308                                    ..Default::default()
3309                                },
3310                                ..Default::default()
3311                            }],
3312                            ..Default::default()
3313                        }],
3314                        ..Default::default()
3315                    },
3316                    stretch::style::Node {
3317                        flex_grow: 4.0000,
3318                        flex_basis: stretch::style::Dimension::Percent(0.1500),
3319                        min_size: stretch::geometry::Size {
3320                            width: stretch::style::Dimension::Percent(0.2000),
3321                            ..Default::default()
3322                        },
3323                        ..Default::default()
3324                    },
3325                ],
3326                ..Default::default()
3327            },
3328            stretch::geometry::Size::undefined(),
3329        )
3330        .unwrap();
3331
3332        assert_eq!(layout.size.width, 200.0000);
3333        assert_eq!(layout.size.height, 200.0000);
3334        assert_eq!(layout.location.x, 0.0000);
3335        assert_eq!(layout.location.y, 0.0000);
3336
3337        assert_eq!(layout.children[0].size.width, 190.0000);
3338        assert_eq!(layout.children[0].size.height, 48.0000);
3339        assert_eq!(layout.children[0].location.x, 5.0000);
3340        assert_eq!(layout.children[0].location.y, 5.0000);
3341
3342        assert_eq!(layout.children[0].children[0].size.width, 92.0000);
3343        assert_eq!(layout.children[0].children[0].size.height, 25.0000);
3344        assert_eq!(layout.children[0].children[0].location.x, 8.0000);
3345        assert_eq!(layout.children[0].children[0].location.y, 8.0000);
3346
3347        assert_eq!(layout.children[0].children[0].children[0].size.width, 36.0000);
3348        assert_eq!(layout.children[0].children[0].children[0].size.height, 6.0000);
3349        assert_eq!(layout.children[0].children[0].children[0].location.x, 10.0000);
3350        assert_eq!(layout.children[0].children[0].children[0].location.y, 10.0000);
3351
3352        assert_eq!(layout.children[1].size.width, 200.0000);
3353        assert_eq!(layout.children[1].size.height, 142.0000);
3354        assert_eq!(layout.children[1].location.x, 0.0000);
3355        assert_eq!(layout.children[1].location.y, 58.0000);
3356    }
3357
3358    #[test]
3359    fn flex_grow_within_constrained_min_column() {
3360        let layout = stretch::compute(
3361            &stretch::style::Node {
3362                flex_direction: stretch::style::FlexDirection::Column,
3363                min_size: stretch::geometry::Size {
3364                    height: stretch::style::Dimension::Points(100.0000),
3365                    ..Default::default()
3366                },
3367                children: vec![
3368                    stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
3369                    stretch::style::Node {
3370                        size: stretch::geometry::Size {
3371                            height: stretch::style::Dimension::Points(50.0000),
3372                            ..Default::default()
3373                        },
3374                        ..Default::default()
3375                    },
3376                ],
3377                ..Default::default()
3378            },
3379            stretch::geometry::Size::undefined(),
3380        )
3381        .unwrap();
3382
3383        assert_eq!(layout.size.width, 0.0000);
3384        assert_eq!(layout.size.height, 100.0000);
3385        assert_eq!(layout.location.x, 0.0000);
3386        assert_eq!(layout.location.y, 0.0000);
3387
3388        assert_eq!(layout.children[0].size.width, 0.0000);
3389        assert_eq!(layout.children[0].size.height, 50.0000);
3390        assert_eq!(layout.children[0].location.x, 0.0000);
3391        assert_eq!(layout.children[0].location.y, 0.0000);
3392
3393        assert_eq!(layout.children[1].size.width, 0.0000);
3394        assert_eq!(layout.children[1].size.height, 50.0000);
3395        assert_eq!(layout.children[1].location.x, 0.0000);
3396        assert_eq!(layout.children[1].location.y, 50.0000);
3397    }
3398
3399    #[test]
3400    fn flex_grow_in_at_most_container() {
3401        let layout = stretch::compute(
3402            &stretch::style::Node {
3403                align_items: stretch::style::AlignItems::FlexStart,
3404                size: stretch::geometry::Size {
3405                    width: stretch::style::Dimension::Points(100.0000),
3406                    height: stretch::style::Dimension::Points(100.0000),
3407                    ..Default::default()
3408                },
3409                children: vec![stretch::style::Node {
3410                    children: vec![stretch::style::Node {
3411                        flex_grow: 1.0000,
3412                        flex_basis: stretch::style::Dimension::Points(0.0000),
3413                        ..Default::default()
3414                    }],
3415                    ..Default::default()
3416                }],
3417                ..Default::default()
3418            },
3419            stretch::geometry::Size::undefined(),
3420        )
3421        .unwrap();
3422
3423        assert_eq!(layout.size.width, 100.0000);
3424        assert_eq!(layout.size.height, 100.0000);
3425        assert_eq!(layout.location.x, 0.0000);
3426        assert_eq!(layout.location.y, 0.0000);
3427
3428        assert_eq!(layout.children[0].size.width, 0.0000);
3429        assert_eq!(layout.children[0].size.height, 0.0000);
3430        assert_eq!(layout.children[0].location.x, 0.0000);
3431        assert_eq!(layout.children[0].location.y, 0.0000);
3432
3433        assert_eq!(layout.children[0].children[0].size.width, 0.0000);
3434        assert_eq!(layout.children[0].children[0].size.height, 0.0000);
3435        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
3436        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
3437    }
3438
3439    #[test]
3440    fn margin_auto_left() {
3441        let layout = stretch::compute(
3442            &stretch::style::Node {
3443                align_items: stretch::style::AlignItems::Center,
3444                size: stretch::geometry::Size {
3445                    width: stretch::style::Dimension::Points(200.0000),
3446                    height: stretch::style::Dimension::Points(200.0000),
3447                    ..Default::default()
3448                },
3449                children: vec![
3450                    stretch::style::Node {
3451                        size: stretch::geometry::Size {
3452                            width: stretch::style::Dimension::Points(50.0000),
3453                            height: stretch::style::Dimension::Points(50.0000),
3454                            ..Default::default()
3455                        },
3456                        margin: stretch::geometry::Rect {
3457                            start: stretch::style::Dimension::Auto,
3458                            ..Default::default()
3459                        },
3460                        ..Default::default()
3461                    },
3462                    stretch::style::Node {
3463                        size: stretch::geometry::Size {
3464                            width: stretch::style::Dimension::Points(50.0000),
3465                            height: stretch::style::Dimension::Points(50.0000),
3466                            ..Default::default()
3467                        },
3468                        ..Default::default()
3469                    },
3470                ],
3471                ..Default::default()
3472            },
3473            stretch::geometry::Size::undefined(),
3474        )
3475        .unwrap();
3476
3477        assert_eq!(layout.size.width, 200.0000);
3478        assert_eq!(layout.size.height, 200.0000);
3479        assert_eq!(layout.location.x, 0.0000);
3480        assert_eq!(layout.location.y, 0.0000);
3481
3482        assert_eq!(layout.children[0].size.width, 50.0000);
3483        assert_eq!(layout.children[0].size.height, 50.0000);
3484        assert_eq!(layout.children[0].location.x, 100.0000);
3485        assert_eq!(layout.children[0].location.y, 75.0000);
3486
3487        assert_eq!(layout.children[1].size.width, 50.0000);
3488        assert_eq!(layout.children[1].size.height, 50.0000);
3489        assert_eq!(layout.children[1].location.x, 150.0000);
3490        assert_eq!(layout.children[1].location.y, 75.0000);
3491    }
3492
3493    #[test]
3494    fn percentage_flex_basis_cross() {
3495        let layout = stretch::compute(
3496            &stretch::style::Node {
3497                flex_direction: stretch::style::FlexDirection::Column,
3498                size: stretch::geometry::Size {
3499                    width: stretch::style::Dimension::Points(200.0000),
3500                    height: stretch::style::Dimension::Points(400.0000),
3501                    ..Default::default()
3502                },
3503                children: vec![
3504                    stretch::style::Node {
3505                        flex_grow: 1.0000,
3506                        flex_basis: stretch::style::Dimension::Percent(0.5000),
3507                        ..Default::default()
3508                    },
3509                    stretch::style::Node {
3510                        flex_grow: 1.0000,
3511                        flex_basis: stretch::style::Dimension::Percent(0.2500),
3512                        ..Default::default()
3513                    },
3514                ],
3515                ..Default::default()
3516            },
3517            stretch::geometry::Size::undefined(),
3518        )
3519        .unwrap();
3520
3521        assert_eq!(layout.size.width, 200.0000);
3522        assert_eq!(layout.size.height, 400.0000);
3523        assert_eq!(layout.location.x, 0.0000);
3524        assert_eq!(layout.location.y, 0.0000);
3525
3526        assert_eq!(layout.children[0].size.width, 200.0000);
3527        assert_eq!(layout.children[0].size.height, 250.0000);
3528        assert_eq!(layout.children[0].location.x, 0.0000);
3529        assert_eq!(layout.children[0].location.y, 0.0000);
3530
3531        assert_eq!(layout.children[1].size.width, 200.0000);
3532        assert_eq!(layout.children[1].size.height, 150.0000);
3533        assert_eq!(layout.children[1].location.x, 0.0000);
3534        assert_eq!(layout.children[1].location.y, 250.0000);
3535    }
3536
3537    #[test]
3538    fn percentage_absolute_position() {
3539        let layout = stretch::compute(
3540            &stretch::style::Node {
3541                flex_direction: stretch::style::FlexDirection::Column,
3542                size: stretch::geometry::Size {
3543                    width: stretch::style::Dimension::Points(200.0000),
3544                    height: stretch::style::Dimension::Points(100.0000),
3545                    ..Default::default()
3546                },
3547                children: vec![stretch::style::Node {
3548                    position_type: stretch::style::PositionType::Absolute,
3549                    size: stretch::geometry::Size {
3550                        width: stretch::style::Dimension::Points(10.0000),
3551                        height: stretch::style::Dimension::Points(10.0000),
3552                        ..Default::default()
3553                    },
3554                    position: stretch::geometry::Rect {
3555                        start: stretch::style::Dimension::Percent(0.3000),
3556                        top: stretch::style::Dimension::Percent(0.1000),
3557                        ..Default::default()
3558                    },
3559                    ..Default::default()
3560                }],
3561                ..Default::default()
3562            },
3563            stretch::geometry::Size::undefined(),
3564        )
3565        .unwrap();
3566
3567        assert_eq!(layout.size.width, 200.0000);
3568        assert_eq!(layout.size.height, 100.0000);
3569        assert_eq!(layout.location.x, 0.0000);
3570        assert_eq!(layout.location.y, 0.0000);
3571
3572        assert_eq!(layout.children[0].size.width, 10.0000);
3573        assert_eq!(layout.children[0].size.height, 10.0000);
3574        assert_eq!(layout.children[0].location.x, 60.0000);
3575        assert_eq!(layout.children[0].location.y, 10.0000);
3576    }
3577
3578    #[test]
3579    fn flex_basis_flex_grow_row() {
3580        let layout = stretch::compute(
3581            &stretch::style::Node {
3582                size: stretch::geometry::Size {
3583                    width: stretch::style::Dimension::Points(100.0000),
3584                    height: stretch::style::Dimension::Points(100.0000),
3585                    ..Default::default()
3586                },
3587                children: vec![
3588                    stretch::style::Node {
3589                        flex_grow: 1.0000,
3590                        flex_basis: stretch::style::Dimension::Points(50.0000),
3591                        ..Default::default()
3592                    },
3593                    stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
3594                ],
3595                ..Default::default()
3596            },
3597            stretch::geometry::Size::undefined(),
3598        )
3599        .unwrap();
3600
3601        assert_eq!(layout.size.width, 100.0000);
3602        assert_eq!(layout.size.height, 100.0000);
3603        assert_eq!(layout.location.x, 0.0000);
3604        assert_eq!(layout.location.y, 0.0000);
3605
3606        assert_eq!(layout.children[0].size.width, 75.0000);
3607        assert_eq!(layout.children[0].size.height, 100.0000);
3608        assert_eq!(layout.children[0].location.x, 0.0000);
3609        assert_eq!(layout.children[0].location.y, 0.0000);
3610
3611        assert_eq!(layout.children[1].size.width, 25.0000);
3612        assert_eq!(layout.children[1].size.height, 100.0000);
3613        assert_eq!(layout.children[1].location.x, 75.0000);
3614        assert_eq!(layout.children[1].location.y, 0.0000);
3615    }
3616
3617    #[test]
3618    fn absolute_layout_in_wrap_reverse_column_container_flex_end() {
3619        let layout = stretch::compute(
3620            &stretch::style::Node {
3621                flex_direction: stretch::style::FlexDirection::Column,
3622                flex_wrap: stretch::style::FlexWrap::WrapReverse,
3623                size: stretch::geometry::Size {
3624                    width: stretch::style::Dimension::Points(100.0000),
3625                    height: stretch::style::Dimension::Points(100.0000),
3626                    ..Default::default()
3627                },
3628                children: vec![stretch::style::Node {
3629                    position_type: stretch::style::PositionType::Absolute,
3630                    align_self: stretch::style::AlignSelf::FlexEnd,
3631                    size: stretch::geometry::Size {
3632                        width: stretch::style::Dimension::Points(20.0000),
3633                        height: stretch::style::Dimension::Points(20.0000),
3634                        ..Default::default()
3635                    },
3636                    ..Default::default()
3637                }],
3638                ..Default::default()
3639            },
3640            stretch::geometry::Size::undefined(),
3641        )
3642        .unwrap();
3643
3644        assert_eq!(layout.size.width, 100.0000);
3645        assert_eq!(layout.size.height, 100.0000);
3646        assert_eq!(layout.location.x, 0.0000);
3647        assert_eq!(layout.location.y, 0.0000);
3648
3649        assert_eq!(layout.children[0].size.width, 20.0000);
3650        assert_eq!(layout.children[0].size.height, 20.0000);
3651        assert_eq!(layout.children[0].location.x, 0.0000);
3652        assert_eq!(layout.children[0].location.y, 0.0000);
3653    }
3654
3655    #[test]
3656    fn justify_content_row_flex_start() {
3657        let layout = stretch::compute(
3658            &stretch::style::Node {
3659                size: stretch::geometry::Size {
3660                    width: stretch::style::Dimension::Points(100.0000),
3661                    height: stretch::style::Dimension::Points(100.0000),
3662                    ..Default::default()
3663                },
3664                children: vec![
3665                    stretch::style::Node {
3666                        size: stretch::geometry::Size {
3667                            width: stretch::style::Dimension::Points(10.0000),
3668                            ..Default::default()
3669                        },
3670                        ..Default::default()
3671                    },
3672                    stretch::style::Node {
3673                        size: stretch::geometry::Size {
3674                            width: stretch::style::Dimension::Points(10.0000),
3675                            ..Default::default()
3676                        },
3677                        ..Default::default()
3678                    },
3679                    stretch::style::Node {
3680                        size: stretch::geometry::Size {
3681                            width: stretch::style::Dimension::Points(10.0000),
3682                            ..Default::default()
3683                        },
3684                        ..Default::default()
3685                    },
3686                ],
3687                ..Default::default()
3688            },
3689            stretch::geometry::Size::undefined(),
3690        )
3691        .unwrap();
3692
3693        assert_eq!(layout.size.width, 100.0000);
3694        assert_eq!(layout.size.height, 100.0000);
3695        assert_eq!(layout.location.x, 0.0000);
3696        assert_eq!(layout.location.y, 0.0000);
3697
3698        assert_eq!(layout.children[0].size.width, 10.0000);
3699        assert_eq!(layout.children[0].size.height, 100.0000);
3700        assert_eq!(layout.children[0].location.x, 0.0000);
3701        assert_eq!(layout.children[0].location.y, 0.0000);
3702
3703        assert_eq!(layout.children[1].size.width, 10.0000);
3704        assert_eq!(layout.children[1].size.height, 100.0000);
3705        assert_eq!(layout.children[1].location.x, 10.0000);
3706        assert_eq!(layout.children[1].location.y, 0.0000);
3707
3708        assert_eq!(layout.children[2].size.width, 10.0000);
3709        assert_eq!(layout.children[2].size.height, 100.0000);
3710        assert_eq!(layout.children[2].location.x, 20.0000);
3711        assert_eq!(layout.children[2].location.y, 0.0000);
3712    }
3713
3714    #[test]
3715    fn margin_auto_left_right_child_bigger_than_parent() {
3716        let layout = stretch::compute(
3717            &stretch::style::Node {
3718                justify_content: stretch::style::JustifyContent::Center,
3719                size: stretch::geometry::Size {
3720                    width: stretch::style::Dimension::Points(52.0000),
3721                    height: stretch::style::Dimension::Points(52.0000),
3722                    ..Default::default()
3723                },
3724                children: vec![stretch::style::Node {
3725                    size: stretch::geometry::Size {
3726                        width: stretch::style::Dimension::Points(72.0000),
3727                        height: stretch::style::Dimension::Points(72.0000),
3728                        ..Default::default()
3729                    },
3730                    margin: stretch::geometry::Rect {
3731                        start: stretch::style::Dimension::Auto,
3732                        end: stretch::style::Dimension::Auto,
3733                        ..Default::default()
3734                    },
3735                    ..Default::default()
3736                }],
3737                ..Default::default()
3738            },
3739            stretch::geometry::Size::undefined(),
3740        )
3741        .unwrap();
3742
3743        assert_eq!(layout.size.width, 52.0000);
3744        assert_eq!(layout.size.height, 52.0000);
3745        assert_eq!(layout.location.x, 0.0000);
3746        assert_eq!(layout.location.y, 0.0000);
3747
3748        assert_eq!(layout.children[0].size.width, 52.0000);
3749        assert_eq!(layout.children[0].size.height, 72.0000);
3750        assert_eq!(layout.children[0].location.x, 0.0000);
3751        assert_eq!(layout.children[0].location.y, 0.0000);
3752    }
3753
3754    #[test]
3755    fn flex_basis_larger_than_content_column() {
3756        let layout = stretch::compute(
3757            &stretch::style::Node {
3758                flex_direction: stretch::style::FlexDirection::Column,
3759                size: stretch::geometry::Size {
3760                    height: stretch::style::Dimension::Points(100.0000),
3761                    ..Default::default()
3762                },
3763                children: vec![stretch::style::Node {
3764                    flex_direction: stretch::style::FlexDirection::Column,
3765                    flex_basis: stretch::style::Dimension::Points(50.0000),
3766                    children: vec![stretch::style::Node {
3767                        size: stretch::geometry::Size {
3768                            width: stretch::style::Dimension::Points(100.0000),
3769                            height: stretch::style::Dimension::Points(10.0000),
3770                            ..Default::default()
3771                        },
3772                        ..Default::default()
3773                    }],
3774                    ..Default::default()
3775                }],
3776                ..Default::default()
3777            },
3778            stretch::geometry::Size::undefined(),
3779        )
3780        .unwrap();
3781
3782        assert_eq!(layout.size.width, 100.0000);
3783        assert_eq!(layout.size.height, 100.0000);
3784        assert_eq!(layout.location.x, 0.0000);
3785        assert_eq!(layout.location.y, 0.0000);
3786
3787        assert_eq!(layout.children[0].size.width, 100.0000);
3788        assert_eq!(layout.children[0].size.height, 50.0000);
3789        assert_eq!(layout.children[0].location.x, 0.0000);
3790        assert_eq!(layout.children[0].location.y, 0.0000);
3791
3792        assert_eq!(layout.children[0].children[0].size.width, 100.0000);
3793        assert_eq!(layout.children[0].children[0].size.height, 10.0000);
3794        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
3795        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
3796    }
3797
3798    #[test]
3799    fn margin_fix_left_auto_right_child_bigger_than_parent() {
3800        let layout = stretch::compute(
3801            &stretch::style::Node {
3802                justify_content: stretch::style::JustifyContent::Center,
3803                size: stretch::geometry::Size {
3804                    width: stretch::style::Dimension::Points(52.0000),
3805                    height: stretch::style::Dimension::Points(52.0000),
3806                    ..Default::default()
3807                },
3808                children: vec![stretch::style::Node {
3809                    size: stretch::geometry::Size {
3810                        width: stretch::style::Dimension::Points(72.0000),
3811                        height: stretch::style::Dimension::Points(72.0000),
3812                        ..Default::default()
3813                    },
3814                    margin: stretch::geometry::Rect {
3815                        start: stretch::style::Dimension::Points(10.0000),
3816                        end: stretch::style::Dimension::Auto,
3817                        ..Default::default()
3818                    },
3819                    ..Default::default()
3820                }],
3821                ..Default::default()
3822            },
3823            stretch::geometry::Size::undefined(),
3824        )
3825        .unwrap();
3826
3827        assert_eq!(layout.size.width, 52.0000);
3828        assert_eq!(layout.size.height, 52.0000);
3829        assert_eq!(layout.location.x, 0.0000);
3830        assert_eq!(layout.location.y, 0.0000);
3831
3832        assert_eq!(layout.children[0].size.width, 42.0000);
3833        assert_eq!(layout.children[0].size.height, 72.0000);
3834        assert_eq!(layout.children[0].location.x, 10.0000);
3835        assert_eq!(layout.children[0].location.y, 0.0000);
3836    }
3837
3838    #[test]
3839    fn percentage_container_in_wrapping_container() {
3840        let layout = stretch::compute(
3841            &stretch::style::Node {
3842                flex_direction: stretch::style::FlexDirection::Column,
3843                align_items: stretch::style::AlignItems::Center,
3844                justify_content: stretch::style::JustifyContent::Center,
3845                size: stretch::geometry::Size {
3846                    width: stretch::style::Dimension::Points(200.0000),
3847                    height: stretch::style::Dimension::Points(200.0000),
3848                    ..Default::default()
3849                },
3850                children: vec![stretch::style::Node {
3851                    flex_direction: stretch::style::FlexDirection::Column,
3852                    children: vec![stretch::style::Node {
3853                        justify_content: stretch::style::JustifyContent::Center,
3854                        size: stretch::geometry::Size {
3855                            width: stretch::style::Dimension::Percent(1.0000),
3856                            ..Default::default()
3857                        },
3858                        children: vec![
3859                            stretch::style::Node {
3860                                size: stretch::geometry::Size {
3861                                    width: stretch::style::Dimension::Points(50.0000),
3862                                    height: stretch::style::Dimension::Points(50.0000),
3863                                    ..Default::default()
3864                                },
3865                                ..Default::default()
3866                            },
3867                            stretch::style::Node {
3868                                size: stretch::geometry::Size {
3869                                    width: stretch::style::Dimension::Points(50.0000),
3870                                    height: stretch::style::Dimension::Points(50.0000),
3871                                    ..Default::default()
3872                                },
3873                                ..Default::default()
3874                            },
3875                        ],
3876                        ..Default::default()
3877                    }],
3878                    ..Default::default()
3879                }],
3880                ..Default::default()
3881            },
3882            stretch::geometry::Size::undefined(),
3883        )
3884        .unwrap();
3885
3886        assert_eq!(layout.size.width, 200.0000);
3887        assert_eq!(layout.size.height, 200.0000);
3888        assert_eq!(layout.location.x, 0.0000);
3889        assert_eq!(layout.location.y, 0.0000);
3890
3891        assert_eq!(layout.children[0].size.width, 100.0000);
3892        assert_eq!(layout.children[0].size.height, 50.0000);
3893        assert_eq!(layout.children[0].location.x, 50.0000);
3894        assert_eq!(layout.children[0].location.y, 75.0000);
3895
3896        assert_eq!(layout.children[0].children[0].size.width, 100.0000);
3897        assert_eq!(layout.children[0].children[0].size.height, 50.0000);
3898        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
3899        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
3900
3901        assert_eq!(layout.children[0].children[0].children[0].size.width, 50.0000);
3902        assert_eq!(layout.children[0].children[0].children[0].size.height, 50.0000);
3903        assert_eq!(layout.children[0].children[0].children[0].location.x, 0.0000);
3904        assert_eq!(layout.children[0].children[0].children[0].location.y, 0.0000);
3905
3906        assert_eq!(layout.children[0].children[0].children[1].size.width, 50.0000);
3907        assert_eq!(layout.children[0].children[0].children[1].size.height, 50.0000);
3908        assert_eq!(layout.children[0].children[0].children[1].location.x, 50.0000);
3909        assert_eq!(layout.children[0].children[0].children[1].location.y, 0.0000);
3910    }
3911
3912    #[test]
3913    fn margin_auto_left_stretching_child() {
3914        let layout = stretch::compute(
3915            &stretch::style::Node {
3916                align_items: stretch::style::AlignItems::Center,
3917                size: stretch::geometry::Size {
3918                    width: stretch::style::Dimension::Points(200.0000),
3919                    height: stretch::style::Dimension::Points(200.0000),
3920                    ..Default::default()
3921                },
3922                children: vec![
3923                    stretch::style::Node {
3924                        flex_grow: 1.0000,
3925                        flex_shrink: 1.0000,
3926                        flex_basis: stretch::style::Dimension::Percent(0.0000),
3927                        margin: stretch::geometry::Rect {
3928                            start: stretch::style::Dimension::Auto,
3929                            ..Default::default()
3930                        },
3931                        ..Default::default()
3932                    },
3933                    stretch::style::Node {
3934                        size: stretch::geometry::Size {
3935                            width: stretch::style::Dimension::Points(50.0000),
3936                            height: stretch::style::Dimension::Points(50.0000),
3937                            ..Default::default()
3938                        },
3939                        ..Default::default()
3940                    },
3941                ],
3942                ..Default::default()
3943            },
3944            stretch::geometry::Size::undefined(),
3945        )
3946        .unwrap();
3947
3948        assert_eq!(layout.size.width, 200.0000);
3949        assert_eq!(layout.size.height, 200.0000);
3950        assert_eq!(layout.location.x, 0.0000);
3951        assert_eq!(layout.location.y, 0.0000);
3952
3953        assert_eq!(layout.children[0].size.width, 150.0000);
3954        assert_eq!(layout.children[0].size.height, 0.0000);
3955        assert_eq!(layout.children[0].location.x, 0.0000);
3956        assert_eq!(layout.children[0].location.y, 100.0000);
3957
3958        assert_eq!(layout.children[1].size.width, 50.0000);
3959        assert_eq!(layout.children[1].size.height, 50.0000);
3960        assert_eq!(layout.children[1].location.x, 150.0000);
3961        assert_eq!(layout.children[1].location.y, 75.0000);
3962    }
3963
3964    #[test]
3965    fn flex_basis_smaller_then_content_with_flex_grow_small_size() {
3966        let layout = stretch::compute(
3967            &stretch::style::Node {
3968                size: stretch::geometry::Size {
3969                    width: stretch::style::Dimension::Points(10.0000),
3970                    ..Default::default()
3971                },
3972                children: vec![
3973                    stretch::style::Node {
3974                        flex_direction: stretch::style::FlexDirection::Column,
3975                        flex_grow: 1.0000,
3976                        flex_basis: stretch::style::Dimension::Points(0.0000),
3977                        children: vec![stretch::style::Node {
3978                            size: stretch::geometry::Size {
3979                                width: stretch::style::Dimension::Points(70.0000),
3980                                height: stretch::style::Dimension::Points(100.0000),
3981                                ..Default::default()
3982                            },
3983                            ..Default::default()
3984                        }],
3985                        ..Default::default()
3986                    },
3987                    stretch::style::Node {
3988                        flex_direction: stretch::style::FlexDirection::Column,
3989                        flex_grow: 1.0000,
3990                        flex_basis: stretch::style::Dimension::Points(0.0000),
3991                        children: vec![stretch::style::Node {
3992                            size: stretch::geometry::Size {
3993                                width: stretch::style::Dimension::Points(20.0000),
3994                                height: stretch::style::Dimension::Points(100.0000),
3995                                ..Default::default()
3996                            },
3997                            ..Default::default()
3998                        }],
3999                        ..Default::default()
4000                    },
4001                ],
4002                ..Default::default()
4003            },
4004            stretch::geometry::Size::undefined(),
4005        )
4006        .unwrap();
4007
4008        assert_eq!(layout.size.width, 10.0000);
4009        assert_eq!(layout.size.height, 100.0000);
4010        assert_eq!(layout.location.x, 0.0000);
4011        assert_eq!(layout.location.y, 0.0000);
4012
4013        assert_eq!(layout.children[0].size.width, 70.0000);
4014        assert_eq!(layout.children[0].size.height, 100.0000);
4015        assert_eq!(layout.children[0].location.x, 0.0000);
4016        assert_eq!(layout.children[0].location.y, 0.0000);
4017
4018        assert_eq!(layout.children[0].children[0].size.width, 70.0000);
4019        assert_eq!(layout.children[0].children[0].size.height, 100.0000);
4020        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
4021        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
4022
4023        assert_eq!(layout.children[1].size.width, 20.0000);
4024        assert_eq!(layout.children[1].size.height, 100.0000);
4025        assert_eq!(layout.children[1].location.x, 70.0000);
4026        assert_eq!(layout.children[1].location.y, 0.0000);
4027
4028        assert_eq!(layout.children[1].children[0].size.width, 20.0000);
4029        assert_eq!(layout.children[1].children[0].size.height, 100.0000);
4030        assert_eq!(layout.children[1].children[0].location.x, 0.0000);
4031        assert_eq!(layout.children[1].children[0].location.y, 0.0000);
4032    }
4033
4034    #[test]
4035    fn percentage_flex_basis_cross_max_width() {
4036        let layout = stretch::compute(
4037            &stretch::style::Node {
4038                flex_direction: stretch::style::FlexDirection::Column,
4039                size: stretch::geometry::Size {
4040                    width: stretch::style::Dimension::Points(200.0000),
4041                    height: stretch::style::Dimension::Points(400.0000),
4042                    ..Default::default()
4043                },
4044                children: vec![
4045                    stretch::style::Node {
4046                        flex_grow: 1.0000,
4047                        flex_basis: stretch::style::Dimension::Percent(0.1000),
4048                        max_size: stretch::geometry::Size {
4049                            width: stretch::style::Dimension::Percent(0.6000),
4050                            ..Default::default()
4051                        },
4052                        ..Default::default()
4053                    },
4054                    stretch::style::Node {
4055                        flex_grow: 4.0000,
4056                        flex_basis: stretch::style::Dimension::Percent(0.1500),
4057                        max_size: stretch::geometry::Size {
4058                            width: stretch::style::Dimension::Percent(0.2000),
4059                            ..Default::default()
4060                        },
4061                        ..Default::default()
4062                    },
4063                ],
4064                ..Default::default()
4065            },
4066            stretch::geometry::Size::undefined(),
4067        )
4068        .unwrap();
4069
4070        assert_eq!(layout.size.width, 200.0000);
4071        assert_eq!(layout.size.height, 400.0000);
4072        assert_eq!(layout.location.x, 0.0000);
4073        assert_eq!(layout.location.y, 0.0000);
4074
4075        assert_eq!(layout.children[0].size.width, 120.0000);
4076        assert_eq!(layout.children[0].size.height, 100.0000);
4077        assert_eq!(layout.children[0].location.x, 0.0000);
4078        assert_eq!(layout.children[0].location.y, 0.0000);
4079
4080        assert_eq!(layout.children[1].size.width, 40.0000);
4081        assert_eq!(layout.children[1].size.height, 300.0000);
4082        assert_eq!(layout.children[1].location.x, 0.0000);
4083        assert_eq!(layout.children[1].location.y, 100.0000);
4084    }
4085
4086    #[test]
4087    fn align_items_flex_end_child_without_margin_bigger_than_parent() {
4088        let layout = stretch::compute(
4089            &stretch::style::Node {
4090                align_items: stretch::style::AlignItems::Center,
4091                justify_content: stretch::style::JustifyContent::Center,
4092                size: stretch::geometry::Size {
4093                    width: stretch::style::Dimension::Points(50.0000),
4094                    height: stretch::style::Dimension::Points(50.0000),
4095                    ..Default::default()
4096                },
4097                children: vec![stretch::style::Node {
4098                    align_items: stretch::style::AlignItems::FlexEnd,
4099                    children: vec![stretch::style::Node {
4100                        size: stretch::geometry::Size {
4101                            width: stretch::style::Dimension::Points(70.0000),
4102                            height: stretch::style::Dimension::Points(70.0000),
4103                            ..Default::default()
4104                        },
4105                        ..Default::default()
4106                    }],
4107                    ..Default::default()
4108                }],
4109                ..Default::default()
4110            },
4111            stretch::geometry::Size::undefined(),
4112        )
4113        .unwrap();
4114
4115        assert_eq!(layout.size.width, 50.0000);
4116        assert_eq!(layout.size.height, 50.0000);
4117        assert_eq!(layout.location.x, 0.0000);
4118        assert_eq!(layout.location.y, 0.0000);
4119
4120        assert_eq!(layout.children[0].size.width, 70.0000);
4121        assert_eq!(layout.children[0].size.height, 70.0000);
4122        assert_eq!(layout.children[0].location.x, -10.0000);
4123        assert_eq!(layout.children[0].location.y, -10.0000);
4124
4125        assert_eq!(layout.children[0].children[0].size.width, 70.0000);
4126        assert_eq!(layout.children[0].children[0].size.height, 70.0000);
4127        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
4128        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
4129    }
4130
4131    #[test]
4132    fn width_smaller_then_content_with_flex_grow_very_large_size() {
4133        let layout = stretch::compute(
4134            &stretch::style::Node {
4135                size: stretch::geometry::Size {
4136                    width: stretch::style::Dimension::Points(200.0000),
4137                    ..Default::default()
4138                },
4139                children: vec![
4140                    stretch::style::Node {
4141                        flex_direction: stretch::style::FlexDirection::Column,
4142                        flex_grow: 1.0000,
4143                        size: stretch::geometry::Size {
4144                            width: stretch::style::Dimension::Points(0.0000),
4145                            ..Default::default()
4146                        },
4147                        children: vec![stretch::style::Node {
4148                            size: stretch::geometry::Size {
4149                                width: stretch::style::Dimension::Points(70.0000),
4150                                height: stretch::style::Dimension::Points(100.0000),
4151                                ..Default::default()
4152                            },
4153                            ..Default::default()
4154                        }],
4155                        ..Default::default()
4156                    },
4157                    stretch::style::Node {
4158                        flex_direction: stretch::style::FlexDirection::Column,
4159                        flex_grow: 1.0000,
4160                        size: stretch::geometry::Size {
4161                            width: stretch::style::Dimension::Points(0.0000),
4162                            ..Default::default()
4163                        },
4164                        children: vec![stretch::style::Node {
4165                            size: stretch::geometry::Size {
4166                                width: stretch::style::Dimension::Points(20.0000),
4167                                height: stretch::style::Dimension::Points(100.0000),
4168                                ..Default::default()
4169                            },
4170                            ..Default::default()
4171                        }],
4172                        ..Default::default()
4173                    },
4174                ],
4175                ..Default::default()
4176            },
4177            stretch::geometry::Size::undefined(),
4178        )
4179        .unwrap();
4180
4181        assert_eq!(layout.size.width, 200.0000);
4182        assert_eq!(layout.size.height, 100.0000);
4183        assert_eq!(layout.location.x, 0.0000);
4184        assert_eq!(layout.location.y, 0.0000);
4185
4186        assert_eq!(layout.children[0].size.width, 100.0000);
4187        assert_eq!(layout.children[0].size.height, 100.0000);
4188        assert_eq!(layout.children[0].location.x, 0.0000);
4189        assert_eq!(layout.children[0].location.y, 0.0000);
4190
4191        assert_eq!(layout.children[0].children[0].size.width, 70.0000);
4192        assert_eq!(layout.children[0].children[0].size.height, 100.0000);
4193        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
4194        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
4195
4196        assert_eq!(layout.children[1].size.width, 100.0000);
4197        assert_eq!(layout.children[1].size.height, 100.0000);
4198        assert_eq!(layout.children[1].location.x, 100.0000);
4199        assert_eq!(layout.children[1].location.y, 0.0000);
4200
4201        assert_eq!(layout.children[1].children[0].size.width, 20.0000);
4202        assert_eq!(layout.children[1].children[0].size.height, 100.0000);
4203        assert_eq!(layout.children[1].children[0].location.x, 0.0000);
4204        assert_eq!(layout.children[1].children[0].location.y, 0.0000);
4205    }
4206
4207    #[test]
4208    fn size_defined_by_child_with_padding() {
4209        let layout = stretch::compute(
4210            &stretch::style::Node {
4211                padding: stretch::geometry::Rect {
4212                    start: stretch::style::Dimension::Points(10.0000),
4213                    end: stretch::style::Dimension::Points(10.0000),
4214                    top: stretch::style::Dimension::Points(10.0000),
4215                    bottom: stretch::style::Dimension::Points(10.0000),
4216                    ..Default::default()
4217                },
4218                children: vec![stretch::style::Node {
4219                    size: stretch::geometry::Size {
4220                        width: stretch::style::Dimension::Points(10.0000),
4221                        height: stretch::style::Dimension::Points(10.0000),
4222                        ..Default::default()
4223                    },
4224                    ..Default::default()
4225                }],
4226                ..Default::default()
4227            },
4228            stretch::geometry::Size::undefined(),
4229        )
4230        .unwrap();
4231
4232        assert_eq!(layout.size.width, 30.0000);
4233        assert_eq!(layout.size.height, 30.0000);
4234        assert_eq!(layout.location.x, 0.0000);
4235        assert_eq!(layout.location.y, 0.0000);
4236
4237        assert_eq!(layout.children[0].size.width, 10.0000);
4238        assert_eq!(layout.children[0].size.height, 10.0000);
4239        assert_eq!(layout.children[0].location.x, 10.0000);
4240        assert_eq!(layout.children[0].location.y, 10.0000);
4241    }
4242
4243    #[test]
4244    fn absolute_layout_within_border() {
4245        let layout = stretch::compute(
4246            &stretch::style::Node {
4247                size: stretch::geometry::Size {
4248                    width: stretch::style::Dimension::Points(100.0000),
4249                    height: stretch::style::Dimension::Points(100.0000),
4250                    ..Default::default()
4251                },
4252                padding: stretch::geometry::Rect {
4253                    start: stretch::style::Dimension::Points(10.0000),
4254                    end: stretch::style::Dimension::Points(10.0000),
4255                    top: stretch::style::Dimension::Points(10.0000),
4256                    bottom: stretch::style::Dimension::Points(10.0000),
4257                    ..Default::default()
4258                },
4259                border: stretch::geometry::Rect {
4260                    start: stretch::style::Dimension::Points(10.0000),
4261                    end: stretch::style::Dimension::Points(10.0000),
4262                    top: stretch::style::Dimension::Points(10.0000),
4263                    bottom: stretch::style::Dimension::Points(10.0000),
4264                    ..Default::default()
4265                },
4266                children: vec![
4267                    stretch::style::Node {
4268                        position_type: stretch::style::PositionType::Absolute,
4269                        size: stretch::geometry::Size {
4270                            width: stretch::style::Dimension::Points(50.0000),
4271                            height: stretch::style::Dimension::Points(50.0000),
4272                            ..Default::default()
4273                        },
4274                        position: stretch::geometry::Rect {
4275                            start: stretch::style::Dimension::Points(0.0000),
4276                            top: stretch::style::Dimension::Points(0.0000),
4277                            ..Default::default()
4278                        },
4279                        ..Default::default()
4280                    },
4281                    stretch::style::Node {
4282                        position_type: stretch::style::PositionType::Absolute,
4283                        size: stretch::geometry::Size {
4284                            width: stretch::style::Dimension::Points(50.0000),
4285                            height: stretch::style::Dimension::Points(50.0000),
4286                            ..Default::default()
4287                        },
4288                        position: stretch::geometry::Rect {
4289                            end: stretch::style::Dimension::Points(0.0000),
4290                            bottom: stretch::style::Dimension::Points(0.0000),
4291                            ..Default::default()
4292                        },
4293                        ..Default::default()
4294                    },
4295                    stretch::style::Node {
4296                        position_type: stretch::style::PositionType::Absolute,
4297                        size: stretch::geometry::Size {
4298                            width: stretch::style::Dimension::Points(50.0000),
4299                            height: stretch::style::Dimension::Points(50.0000),
4300                            ..Default::default()
4301                        },
4302                        margin: stretch::geometry::Rect {
4303                            start: stretch::style::Dimension::Points(10.0000),
4304                            end: stretch::style::Dimension::Points(10.0000),
4305                            top: stretch::style::Dimension::Points(10.0000),
4306                            bottom: stretch::style::Dimension::Points(10.0000),
4307                            ..Default::default()
4308                        },
4309                        position: stretch::geometry::Rect {
4310                            start: stretch::style::Dimension::Points(0.0000),
4311                            top: stretch::style::Dimension::Points(0.0000),
4312                            ..Default::default()
4313                        },
4314                        ..Default::default()
4315                    },
4316                    stretch::style::Node {
4317                        position_type: stretch::style::PositionType::Absolute,
4318                        size: stretch::geometry::Size {
4319                            width: stretch::style::Dimension::Points(50.0000),
4320                            height: stretch::style::Dimension::Points(50.0000),
4321                            ..Default::default()
4322                        },
4323                        margin: stretch::geometry::Rect {
4324                            start: stretch::style::Dimension::Points(10.0000),
4325                            end: stretch::style::Dimension::Points(10.0000),
4326                            top: stretch::style::Dimension::Points(10.0000),
4327                            bottom: stretch::style::Dimension::Points(10.0000),
4328                            ..Default::default()
4329                        },
4330                        position: stretch::geometry::Rect {
4331                            end: stretch::style::Dimension::Points(0.0000),
4332                            bottom: stretch::style::Dimension::Points(0.0000),
4333                            ..Default::default()
4334                        },
4335                        ..Default::default()
4336                    },
4337                ],
4338                ..Default::default()
4339            },
4340            stretch::geometry::Size::undefined(),
4341        )
4342        .unwrap();
4343
4344        assert_eq!(layout.size.width, 100.0000);
4345        assert_eq!(layout.size.height, 100.0000);
4346        assert_eq!(layout.location.x, 0.0000);
4347        assert_eq!(layout.location.y, 0.0000);
4348
4349        assert_eq!(layout.children[0].size.width, 50.0000);
4350        assert_eq!(layout.children[0].size.height, 50.0000);
4351        assert_eq!(layout.children[0].location.x, 10.0000);
4352        assert_eq!(layout.children[0].location.y, 10.0000);
4353
4354        assert_eq!(layout.children[1].size.width, 50.0000);
4355        assert_eq!(layout.children[1].size.height, 50.0000);
4356        assert_eq!(layout.children[1].location.x, 40.0000);
4357        assert_eq!(layout.children[1].location.y, 40.0000);
4358
4359        assert_eq!(layout.children[2].size.width, 50.0000);
4360        assert_eq!(layout.children[2].size.height, 50.0000);
4361        assert_eq!(layout.children[2].location.x, 20.0000);
4362        assert_eq!(layout.children[2].location.y, 20.0000);
4363
4364        assert_eq!(layout.children[3].size.width, 50.0000);
4365        assert_eq!(layout.children[3].size.height, 50.0000);
4366        assert_eq!(layout.children[3].location.x, 30.0000);
4367        assert_eq!(layout.children[3].location.y, 30.0000);
4368    }
4369
4370    #[test]
4371    fn margin_auto_left_fix_right_child_bigger_than_parent() {
4372        let layout = stretch::compute(
4373            &stretch::style::Node {
4374                justify_content: stretch::style::JustifyContent::Center,
4375                size: stretch::geometry::Size {
4376                    width: stretch::style::Dimension::Points(52.0000),
4377                    height: stretch::style::Dimension::Points(52.0000),
4378                    ..Default::default()
4379                },
4380                children: vec![stretch::style::Node {
4381                    size: stretch::geometry::Size {
4382                        width: stretch::style::Dimension::Points(72.0000),
4383                        height: stretch::style::Dimension::Points(72.0000),
4384                        ..Default::default()
4385                    },
4386                    margin: stretch::geometry::Rect {
4387                        start: stretch::style::Dimension::Auto,
4388                        end: stretch::style::Dimension::Points(10.0000),
4389                        ..Default::default()
4390                    },
4391                    ..Default::default()
4392                }],
4393                ..Default::default()
4394            },
4395            stretch::geometry::Size::undefined(),
4396        )
4397        .unwrap();
4398
4399        assert_eq!(layout.size.width, 52.0000);
4400        assert_eq!(layout.size.height, 52.0000);
4401        assert_eq!(layout.location.x, 0.0000);
4402        assert_eq!(layout.location.y, 0.0000);
4403
4404        assert_eq!(layout.children[0].size.width, 42.0000);
4405        assert_eq!(layout.children[0].size.height, 72.0000);
4406        assert_eq!(layout.children[0].location.x, 0.0000);
4407        assert_eq!(layout.children[0].location.y, 0.0000);
4408    }
4409
4410    #[test]
4411    fn justify_content_row_flex_end() {
4412        let layout = stretch::compute(
4413            &stretch::style::Node {
4414                justify_content: stretch::style::JustifyContent::FlexEnd,
4415                size: stretch::geometry::Size {
4416                    width: stretch::style::Dimension::Points(100.0000),
4417                    height: stretch::style::Dimension::Points(100.0000),
4418                    ..Default::default()
4419                },
4420                children: vec![
4421                    stretch::style::Node {
4422                        size: stretch::geometry::Size {
4423                            width: stretch::style::Dimension::Points(10.0000),
4424                            ..Default::default()
4425                        },
4426                        ..Default::default()
4427                    },
4428                    stretch::style::Node {
4429                        size: stretch::geometry::Size {
4430                            width: stretch::style::Dimension::Points(10.0000),
4431                            ..Default::default()
4432                        },
4433                        ..Default::default()
4434                    },
4435                    stretch::style::Node {
4436                        size: stretch::geometry::Size {
4437                            width: stretch::style::Dimension::Points(10.0000),
4438                            ..Default::default()
4439                        },
4440                        ..Default::default()
4441                    },
4442                ],
4443                ..Default::default()
4444            },
4445            stretch::geometry::Size::undefined(),
4446        )
4447        .unwrap();
4448
4449        assert_eq!(layout.size.width, 100.0000);
4450        assert_eq!(layout.size.height, 100.0000);
4451        assert_eq!(layout.location.x, 0.0000);
4452        assert_eq!(layout.location.y, 0.0000);
4453
4454        assert_eq!(layout.children[0].size.width, 10.0000);
4455        assert_eq!(layout.children[0].size.height, 100.0000);
4456        assert_eq!(layout.children[0].location.x, 70.0000);
4457        assert_eq!(layout.children[0].location.y, 0.0000);
4458
4459        assert_eq!(layout.children[1].size.width, 10.0000);
4460        assert_eq!(layout.children[1].size.height, 100.0000);
4461        assert_eq!(layout.children[1].location.x, 80.0000);
4462        assert_eq!(layout.children[1].location.y, 0.0000);
4463
4464        assert_eq!(layout.children[2].size.width, 10.0000);
4465        assert_eq!(layout.children[2].size.height, 100.0000);
4466        assert_eq!(layout.children[2].location.x, 90.0000);
4467        assert_eq!(layout.children[2].location.y, 0.0000);
4468    }
4469
4470    #[test]
4471    fn margin_bottom() {
4472        let layout = stretch::compute(
4473            &stretch::style::Node {
4474                flex_direction: stretch::style::FlexDirection::Column,
4475                justify_content: stretch::style::JustifyContent::FlexEnd,
4476                size: stretch::geometry::Size {
4477                    width: stretch::style::Dimension::Points(100.0000),
4478                    height: stretch::style::Dimension::Points(100.0000),
4479                    ..Default::default()
4480                },
4481                children: vec![stretch::style::Node {
4482                    size: stretch::geometry::Size {
4483                        height: stretch::style::Dimension::Points(10.0000),
4484                        ..Default::default()
4485                    },
4486                    margin: stretch::geometry::Rect {
4487                        bottom: stretch::style::Dimension::Points(10.0000),
4488                        ..Default::default()
4489                    },
4490                    ..Default::default()
4491                }],
4492                ..Default::default()
4493            },
4494            stretch::geometry::Size::undefined(),
4495        )
4496        .unwrap();
4497
4498        assert_eq!(layout.size.width, 100.0000);
4499        assert_eq!(layout.size.height, 100.0000);
4500        assert_eq!(layout.location.x, 0.0000);
4501        assert_eq!(layout.location.y, 0.0000);
4502
4503        assert_eq!(layout.children[0].size.width, 100.0000);
4504        assert_eq!(layout.children[0].size.height, 10.0000);
4505        assert_eq!(layout.children[0].location.x, 0.0000);
4506        assert_eq!(layout.children[0].location.y, 80.0000);
4507    }
4508
4509    #[test]
4510    fn margin_should_not_be_part_of_max_height() {
4511        let layout = stretch::compute(
4512            &stretch::style::Node {
4513                size: stretch::geometry::Size {
4514                    width: stretch::style::Dimension::Points(250.0000),
4515                    height: stretch::style::Dimension::Points(250.0000),
4516                    ..Default::default()
4517                },
4518                children: vec![stretch::style::Node {
4519                    size: stretch::geometry::Size {
4520                        width: stretch::style::Dimension::Points(100.0000),
4521                        height: stretch::style::Dimension::Points(100.0000),
4522                        ..Default::default()
4523                    },
4524                    max_size: stretch::geometry::Size {
4525                        height: stretch::style::Dimension::Points(100.0000),
4526                        ..Default::default()
4527                    },
4528                    margin: stretch::geometry::Rect {
4529                        top: stretch::style::Dimension::Points(20.0000),
4530                        ..Default::default()
4531                    },
4532                    ..Default::default()
4533                }],
4534                ..Default::default()
4535            },
4536            stretch::geometry::Size::undefined(),
4537        )
4538        .unwrap();
4539
4540        assert_eq!(layout.size.width, 250.0000);
4541        assert_eq!(layout.size.height, 250.0000);
4542        assert_eq!(layout.location.x, 0.0000);
4543        assert_eq!(layout.location.y, 0.0000);
4544
4545        assert_eq!(layout.children[0].size.width, 100.0000);
4546        assert_eq!(layout.children[0].size.height, 100.0000);
4547        assert_eq!(layout.children[0].location.x, 0.0000);
4548        assert_eq!(layout.children[0].location.y, 20.0000);
4549    }
4550
4551    #[test]
4552    fn flex_basis_smaller_than_main_dimen_row() {
4553        let layout = stretch::compute(
4554            &stretch::style::Node {
4555                size: stretch::geometry::Size {
4556                    width: stretch::style::Dimension::Points(100.0000),
4557                    ..Default::default()
4558                },
4559                children: vec![stretch::style::Node {
4560                    flex_basis: stretch::style::Dimension::Points(10.0000),
4561                    size: stretch::geometry::Size {
4562                        width: stretch::style::Dimension::Points(50.0000),
4563                        height: stretch::style::Dimension::Points(50.0000),
4564                        ..Default::default()
4565                    },
4566                    ..Default::default()
4567                }],
4568                ..Default::default()
4569            },
4570            stretch::geometry::Size::undefined(),
4571        )
4572        .unwrap();
4573
4574        assert_eq!(layout.size.width, 100.0000);
4575        assert_eq!(layout.size.height, 50.0000);
4576        assert_eq!(layout.location.x, 0.0000);
4577        assert_eq!(layout.location.y, 0.0000);
4578
4579        assert_eq!(layout.children[0].size.width, 10.0000);
4580        assert_eq!(layout.children[0].size.height, 50.0000);
4581        assert_eq!(layout.children[0].location.x, 0.0000);
4582        assert_eq!(layout.children[0].location.y, 0.0000);
4583    }
4584
4585    #[test]
4586    fn percentage_flex_basis_cross_min_height() {
4587        let layout = stretch::compute(
4588            &stretch::style::Node {
4589                flex_direction: stretch::style::FlexDirection::Column,
4590                size: stretch::geometry::Size {
4591                    width: stretch::style::Dimension::Points(200.0000),
4592                    height: stretch::style::Dimension::Points(400.0000),
4593                    ..Default::default()
4594                },
4595                children: vec![
4596                    stretch::style::Node {
4597                        flex_grow: 1.0000,
4598                        min_size: stretch::geometry::Size {
4599                            height: stretch::style::Dimension::Percent(0.6000),
4600                            ..Default::default()
4601                        },
4602                        ..Default::default()
4603                    },
4604                    stretch::style::Node {
4605                        flex_grow: 2.0000,
4606                        min_size: stretch::geometry::Size {
4607                            height: stretch::style::Dimension::Percent(0.1000),
4608                            ..Default::default()
4609                        },
4610                        ..Default::default()
4611                    },
4612                ],
4613                ..Default::default()
4614            },
4615            stretch::geometry::Size::undefined(),
4616        )
4617        .unwrap();
4618
4619        assert_eq!(layout.size.width, 200.0000);
4620        assert_eq!(layout.size.height, 400.0000);
4621        assert_eq!(layout.location.x, 0.0000);
4622        assert_eq!(layout.location.y, 0.0000);
4623
4624        assert_eq!(layout.children[0].size.width, 200.0000);
4625        assert_eq!(layout.children[0].size.height, 280.0000);
4626        assert_eq!(layout.children[0].location.x, 0.0000);
4627        assert_eq!(layout.children[0].location.y, 0.0000);
4628
4629        assert_eq!(layout.children[1].size.width, 200.0000);
4630        assert_eq!(layout.children[1].size.height, 120.0000);
4631        assert_eq!(layout.children[1].location.x, 0.0000);
4632        assert_eq!(layout.children[1].location.y, 280.0000);
4633    }
4634
4635    #[test]
4636    fn nested_overflowing_child_in_constraint_parent() {
4637        let layout = stretch::compute(
4638            &stretch::style::Node {
4639                size: stretch::geometry::Size {
4640                    width: stretch::style::Dimension::Points(100.0000),
4641                    height: stretch::style::Dimension::Points(100.0000),
4642                    ..Default::default()
4643                },
4644                children: vec![stretch::style::Node {
4645                    size: stretch::geometry::Size {
4646                        width: stretch::style::Dimension::Points(100.0000),
4647                        height: stretch::style::Dimension::Points(100.0000),
4648                        ..Default::default()
4649                    },
4650                    children: vec![stretch::style::Node {
4651                        size: stretch::geometry::Size {
4652                            width: stretch::style::Dimension::Points(200.0000),
4653                            height: stretch::style::Dimension::Points(200.0000),
4654                            ..Default::default()
4655                        },
4656                        ..Default::default()
4657                    }],
4658                    ..Default::default()
4659                }],
4660                ..Default::default()
4661            },
4662            stretch::geometry::Size::undefined(),
4663        )
4664        .unwrap();
4665
4666        assert_eq!(layout.size.width, 100.0000);
4667        assert_eq!(layout.size.height, 100.0000);
4668        assert_eq!(layout.location.x, 0.0000);
4669        assert_eq!(layout.location.y, 0.0000);
4670
4671        assert_eq!(layout.children[0].size.width, 100.0000);
4672        assert_eq!(layout.children[0].size.height, 100.0000);
4673        assert_eq!(layout.children[0].location.x, 0.0000);
4674        assert_eq!(layout.children[0].location.y, 0.0000);
4675
4676        assert_eq!(layout.children[0].children[0].size.width, 100.0000);
4677        assert_eq!(layout.children[0].children[0].size.height, 200.0000);
4678        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
4679        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
4680    }
4681
4682    #[test]
4683    fn wrapped_row_within_align_items_center() {
4684        let layout = stretch::compute(
4685            &stretch::style::Node {
4686                flex_direction: stretch::style::FlexDirection::Column,
4687                align_items: stretch::style::AlignItems::Center,
4688                size: stretch::geometry::Size {
4689                    width: stretch::style::Dimension::Points(200.0000),
4690                    height: stretch::style::Dimension::Points(200.0000),
4691                    ..Default::default()
4692                },
4693                children: vec![stretch::style::Node {
4694                    flex_wrap: stretch::style::FlexWrap::Wrap,
4695                    children: vec![
4696                        stretch::style::Node {
4697                            size: stretch::geometry::Size {
4698                                width: stretch::style::Dimension::Points(150.0000),
4699                                height: stretch::style::Dimension::Points(80.0000),
4700                                ..Default::default()
4701                            },
4702                            ..Default::default()
4703                        },
4704                        stretch::style::Node {
4705                            size: stretch::geometry::Size {
4706                                width: stretch::style::Dimension::Points(80.0000),
4707                                height: stretch::style::Dimension::Points(80.0000),
4708                                ..Default::default()
4709                            },
4710                            ..Default::default()
4711                        },
4712                    ],
4713                    ..Default::default()
4714                }],
4715                ..Default::default()
4716            },
4717            stretch::geometry::Size::undefined(),
4718        )
4719        .unwrap();
4720
4721        assert_eq!(layout.size.width, 200.0000);
4722        assert_eq!(layout.size.height, 200.0000);
4723        assert_eq!(layout.location.x, 0.0000);
4724        assert_eq!(layout.location.y, 0.0000);
4725
4726        assert_eq!(layout.children[0].size.width, 200.0000);
4727        assert_eq!(layout.children[0].size.height, 160.0000);
4728        assert_eq!(layout.children[0].location.x, 0.0000);
4729        assert_eq!(layout.children[0].location.y, 0.0000);
4730
4731        assert_eq!(layout.children[0].children[0].size.width, 150.0000);
4732        assert_eq!(layout.children[0].children[0].size.height, 80.0000);
4733        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
4734        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
4735
4736        assert_eq!(layout.children[0].children[1].size.width, 80.0000);
4737        assert_eq!(layout.children[0].children[1].size.height, 80.0000);
4738        assert_eq!(layout.children[0].children[1].location.x, 0.0000);
4739        assert_eq!(layout.children[0].children[1].location.y, 80.0000);
4740    }
4741
4742    #[test]
4743    fn justify_content_column_center() {
4744        let layout = stretch::compute(
4745            &stretch::style::Node {
4746                flex_direction: stretch::style::FlexDirection::Column,
4747                justify_content: stretch::style::JustifyContent::Center,
4748                size: stretch::geometry::Size {
4749                    width: stretch::style::Dimension::Points(100.0000),
4750                    height: stretch::style::Dimension::Points(100.0000),
4751                    ..Default::default()
4752                },
4753                children: vec![
4754                    stretch::style::Node {
4755                        size: stretch::geometry::Size {
4756                            height: stretch::style::Dimension::Points(10.0000),
4757                            ..Default::default()
4758                        },
4759                        ..Default::default()
4760                    },
4761                    stretch::style::Node {
4762                        size: stretch::geometry::Size {
4763                            height: stretch::style::Dimension::Points(10.0000),
4764                            ..Default::default()
4765                        },
4766                        ..Default::default()
4767                    },
4768                    stretch::style::Node {
4769                        size: stretch::geometry::Size {
4770                            height: stretch::style::Dimension::Points(10.0000),
4771                            ..Default::default()
4772                        },
4773                        ..Default::default()
4774                    },
4775                ],
4776                ..Default::default()
4777            },
4778            stretch::geometry::Size::undefined(),
4779        )
4780        .unwrap();
4781
4782        assert_eq!(layout.size.width, 100.0000);
4783        assert_eq!(layout.size.height, 100.0000);
4784        assert_eq!(layout.location.x, 0.0000);
4785        assert_eq!(layout.location.y, 0.0000);
4786
4787        assert_eq!(layout.children[0].size.width, 100.0000);
4788        assert_eq!(layout.children[0].size.height, 10.0000);
4789        assert_eq!(layout.children[0].location.x, 0.0000);
4790        assert_eq!(layout.children[0].location.y, 35.0000);
4791
4792        assert_eq!(layout.children[1].size.width, 100.0000);
4793        assert_eq!(layout.children[1].size.height, 10.0000);
4794        assert_eq!(layout.children[1].location.x, 0.0000);
4795        assert_eq!(layout.children[1].location.y, 45.0000);
4796
4797        assert_eq!(layout.children[2].size.width, 100.0000);
4798        assert_eq!(layout.children[2].size.height, 10.0000);
4799        assert_eq!(layout.children[2].location.x, 0.0000);
4800        assert_eq!(layout.children[2].location.y, 55.0000);
4801    }
4802
4803    #[test]
4804    fn align_items_center_child_with_margin_bigger_than_parent() {
4805        let layout = stretch::compute(
4806            &stretch::style::Node {
4807                align_items: stretch::style::AlignItems::Center,
4808                justify_content: stretch::style::JustifyContent::Center,
4809                size: stretch::geometry::Size {
4810                    width: stretch::style::Dimension::Points(50.0000),
4811                    height: stretch::style::Dimension::Points(50.0000),
4812                    ..Default::default()
4813                },
4814                children: vec![stretch::style::Node {
4815                    align_items: stretch::style::AlignItems::Center,
4816                    children: vec![stretch::style::Node {
4817                        size: stretch::geometry::Size {
4818                            width: stretch::style::Dimension::Points(50.0000),
4819                            height: stretch::style::Dimension::Points(50.0000),
4820                            ..Default::default()
4821                        },
4822                        margin: stretch::geometry::Rect {
4823                            start: stretch::style::Dimension::Points(10.0000),
4824                            end: stretch::style::Dimension::Points(10.0000),
4825                            ..Default::default()
4826                        },
4827                        ..Default::default()
4828                    }],
4829                    ..Default::default()
4830                }],
4831                ..Default::default()
4832            },
4833            stretch::geometry::Size::undefined(),
4834        )
4835        .unwrap();
4836
4837        assert_eq!(layout.size.width, 50.0000);
4838        assert_eq!(layout.size.height, 50.0000);
4839        assert_eq!(layout.location.x, 0.0000);
4840        assert_eq!(layout.location.y, 0.0000);
4841
4842        assert_eq!(layout.children[0].size.width, 70.0000);
4843        assert_eq!(layout.children[0].size.height, 50.0000);
4844        assert_eq!(layout.children[0].location.x, -10.0000);
4845        assert_eq!(layout.children[0].location.y, 0.0000);
4846
4847        assert_eq!(layout.children[0].children[0].size.width, 50.0000);
4848        assert_eq!(layout.children[0].children[0].size.height, 50.0000);
4849        assert_eq!(layout.children[0].children[0].location.x, 10.0000);
4850        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
4851    }
4852
4853    #[test]
4854    fn percentage_width_height() {
4855        let layout = stretch::compute(
4856            &stretch::style::Node {
4857                size: stretch::geometry::Size {
4858                    width: stretch::style::Dimension::Points(200.0000),
4859                    height: stretch::style::Dimension::Points(400.0000),
4860                    ..Default::default()
4861                },
4862                children: vec![stretch::style::Node {
4863                    size: stretch::geometry::Size {
4864                        width: stretch::style::Dimension::Percent(0.3000),
4865                        height: stretch::style::Dimension::Percent(0.3000),
4866                        ..Default::default()
4867                    },
4868                    ..Default::default()
4869                }],
4870                ..Default::default()
4871            },
4872            stretch::geometry::Size::undefined(),
4873        )
4874        .unwrap();
4875
4876        assert_eq!(layout.size.width, 200.0000);
4877        assert_eq!(layout.size.height, 400.0000);
4878        assert_eq!(layout.location.x, 0.0000);
4879        assert_eq!(layout.location.y, 0.0000);
4880
4881        assert_eq!(layout.children[0].size.width, 60.0000);
4882        assert_eq!(layout.children[0].size.height, 120.0000);
4883        assert_eq!(layout.children[0].location.x, 0.0000);
4884        assert_eq!(layout.children[0].location.y, 0.0000);
4885    }
4886
4887    #[test]
4888    fn margin_auto_mutiple_children_column() {
4889        let layout = stretch::compute(
4890            &stretch::style::Node {
4891                flex_direction: stretch::style::FlexDirection::Column,
4892                align_items: stretch::style::AlignItems::Center,
4893                size: stretch::geometry::Size {
4894                    width: stretch::style::Dimension::Points(200.0000),
4895                    height: stretch::style::Dimension::Points(200.0000),
4896                    ..Default::default()
4897                },
4898                children: vec![
4899                    stretch::style::Node {
4900                        size: stretch::geometry::Size {
4901                            width: stretch::style::Dimension::Points(50.0000),
4902                            height: stretch::style::Dimension::Points(50.0000),
4903                            ..Default::default()
4904                        },
4905                        margin: stretch::geometry::Rect { top: stretch::style::Dimension::Auto, ..Default::default() },
4906                        ..Default::default()
4907                    },
4908                    stretch::style::Node {
4909                        size: stretch::geometry::Size {
4910                            width: stretch::style::Dimension::Points(50.0000),
4911                            height: stretch::style::Dimension::Points(50.0000),
4912                            ..Default::default()
4913                        },
4914                        margin: stretch::geometry::Rect { top: stretch::style::Dimension::Auto, ..Default::default() },
4915                        ..Default::default()
4916                    },
4917                    stretch::style::Node {
4918                        size: stretch::geometry::Size {
4919                            width: stretch::style::Dimension::Points(50.0000),
4920                            height: stretch::style::Dimension::Points(50.0000),
4921                            ..Default::default()
4922                        },
4923                        ..Default::default()
4924                    },
4925                ],
4926                ..Default::default()
4927            },
4928            stretch::geometry::Size::undefined(),
4929        )
4930        .unwrap();
4931
4932        assert_eq!(layout.size.width, 200.0000);
4933        assert_eq!(layout.size.height, 200.0000);
4934        assert_eq!(layout.location.x, 0.0000);
4935        assert_eq!(layout.location.y, 0.0000);
4936
4937        assert_eq!(layout.children[0].size.width, 50.0000);
4938        assert_eq!(layout.children[0].size.height, 50.0000);
4939        assert_eq!(layout.children[0].location.x, 75.0000);
4940        assert_eq!(layout.children[0].location.y, 25.0000);
4941
4942        assert_eq!(layout.children[1].size.width, 50.0000);
4943        assert_eq!(layout.children[1].size.height, 50.0000);
4944        assert_eq!(layout.children[1].location.x, 75.0000);
4945        assert_eq!(layout.children[1].location.y, 100.0000);
4946
4947        assert_eq!(layout.children[2].size.width, 50.0000);
4948        assert_eq!(layout.children[2].size.height, 50.0000);
4949        assert_eq!(layout.children[2].location.x, 75.0000);
4950        assert_eq!(layout.children[2].location.y, 150.0000);
4951    }
4952
4953    #[test]
4954    fn min_width_overrides_width_on_root() {
4955        let layout = stretch::compute(
4956            &stretch::style::Node {
4957                size: stretch::geometry::Size {
4958                    width: stretch::style::Dimension::Points(50.0000),
4959                    ..Default::default()
4960                },
4961                min_size: stretch::geometry::Size {
4962                    width: stretch::style::Dimension::Points(100.0000),
4963                    ..Default::default()
4964                },
4965                ..Default::default()
4966            },
4967            stretch::geometry::Size::undefined(),
4968        )
4969        .unwrap();
4970
4971        assert_eq!(layout.size.width, 100.0000);
4972        assert_eq!(layout.size.height, 0.0000);
4973        assert_eq!(layout.location.x, 0.0000);
4974        assert_eq!(layout.location.y, 0.0000);
4975    }
4976
4977    #[test]
4978    fn flex_wrap_wrap_to_child_height() {
4979        let layout = stretch::compute(
4980            &stretch::style::Node {
4981                flex_direction: stretch::style::FlexDirection::Column,
4982                children: vec![
4983                    stretch::style::Node {
4984                        flex_wrap: stretch::style::FlexWrap::Wrap,
4985                        align_items: stretch::style::AlignItems::FlexStart,
4986                        children: vec![stretch::style::Node {
4987                            flex_direction: stretch::style::FlexDirection::Column,
4988                            size: stretch::geometry::Size {
4989                                width: stretch::style::Dimension::Points(100.0000),
4990                                ..Default::default()
4991                            },
4992                            children: vec![stretch::style::Node {
4993                                size: stretch::geometry::Size {
4994                                    width: stretch::style::Dimension::Points(100.0000),
4995                                    height: stretch::style::Dimension::Points(100.0000),
4996                                    ..Default::default()
4997                                },
4998                                ..Default::default()
4999                            }],
5000                            ..Default::default()
5001                        }],
5002                        ..Default::default()
5003                    },
5004                    stretch::style::Node {
5005                        size: stretch::geometry::Size {
5006                            width: stretch::style::Dimension::Points(100.0000),
5007                            height: stretch::style::Dimension::Points(100.0000),
5008                            ..Default::default()
5009                        },
5010                        ..Default::default()
5011                    },
5012                ],
5013                ..Default::default()
5014            },
5015            stretch::geometry::Size::undefined(),
5016        )
5017        .unwrap();
5018
5019        assert_eq!(layout.size.width, 100.0000);
5020        assert_eq!(layout.size.height, 200.0000);
5021        assert_eq!(layout.location.x, 0.0000);
5022        assert_eq!(layout.location.y, 0.0000);
5023
5024        assert_eq!(layout.children[0].size.width, 100.0000);
5025        assert_eq!(layout.children[0].size.height, 100.0000);
5026        assert_eq!(layout.children[0].location.x, 0.0000);
5027        assert_eq!(layout.children[0].location.y, 0.0000);
5028
5029        assert_eq!(layout.children[0].children[0].size.width, 100.0000);
5030        assert_eq!(layout.children[0].children[0].size.height, 100.0000);
5031        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
5032        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
5033
5034        assert_eq!(layout.children[0].children[0].children[0].size.width, 100.0000);
5035        assert_eq!(layout.children[0].children[0].children[0].size.height, 100.0000);
5036        assert_eq!(layout.children[0].children[0].children[0].location.x, 0.0000);
5037        assert_eq!(layout.children[0].children[0].children[0].location.y, 0.0000);
5038
5039        assert_eq!(layout.children[1].size.width, 100.0000);
5040        assert_eq!(layout.children[1].size.height, 100.0000);
5041        assert_eq!(layout.children[1].location.x, 0.0000);
5042        assert_eq!(layout.children[1].location.y, 100.0000);
5043    }
5044
5045    #[test]
5046    fn wrap_nodes_with_content_sizing_margin_cross() {
5047        let layout = stretch::compute(
5048            &stretch::style::Node {
5049                flex_direction: stretch::style::FlexDirection::Column,
5050                size: stretch::geometry::Size {
5051                    width: stretch::style::Dimension::Points(500.0000),
5052                    height: stretch::style::Dimension::Points(500.0000),
5053                    ..Default::default()
5054                },
5055                children: vec![stretch::style::Node {
5056                    flex_wrap: stretch::style::FlexWrap::Wrap,
5057                    size: stretch::geometry::Size {
5058                        width: stretch::style::Dimension::Points(70.0000),
5059                        ..Default::default()
5060                    },
5061                    children: vec![
5062                        stretch::style::Node {
5063                            flex_direction: stretch::style::FlexDirection::Column,
5064                            children: vec![stretch::style::Node {
5065                                size: stretch::geometry::Size {
5066                                    width: stretch::style::Dimension::Points(40.0000),
5067                                    height: stretch::style::Dimension::Points(40.0000),
5068                                    ..Default::default()
5069                                },
5070                                ..Default::default()
5071                            }],
5072                            ..Default::default()
5073                        },
5074                        stretch::style::Node {
5075                            flex_direction: stretch::style::FlexDirection::Column,
5076                            margin: stretch::geometry::Rect {
5077                                top: stretch::style::Dimension::Points(10.0000),
5078                                ..Default::default()
5079                            },
5080                            children: vec![stretch::style::Node {
5081                                size: stretch::geometry::Size {
5082                                    width: stretch::style::Dimension::Points(40.0000),
5083                                    height: stretch::style::Dimension::Points(40.0000),
5084                                    ..Default::default()
5085                                },
5086                                ..Default::default()
5087                            }],
5088                            ..Default::default()
5089                        },
5090                    ],
5091                    ..Default::default()
5092                }],
5093                ..Default::default()
5094            },
5095            stretch::geometry::Size::undefined(),
5096        )
5097        .unwrap();
5098
5099        assert_eq!(layout.size.width, 500.0000);
5100        assert_eq!(layout.size.height, 500.0000);
5101        assert_eq!(layout.location.x, 0.0000);
5102        assert_eq!(layout.location.y, 0.0000);
5103
5104        assert_eq!(layout.children[0].size.width, 70.0000);
5105        assert_eq!(layout.children[0].size.height, 90.0000);
5106        assert_eq!(layout.children[0].location.x, 0.0000);
5107        assert_eq!(layout.children[0].location.y, 0.0000);
5108
5109        assert_eq!(layout.children[0].children[0].size.width, 40.0000);
5110        assert_eq!(layout.children[0].children[0].size.height, 40.0000);
5111        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
5112        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
5113
5114        assert_eq!(layout.children[0].children[0].children[0].size.width, 40.0000);
5115        assert_eq!(layout.children[0].children[0].children[0].size.height, 40.0000);
5116        assert_eq!(layout.children[0].children[0].children[0].location.x, 0.0000);
5117        assert_eq!(layout.children[0].children[0].children[0].location.y, 0.0000);
5118
5119        assert_eq!(layout.children[0].children[1].size.width, 40.0000);
5120        assert_eq!(layout.children[0].children[1].size.height, 40.0000);
5121        assert_eq!(layout.children[0].children[1].location.x, 0.0000);
5122        assert_eq!(layout.children[0].children[1].location.y, 50.0000);
5123
5124        assert_eq!(layout.children[0].children[1].children[0].size.width, 40.0000);
5125        assert_eq!(layout.children[0].children[1].children[0].size.height, 40.0000);
5126        assert_eq!(layout.children[0].children[1].children[0].location.x, 0.0000);
5127        assert_eq!(layout.children[0].children[1].children[0].location.y, 0.0000);
5128    }
5129
5130    #[test]
5131    fn align_baseline() {
5132        let layout = stretch::compute(
5133            &stretch::style::Node {
5134                align_items: stretch::style::AlignItems::Baseline,
5135                size: stretch::geometry::Size {
5136                    width: stretch::style::Dimension::Points(100.0000),
5137                    height: stretch::style::Dimension::Points(100.0000),
5138                    ..Default::default()
5139                },
5140                children: vec![
5141                    stretch::style::Node {
5142                        size: stretch::geometry::Size {
5143                            width: stretch::style::Dimension::Points(50.0000),
5144                            height: stretch::style::Dimension::Points(50.0000),
5145                            ..Default::default()
5146                        },
5147                        ..Default::default()
5148                    },
5149                    stretch::style::Node {
5150                        size: stretch::geometry::Size {
5151                            width: stretch::style::Dimension::Points(50.0000),
5152                            height: stretch::style::Dimension::Points(20.0000),
5153                            ..Default::default()
5154                        },
5155                        ..Default::default()
5156                    },
5157                ],
5158                ..Default::default()
5159            },
5160            stretch::geometry::Size::undefined(),
5161        )
5162        .unwrap();
5163
5164        assert_eq!(layout.size.width, 100.0000);
5165        assert_eq!(layout.size.height, 100.0000);
5166        assert_eq!(layout.location.x, 0.0000);
5167        assert_eq!(layout.location.y, 0.0000);
5168
5169        assert_eq!(layout.children[0].size.width, 50.0000);
5170        assert_eq!(layout.children[0].size.height, 50.0000);
5171        assert_eq!(layout.children[0].location.x, 0.0000);
5172        assert_eq!(layout.children[0].location.y, 0.0000);
5173
5174        assert_eq!(layout.children[1].size.width, 50.0000);
5175        assert_eq!(layout.children[1].size.height, 20.0000);
5176        assert_eq!(layout.children[1].location.x, 50.0000);
5177        assert_eq!(layout.children[1].location.y, 30.0000);
5178    }
5179
5180    #[test]
5181    fn margin_with_sibling_row() {
5182        let layout = stretch::compute(
5183            &stretch::style::Node {
5184                size: stretch::geometry::Size {
5185                    width: stretch::style::Dimension::Points(100.0000),
5186                    height: stretch::style::Dimension::Points(100.0000),
5187                    ..Default::default()
5188                },
5189                children: vec![
5190                    stretch::style::Node {
5191                        flex_grow: 1.0000,
5192                        margin: stretch::geometry::Rect {
5193                            end: stretch::style::Dimension::Points(10.0000),
5194                            ..Default::default()
5195                        },
5196                        ..Default::default()
5197                    },
5198                    stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
5199                ],
5200                ..Default::default()
5201            },
5202            stretch::geometry::Size::undefined(),
5203        )
5204        .unwrap();
5205
5206        assert_eq!(layout.size.width, 100.0000);
5207        assert_eq!(layout.size.height, 100.0000);
5208        assert_eq!(layout.location.x, 0.0000);
5209        assert_eq!(layout.location.y, 0.0000);
5210
5211        assert_eq!(layout.children[0].size.width, 45.0000);
5212        assert_eq!(layout.children[0].size.height, 100.0000);
5213        assert_eq!(layout.children[0].location.x, 0.0000);
5214        assert_eq!(layout.children[0].location.y, 0.0000);
5215
5216        assert_eq!(layout.children[1].size.width, 45.0000);
5217        assert_eq!(layout.children[1].size.height, 100.0000);
5218        assert_eq!(layout.children[1].location.x, 55.0000);
5219        assert_eq!(layout.children[1].location.y, 0.0000);
5220    }
5221
5222    #[test]
5223    fn wrap_reverse_row_align_content_space_around() {
5224        let layout = stretch::compute(
5225            &stretch::style::Node {
5226                flex_wrap: stretch::style::FlexWrap::WrapReverse,
5227                align_content: stretch::style::AlignContent::SpaceAround,
5228                size: stretch::geometry::Size {
5229                    width: stretch::style::Dimension::Points(100.0000),
5230                    ..Default::default()
5231                },
5232                children: vec![
5233                    stretch::style::Node {
5234                        size: stretch::geometry::Size {
5235                            width: stretch::style::Dimension::Points(30.0000),
5236                            height: stretch::style::Dimension::Points(10.0000),
5237                            ..Default::default()
5238                        },
5239                        ..Default::default()
5240                    },
5241                    stretch::style::Node {
5242                        size: stretch::geometry::Size {
5243                            width: stretch::style::Dimension::Points(30.0000),
5244                            height: stretch::style::Dimension::Points(20.0000),
5245                            ..Default::default()
5246                        },
5247                        ..Default::default()
5248                    },
5249                    stretch::style::Node {
5250                        size: stretch::geometry::Size {
5251                            width: stretch::style::Dimension::Points(30.0000),
5252                            height: stretch::style::Dimension::Points(30.0000),
5253                            ..Default::default()
5254                        },
5255                        ..Default::default()
5256                    },
5257                    stretch::style::Node {
5258                        size: stretch::geometry::Size {
5259                            width: stretch::style::Dimension::Points(30.0000),
5260                            height: stretch::style::Dimension::Points(40.0000),
5261                            ..Default::default()
5262                        },
5263                        ..Default::default()
5264                    },
5265                    stretch::style::Node {
5266                        size: stretch::geometry::Size {
5267                            width: stretch::style::Dimension::Points(30.0000),
5268                            height: stretch::style::Dimension::Points(50.0000),
5269                            ..Default::default()
5270                        },
5271                        ..Default::default()
5272                    },
5273                ],
5274                ..Default::default()
5275            },
5276            stretch::geometry::Size::undefined(),
5277        )
5278        .unwrap();
5279
5280        assert_eq!(layout.size.width, 100.0000);
5281        assert_eq!(layout.size.height, 80.0000);
5282        assert_eq!(layout.location.x, 0.0000);
5283        assert_eq!(layout.location.y, 0.0000);
5284
5285        assert_eq!(layout.children[0].size.width, 30.0000);
5286        assert_eq!(layout.children[0].size.height, 10.0000);
5287        assert_eq!(layout.children[0].location.x, 0.0000);
5288        assert_eq!(layout.children[0].location.y, 70.0000);
5289
5290        assert_eq!(layout.children[1].size.width, 30.0000);
5291        assert_eq!(layout.children[1].size.height, 20.0000);
5292        assert_eq!(layout.children[1].location.x, 30.0000);
5293        assert_eq!(layout.children[1].location.y, 60.0000);
5294
5295        assert_eq!(layout.children[2].size.width, 30.0000);
5296        assert_eq!(layout.children[2].size.height, 30.0000);
5297        assert_eq!(layout.children[2].location.x, 60.0000);
5298        assert_eq!(layout.children[2].location.y, 50.0000);
5299
5300        assert_eq!(layout.children[3].size.width, 30.0000);
5301        assert_eq!(layout.children[3].size.height, 40.0000);
5302        assert_eq!(layout.children[3].location.x, 0.0000);
5303        assert_eq!(layout.children[3].location.y, 10.0000);
5304
5305        assert_eq!(layout.children[4].size.width, 30.0000);
5306        assert_eq!(layout.children[4].size.height, 50.0000);
5307        assert_eq!(layout.children[4].location.x, 30.0000);
5308        assert_eq!(layout.children[4].location.y, 0.0000);
5309    }
5310
5311    #[test]
5312    fn wrap_reverse_column() {
5313        let layout = stretch::compute(
5314            &stretch::style::Node {
5315                flex_direction: stretch::style::FlexDirection::Column,
5316                flex_wrap: stretch::style::FlexWrap::WrapReverse,
5317                size: stretch::geometry::Size {
5318                    width: stretch::style::Dimension::Points(100.0000),
5319                    height: stretch::style::Dimension::Points(100.0000),
5320                    ..Default::default()
5321                },
5322                children: vec![
5323                    stretch::style::Node {
5324                        size: stretch::geometry::Size {
5325                            width: stretch::style::Dimension::Points(30.0000),
5326                            height: stretch::style::Dimension::Points(31.0000),
5327                            ..Default::default()
5328                        },
5329                        ..Default::default()
5330                    },
5331                    stretch::style::Node {
5332                        size: stretch::geometry::Size {
5333                            width: stretch::style::Dimension::Points(30.0000),
5334                            height: stretch::style::Dimension::Points(32.0000),
5335                            ..Default::default()
5336                        },
5337                        ..Default::default()
5338                    },
5339                    stretch::style::Node {
5340                        size: stretch::geometry::Size {
5341                            width: stretch::style::Dimension::Points(30.0000),
5342                            height: stretch::style::Dimension::Points(33.0000),
5343                            ..Default::default()
5344                        },
5345                        ..Default::default()
5346                    },
5347                    stretch::style::Node {
5348                        size: stretch::geometry::Size {
5349                            width: stretch::style::Dimension::Points(30.0000),
5350                            height: stretch::style::Dimension::Points(34.0000),
5351                            ..Default::default()
5352                        },
5353                        ..Default::default()
5354                    },
5355                ],
5356                ..Default::default()
5357            },
5358            stretch::geometry::Size::undefined(),
5359        )
5360        .unwrap();
5361
5362        assert_eq!(layout.size.width, 100.0000);
5363        assert_eq!(layout.size.height, 100.0000);
5364        assert_eq!(layout.location.x, 0.0000);
5365        assert_eq!(layout.location.y, 0.0000);
5366
5367        assert_eq!(layout.children[0].size.width, 30.0000);
5368        assert_eq!(layout.children[0].size.height, 31.0000);
5369        assert_eq!(layout.children[0].location.x, 70.0000);
5370        assert_eq!(layout.children[0].location.y, 0.0000);
5371
5372        assert_eq!(layout.children[1].size.width, 30.0000);
5373        assert_eq!(layout.children[1].size.height, 32.0000);
5374        assert_eq!(layout.children[1].location.x, 70.0000);
5375        assert_eq!(layout.children[1].location.y, 31.0000);
5376
5377        assert_eq!(layout.children[2].size.width, 30.0000);
5378        assert_eq!(layout.children[2].size.height, 33.0000);
5379        assert_eq!(layout.children[2].location.x, 70.0000);
5380        assert_eq!(layout.children[2].location.y, 63.0000);
5381
5382        assert_eq!(layout.children[3].size.width, 30.0000);
5383        assert_eq!(layout.children[3].size.height, 34.0000);
5384        assert_eq!(layout.children[3].location.x, 20.0000);
5385        assert_eq!(layout.children[3].location.y, 0.0000);
5386    }
5387
5388    #[test]
5389    fn align_items_center_with_child_margin() {
5390        let layout = stretch::compute(
5391            &stretch::style::Node {
5392                align_items: stretch::style::AlignItems::Center,
5393                size: stretch::geometry::Size {
5394                    width: stretch::style::Dimension::Points(100.0000),
5395                    height: stretch::style::Dimension::Points(100.0000),
5396                    ..Default::default()
5397                },
5398                children: vec![stretch::style::Node {
5399                    size: stretch::geometry::Size {
5400                        width: stretch::style::Dimension::Points(10.0000),
5401                        height: stretch::style::Dimension::Points(10.0000),
5402                        ..Default::default()
5403                    },
5404                    margin: stretch::geometry::Rect {
5405                        top: stretch::style::Dimension::Points(10.0000),
5406                        ..Default::default()
5407                    },
5408                    ..Default::default()
5409                }],
5410                ..Default::default()
5411            },
5412            stretch::geometry::Size::undefined(),
5413        )
5414        .unwrap();
5415
5416        assert_eq!(layout.size.width, 100.0000);
5417        assert_eq!(layout.size.height, 100.0000);
5418        assert_eq!(layout.location.x, 0.0000);
5419        assert_eq!(layout.location.y, 0.0000);
5420
5421        assert_eq!(layout.children[0].size.width, 10.0000);
5422        assert_eq!(layout.children[0].size.height, 10.0000);
5423        assert_eq!(layout.children[0].location.x, 0.0000);
5424        assert_eq!(layout.children[0].location.y, 50.0000);
5425    }
5426
5427    #[test]
5428    fn flex_direction_column_reverse() {
5429        let layout = stretch::compute(
5430            &stretch::style::Node {
5431                flex_direction: stretch::style::FlexDirection::ColumnReverse,
5432                size: stretch::geometry::Size {
5433                    width: stretch::style::Dimension::Points(100.0000),
5434                    height: stretch::style::Dimension::Points(100.0000),
5435                    ..Default::default()
5436                },
5437                children: vec![
5438                    stretch::style::Node {
5439                        size: stretch::geometry::Size {
5440                            height: stretch::style::Dimension::Points(10.0000),
5441                            ..Default::default()
5442                        },
5443                        ..Default::default()
5444                    },
5445                    stretch::style::Node {
5446                        size: stretch::geometry::Size {
5447                            height: stretch::style::Dimension::Points(10.0000),
5448                            ..Default::default()
5449                        },
5450                        ..Default::default()
5451                    },
5452                    stretch::style::Node {
5453                        size: stretch::geometry::Size {
5454                            height: stretch::style::Dimension::Points(10.0000),
5455                            ..Default::default()
5456                        },
5457                        ..Default::default()
5458                    },
5459                ],
5460                ..Default::default()
5461            },
5462            stretch::geometry::Size::undefined(),
5463        )
5464        .unwrap();
5465
5466        assert_eq!(layout.size.width, 100.0000);
5467        assert_eq!(layout.size.height, 100.0000);
5468        assert_eq!(layout.location.x, 0.0000);
5469        assert_eq!(layout.location.y, 0.0000);
5470
5471        assert_eq!(layout.children[0].size.width, 100.0000);
5472        assert_eq!(layout.children[0].size.height, 10.0000);
5473        assert_eq!(layout.children[0].location.x, 0.0000);
5474        assert_eq!(layout.children[0].location.y, 90.0000);
5475
5476        assert_eq!(layout.children[1].size.width, 100.0000);
5477        assert_eq!(layout.children[1].size.height, 10.0000);
5478        assert_eq!(layout.children[1].location.x, 0.0000);
5479        assert_eq!(layout.children[1].location.y, 80.0000);
5480
5481        assert_eq!(layout.children[2].size.width, 100.0000);
5482        assert_eq!(layout.children[2].size.height, 10.0000);
5483        assert_eq!(layout.children[2].location.x, 0.0000);
5484        assert_eq!(layout.children[2].location.y, 70.0000);
5485    }
5486
5487    #[test]
5488    fn flex_direction_column() {
5489        let layout = stretch::compute(
5490            &stretch::style::Node {
5491                flex_direction: stretch::style::FlexDirection::Column,
5492                size: stretch::geometry::Size {
5493                    width: stretch::style::Dimension::Points(100.0000),
5494                    height: stretch::style::Dimension::Points(100.0000),
5495                    ..Default::default()
5496                },
5497                children: vec![
5498                    stretch::style::Node {
5499                        size: stretch::geometry::Size {
5500                            height: stretch::style::Dimension::Points(10.0000),
5501                            ..Default::default()
5502                        },
5503                        ..Default::default()
5504                    },
5505                    stretch::style::Node {
5506                        size: stretch::geometry::Size {
5507                            height: stretch::style::Dimension::Points(10.0000),
5508                            ..Default::default()
5509                        },
5510                        ..Default::default()
5511                    },
5512                    stretch::style::Node {
5513                        size: stretch::geometry::Size {
5514                            height: stretch::style::Dimension::Points(10.0000),
5515                            ..Default::default()
5516                        },
5517                        ..Default::default()
5518                    },
5519                ],
5520                ..Default::default()
5521            },
5522            stretch::geometry::Size::undefined(),
5523        )
5524        .unwrap();
5525
5526        assert_eq!(layout.size.width, 100.0000);
5527        assert_eq!(layout.size.height, 100.0000);
5528        assert_eq!(layout.location.x, 0.0000);
5529        assert_eq!(layout.location.y, 0.0000);
5530
5531        assert_eq!(layout.children[0].size.width, 100.0000);
5532        assert_eq!(layout.children[0].size.height, 10.0000);
5533        assert_eq!(layout.children[0].location.x, 0.0000);
5534        assert_eq!(layout.children[0].location.y, 0.0000);
5535
5536        assert_eq!(layout.children[1].size.width, 100.0000);
5537        assert_eq!(layout.children[1].size.height, 10.0000);
5538        assert_eq!(layout.children[1].location.x, 0.0000);
5539        assert_eq!(layout.children[1].location.y, 10.0000);
5540
5541        assert_eq!(layout.children[2].size.width, 100.0000);
5542        assert_eq!(layout.children[2].size.height, 10.0000);
5543        assert_eq!(layout.children[2].location.x, 0.0000);
5544        assert_eq!(layout.children[2].location.y, 20.0000);
5545    }
5546
5547    #[test]
5548    fn align_items_center_child_without_margin_bigger_than_parent() {
5549        let layout = stretch::compute(
5550            &stretch::style::Node {
5551                align_items: stretch::style::AlignItems::Center,
5552                justify_content: stretch::style::JustifyContent::Center,
5553                size: stretch::geometry::Size {
5554                    width: stretch::style::Dimension::Points(50.0000),
5555                    height: stretch::style::Dimension::Points(50.0000),
5556                    ..Default::default()
5557                },
5558                children: vec![stretch::style::Node {
5559                    align_items: stretch::style::AlignItems::Center,
5560                    children: vec![stretch::style::Node {
5561                        size: stretch::geometry::Size {
5562                            width: stretch::style::Dimension::Points(70.0000),
5563                            height: stretch::style::Dimension::Points(70.0000),
5564                            ..Default::default()
5565                        },
5566                        ..Default::default()
5567                    }],
5568                    ..Default::default()
5569                }],
5570                ..Default::default()
5571            },
5572            stretch::geometry::Size::undefined(),
5573        )
5574        .unwrap();
5575
5576        assert_eq!(layout.size.width, 50.0000);
5577        assert_eq!(layout.size.height, 50.0000);
5578        assert_eq!(layout.location.x, 0.0000);
5579        assert_eq!(layout.location.y, 0.0000);
5580
5581        assert_eq!(layout.children[0].size.width, 70.0000);
5582        assert_eq!(layout.children[0].size.height, 70.0000);
5583        assert_eq!(layout.children[0].location.x, -10.0000);
5584        assert_eq!(layout.children[0].location.y, -10.0000);
5585
5586        assert_eq!(layout.children[0].children[0].size.width, 70.0000);
5587        assert_eq!(layout.children[0].children[0].size.height, 70.0000);
5588        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
5589        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
5590    }
5591
5592    #[test]
5593    fn align_self_flex_end_override_flex_start() {
5594        let layout = stretch::compute(
5595            &stretch::style::Node {
5596                align_items: stretch::style::AlignItems::FlexStart,
5597                size: stretch::geometry::Size {
5598                    width: stretch::style::Dimension::Points(100.0000),
5599                    height: stretch::style::Dimension::Points(100.0000),
5600                    ..Default::default()
5601                },
5602                children: vec![stretch::style::Node {
5603                    align_self: stretch::style::AlignSelf::FlexEnd,
5604                    size: stretch::geometry::Size {
5605                        width: stretch::style::Dimension::Points(10.0000),
5606                        height: stretch::style::Dimension::Points(10.0000),
5607                        ..Default::default()
5608                    },
5609                    ..Default::default()
5610                }],
5611                ..Default::default()
5612            },
5613            stretch::geometry::Size::undefined(),
5614        )
5615        .unwrap();
5616
5617        assert_eq!(layout.size.width, 100.0000);
5618        assert_eq!(layout.size.height, 100.0000);
5619        assert_eq!(layout.location.x, 0.0000);
5620        assert_eq!(layout.location.y, 0.0000);
5621
5622        assert_eq!(layout.children[0].size.width, 10.0000);
5623        assert_eq!(layout.children[0].size.height, 10.0000);
5624        assert_eq!(layout.children[0].location.x, 0.0000);
5625        assert_eq!(layout.children[0].location.y, 90.0000);
5626    }
5627
5628    #[test]
5629    fn rounding_total_fractial() {
5630        let layout = stretch::compute(
5631            &stretch::style::Node {
5632                flex_direction: stretch::style::FlexDirection::Column,
5633                size: stretch::geometry::Size {
5634                    width: stretch::style::Dimension::Points(87.4000),
5635                    height: stretch::style::Dimension::Points(113.4000),
5636                    ..Default::default()
5637                },
5638                children: vec![
5639                    stretch::style::Node {
5640                        flex_grow: 0.7000,
5641                        flex_basis: stretch::style::Dimension::Points(50.3000),
5642                        size: stretch::geometry::Size {
5643                            height: stretch::style::Dimension::Points(20.3000),
5644                            ..Default::default()
5645                        },
5646                        ..Default::default()
5647                    },
5648                    stretch::style::Node {
5649                        flex_grow: 1.6000,
5650                        size: stretch::geometry::Size {
5651                            height: stretch::style::Dimension::Points(10.0000),
5652                            ..Default::default()
5653                        },
5654                        ..Default::default()
5655                    },
5656                    stretch::style::Node {
5657                        flex_grow: 1.1000,
5658                        size: stretch::geometry::Size {
5659                            height: stretch::style::Dimension::Points(10.7000),
5660                            ..Default::default()
5661                        },
5662                        ..Default::default()
5663                    },
5664                ],
5665                ..Default::default()
5666            },
5667            stretch::geometry::Size::undefined(),
5668        )
5669        .unwrap();
5670
5671        assert_eq!(layout.size.width, 87.0000);
5672        assert_eq!(layout.size.height, 113.0000);
5673        assert_eq!(layout.location.x, 0.0000);
5674        assert_eq!(layout.location.y, 0.0000);
5675
5676        assert_eq!(layout.children[0].size.width, 87.0000);
5677        assert_eq!(layout.children[0].size.height, 59.0000);
5678        assert_eq!(layout.children[0].location.x, 0.0000);
5679        assert_eq!(layout.children[0].location.y, 0.0000);
5680
5681        assert_eq!(layout.children[1].size.width, 87.0000);
5682        assert_eq!(layout.children[1].size.height, 30.0000);
5683        assert_eq!(layout.children[1].location.x, 0.0000);
5684        assert_eq!(layout.children[1].location.y, 59.0000);
5685
5686        assert_eq!(layout.children[2].size.width, 87.0000);
5687        assert_eq!(layout.children[2].size.height, 24.0000);
5688        assert_eq!(layout.children[2].location.x, 0.0000);
5689        assert_eq!(layout.children[2].location.y, 89.0000);
5690    }
5691
5692    #[test]
5693    fn align_baseline_child_multiline() {
5694        let layout = stretch::compute(
5695            &stretch::style::Node {
5696                align_items: stretch::style::AlignItems::Baseline,
5697                size: stretch::geometry::Size {
5698                    width: stretch::style::Dimension::Points(100.0000),
5699                    ..Default::default()
5700                },
5701                children: vec![
5702                    stretch::style::Node {
5703                        size: stretch::geometry::Size {
5704                            width: stretch::style::Dimension::Points(50.0000),
5705                            height: stretch::style::Dimension::Points(60.0000),
5706                            ..Default::default()
5707                        },
5708                        ..Default::default()
5709                    },
5710                    stretch::style::Node {
5711                        flex_wrap: stretch::style::FlexWrap::Wrap,
5712                        size: stretch::geometry::Size {
5713                            width: stretch::style::Dimension::Points(50.0000),
5714                            ..Default::default()
5715                        },
5716                        children: vec![
5717                            stretch::style::Node {
5718                                size: stretch::geometry::Size {
5719                                    width: stretch::style::Dimension::Points(25.0000),
5720                                    height: stretch::style::Dimension::Points(20.0000),
5721                                    ..Default::default()
5722                                },
5723                                ..Default::default()
5724                            },
5725                            stretch::style::Node {
5726                                size: stretch::geometry::Size {
5727                                    width: stretch::style::Dimension::Points(25.0000),
5728                                    height: stretch::style::Dimension::Points(10.0000),
5729                                    ..Default::default()
5730                                },
5731                                ..Default::default()
5732                            },
5733                            stretch::style::Node {
5734                                size: stretch::geometry::Size {
5735                                    width: stretch::style::Dimension::Points(25.0000),
5736                                    height: stretch::style::Dimension::Points(20.0000),
5737                                    ..Default::default()
5738                                },
5739                                ..Default::default()
5740                            },
5741                            stretch::style::Node {
5742                                size: stretch::geometry::Size {
5743                                    width: stretch::style::Dimension::Points(25.0000),
5744                                    height: stretch::style::Dimension::Points(10.0000),
5745                                    ..Default::default()
5746                                },
5747                                ..Default::default()
5748                            },
5749                        ],
5750                        ..Default::default()
5751                    },
5752                ],
5753                ..Default::default()
5754            },
5755            stretch::geometry::Size::undefined(),
5756        )
5757        .unwrap();
5758
5759        assert_eq!(layout.size.width, 100.0000);
5760        assert_eq!(layout.size.height, 80.0000);
5761        assert_eq!(layout.location.x, 0.0000);
5762        assert_eq!(layout.location.y, 0.0000);
5763
5764        assert_eq!(layout.children[0].size.width, 50.0000);
5765        assert_eq!(layout.children[0].size.height, 60.0000);
5766        assert_eq!(layout.children[0].location.x, 0.0000);
5767        assert_eq!(layout.children[0].location.y, 0.0000);
5768
5769        assert_eq!(layout.children[1].size.width, 50.0000);
5770        assert_eq!(layout.children[1].size.height, 40.0000);
5771        assert_eq!(layout.children[1].location.x, 50.0000);
5772        assert_eq!(layout.children[1].location.y, 40.0000);
5773
5774        assert_eq!(layout.children[1].children[0].size.width, 25.0000);
5775        assert_eq!(layout.children[1].children[0].size.height, 20.0000);
5776        assert_eq!(layout.children[1].children[0].location.x, 0.0000);
5777        assert_eq!(layout.children[1].children[0].location.y, 0.0000);
5778
5779        assert_eq!(layout.children[1].children[1].size.width, 25.0000);
5780        assert_eq!(layout.children[1].children[1].size.height, 10.0000);
5781        assert_eq!(layout.children[1].children[1].location.x, 25.0000);
5782        assert_eq!(layout.children[1].children[1].location.y, 0.0000);
5783
5784        assert_eq!(layout.children[1].children[2].size.width, 25.0000);
5785        assert_eq!(layout.children[1].children[2].size.height, 20.0000);
5786        assert_eq!(layout.children[1].children[2].location.x, 0.0000);
5787        assert_eq!(layout.children[1].children[2].location.y, 20.0000);
5788
5789        assert_eq!(layout.children[1].children[3].size.width, 25.0000);
5790        assert_eq!(layout.children[1].children[3].size.height, 10.0000);
5791        assert_eq!(layout.children[1].children[3].location.x, 25.0000);
5792        assert_eq!(layout.children[1].children[3].location.y, 20.0000);
5793    }
5794
5795    #[test]
5796    fn absolute_layout_align_items_center_on_child_only() {
5797        let layout = stretch::compute(
5798            &stretch::style::Node {
5799                size: stretch::geometry::Size {
5800                    width: stretch::style::Dimension::Points(110.0000),
5801                    height: stretch::style::Dimension::Points(100.0000),
5802                    ..Default::default()
5803                },
5804                children: vec![stretch::style::Node {
5805                    position_type: stretch::style::PositionType::Absolute,
5806                    align_self: stretch::style::AlignSelf::Center,
5807                    size: stretch::geometry::Size {
5808                        width: stretch::style::Dimension::Points(60.0000),
5809                        height: stretch::style::Dimension::Points(40.0000),
5810                        ..Default::default()
5811                    },
5812                    ..Default::default()
5813                }],
5814                ..Default::default()
5815            },
5816            stretch::geometry::Size::undefined(),
5817        )
5818        .unwrap();
5819
5820        assert_eq!(layout.size.width, 110.0000);
5821        assert_eq!(layout.size.height, 100.0000);
5822        assert_eq!(layout.location.x, 0.0000);
5823        assert_eq!(layout.location.y, 0.0000);
5824
5825        assert_eq!(layout.children[0].size.width, 60.0000);
5826        assert_eq!(layout.children[0].size.height, 40.0000);
5827        assert_eq!(layout.children[0].location.x, 0.0000);
5828        assert_eq!(layout.children[0].location.y, 30.0000);
5829    }
5830
5831    #[test]
5832    fn wrap_reverse_row_single_line_different_size() {
5833        let layout = stretch::compute(
5834            &stretch::style::Node {
5835                flex_wrap: stretch::style::FlexWrap::WrapReverse,
5836                align_content: stretch::style::AlignContent::FlexStart,
5837                size: stretch::geometry::Size {
5838                    width: stretch::style::Dimension::Points(300.0000),
5839                    ..Default::default()
5840                },
5841                children: vec![
5842                    stretch::style::Node {
5843                        size: stretch::geometry::Size {
5844                            width: stretch::style::Dimension::Points(30.0000),
5845                            height: stretch::style::Dimension::Points(10.0000),
5846                            ..Default::default()
5847                        },
5848                        ..Default::default()
5849                    },
5850                    stretch::style::Node {
5851                        size: stretch::geometry::Size {
5852                            width: stretch::style::Dimension::Points(30.0000),
5853                            height: stretch::style::Dimension::Points(20.0000),
5854                            ..Default::default()
5855                        },
5856                        ..Default::default()
5857                    },
5858                    stretch::style::Node {
5859                        size: stretch::geometry::Size {
5860                            width: stretch::style::Dimension::Points(30.0000),
5861                            height: stretch::style::Dimension::Points(30.0000),
5862                            ..Default::default()
5863                        },
5864                        ..Default::default()
5865                    },
5866                    stretch::style::Node {
5867                        size: stretch::geometry::Size {
5868                            width: stretch::style::Dimension::Points(30.0000),
5869                            height: stretch::style::Dimension::Points(40.0000),
5870                            ..Default::default()
5871                        },
5872                        ..Default::default()
5873                    },
5874                    stretch::style::Node {
5875                        size: stretch::geometry::Size {
5876                            width: stretch::style::Dimension::Points(30.0000),
5877                            height: stretch::style::Dimension::Points(50.0000),
5878                            ..Default::default()
5879                        },
5880                        ..Default::default()
5881                    },
5882                ],
5883                ..Default::default()
5884            },
5885            stretch::geometry::Size::undefined(),
5886        )
5887        .unwrap();
5888
5889        assert_eq!(layout.size.width, 300.0000);
5890        assert_eq!(layout.size.height, 50.0000);
5891        assert_eq!(layout.location.x, 0.0000);
5892        assert_eq!(layout.location.y, 0.0000);
5893
5894        assert_eq!(layout.children[0].size.width, 30.0000);
5895        assert_eq!(layout.children[0].size.height, 10.0000);
5896        assert_eq!(layout.children[0].location.x, 0.0000);
5897        assert_eq!(layout.children[0].location.y, 40.0000);
5898
5899        assert_eq!(layout.children[1].size.width, 30.0000);
5900        assert_eq!(layout.children[1].size.height, 20.0000);
5901        assert_eq!(layout.children[1].location.x, 30.0000);
5902        assert_eq!(layout.children[1].location.y, 30.0000);
5903
5904        assert_eq!(layout.children[2].size.width, 30.0000);
5905        assert_eq!(layout.children[2].size.height, 30.0000);
5906        assert_eq!(layout.children[2].location.x, 60.0000);
5907        assert_eq!(layout.children[2].location.y, 20.0000);
5908
5909        assert_eq!(layout.children[3].size.width, 30.0000);
5910        assert_eq!(layout.children[3].size.height, 40.0000);
5911        assert_eq!(layout.children[3].location.x, 90.0000);
5912        assert_eq!(layout.children[3].location.y, 10.0000);
5913
5914        assert_eq!(layout.children[4].size.width, 30.0000);
5915        assert_eq!(layout.children[4].size.height, 50.0000);
5916        assert_eq!(layout.children[4].location.x, 120.0000);
5917        assert_eq!(layout.children[4].location.y, 0.0000);
5918    }
5919
5920    #[test]
5921    fn rounding_fractial_input_4() {
5922        let layout = stretch::compute(
5923            &stretch::style::Node {
5924                flex_direction: stretch::style::FlexDirection::Column,
5925                size: stretch::geometry::Size {
5926                    width: stretch::style::Dimension::Points(100.0000),
5927                    height: stretch::style::Dimension::Points(113.4000),
5928                    ..Default::default()
5929                },
5930                children: vec![
5931                    stretch::style::Node {
5932                        flex_grow: 1.0000,
5933                        flex_basis: stretch::style::Dimension::Points(50.0000),
5934                        size: stretch::geometry::Size {
5935                            height: stretch::style::Dimension::Points(20.0000),
5936                            ..Default::default()
5937                        },
5938                        ..Default::default()
5939                    },
5940                    stretch::style::Node {
5941                        flex_grow: 1.0000,
5942                        size: stretch::geometry::Size {
5943                            height: stretch::style::Dimension::Points(10.0000),
5944                            ..Default::default()
5945                        },
5946                        ..Default::default()
5947                    },
5948                    stretch::style::Node {
5949                        flex_grow: 1.0000,
5950                        size: stretch::geometry::Size {
5951                            height: stretch::style::Dimension::Points(10.0000),
5952                            ..Default::default()
5953                        },
5954                        ..Default::default()
5955                    },
5956                ],
5957                ..Default::default()
5958            },
5959            stretch::geometry::Size::undefined(),
5960        )
5961        .unwrap();
5962
5963        assert_eq!(layout.size.width, 100.0000);
5964        assert_eq!(layout.size.height, 113.0000);
5965        assert_eq!(layout.location.x, 0.0000);
5966        assert_eq!(layout.location.y, 0.0000);
5967
5968        assert_eq!(layout.children[0].size.width, 100.0000);
5969        assert_eq!(layout.children[0].size.height, 64.0000);
5970        assert_eq!(layout.children[0].location.x, 0.0000);
5971        assert_eq!(layout.children[0].location.y, 0.0000);
5972
5973        assert_eq!(layout.children[1].size.width, 100.0000);
5974        assert_eq!(layout.children[1].size.height, 25.0000);
5975        assert_eq!(layout.children[1].location.x, 0.0000);
5976        assert_eq!(layout.children[1].location.y, 64.0000);
5977
5978        assert_eq!(layout.children[2].size.width, 100.0000);
5979        assert_eq!(layout.children[2].size.height, 24.0000);
5980        assert_eq!(layout.children[2].location.x, 0.0000);
5981        assert_eq!(layout.children[2].location.y, 89.0000);
5982    }
5983
5984    #[test]
5985    fn width_smaller_then_content_with_flex_grow_unconstraint_size() {
5986        let layout = stretch::compute(
5987            &stretch::style::Node {
5988                children: vec![
5989                    stretch::style::Node {
5990                        flex_direction: stretch::style::FlexDirection::Column,
5991                        flex_grow: 1.0000,
5992                        size: stretch::geometry::Size {
5993                            width: stretch::style::Dimension::Points(0.0000),
5994                            ..Default::default()
5995                        },
5996                        children: vec![stretch::style::Node {
5997                            size: stretch::geometry::Size {
5998                                width: stretch::style::Dimension::Points(70.0000),
5999                                height: stretch::style::Dimension::Points(100.0000),
6000                                ..Default::default()
6001                            },
6002                            ..Default::default()
6003                        }],
6004                        ..Default::default()
6005                    },
6006                    stretch::style::Node {
6007                        flex_direction: stretch::style::FlexDirection::Column,
6008                        flex_grow: 1.0000,
6009                        size: stretch::geometry::Size {
6010                            width: stretch::style::Dimension::Points(0.0000),
6011                            ..Default::default()
6012                        },
6013                        children: vec![stretch::style::Node {
6014                            size: stretch::geometry::Size {
6015                                width: stretch::style::Dimension::Points(20.0000),
6016                                height: stretch::style::Dimension::Points(100.0000),
6017                                ..Default::default()
6018                            },
6019                            ..Default::default()
6020                        }],
6021                        ..Default::default()
6022                    },
6023                ],
6024                ..Default::default()
6025            },
6026            stretch::geometry::Size::undefined(),
6027        )
6028        .unwrap();
6029
6030        assert_eq!(layout.size.width, 0.0000);
6031        assert_eq!(layout.size.height, 100.0000);
6032        assert_eq!(layout.location.x, 0.0000);
6033        assert_eq!(layout.location.y, 0.0000);
6034
6035        assert_eq!(layout.children[0].size.width, 0.0000);
6036        assert_eq!(layout.children[0].size.height, 100.0000);
6037        assert_eq!(layout.children[0].location.x, 0.0000);
6038        assert_eq!(layout.children[0].location.y, 0.0000);
6039
6040        assert_eq!(layout.children[0].children[0].size.width, 70.0000);
6041        assert_eq!(layout.children[0].children[0].size.height, 100.0000);
6042        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
6043        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
6044
6045        assert_eq!(layout.children[1].size.width, 0.0000);
6046        assert_eq!(layout.children[1].size.height, 100.0000);
6047        assert_eq!(layout.children[1].location.x, 0.0000);
6048        assert_eq!(layout.children[1].location.y, 0.0000);
6049
6050        assert_eq!(layout.children[1].children[0].size.width, 20.0000);
6051        assert_eq!(layout.children[1].children[0].size.height, 100.0000);
6052        assert_eq!(layout.children[1].children[0].location.x, 0.0000);
6053        assert_eq!(layout.children[1].children[0].location.y, 0.0000);
6054    }
6055
6056    #[test]
6057    fn padding_flex_child() {
6058        let layout = stretch::compute(
6059            &stretch::style::Node {
6060                size: stretch::geometry::Size {
6061                    width: stretch::style::Dimension::Points(100.0000),
6062                    height: stretch::style::Dimension::Points(100.0000),
6063                    ..Default::default()
6064                },
6065                padding: stretch::geometry::Rect {
6066                    start: stretch::style::Dimension::Points(10.0000),
6067                    end: stretch::style::Dimension::Points(10.0000),
6068                    top: stretch::style::Dimension::Points(10.0000),
6069                    bottom: stretch::style::Dimension::Points(10.0000),
6070                    ..Default::default()
6071                },
6072                children: vec![stretch::style::Node {
6073                    flex_grow: 1.0000,
6074                    size: stretch::geometry::Size {
6075                        width: stretch::style::Dimension::Points(10.0000),
6076                        ..Default::default()
6077                    },
6078                    ..Default::default()
6079                }],
6080                ..Default::default()
6081            },
6082            stretch::geometry::Size::undefined(),
6083        )
6084        .unwrap();
6085
6086        assert_eq!(layout.size.width, 100.0000);
6087        assert_eq!(layout.size.height, 100.0000);
6088        assert_eq!(layout.location.x, 0.0000);
6089        assert_eq!(layout.location.y, 0.0000);
6090
6091        assert_eq!(layout.children[0].size.width, 80.0000);
6092        assert_eq!(layout.children[0].size.height, 80.0000);
6093        assert_eq!(layout.children[0].location.x, 10.0000);
6094        assert_eq!(layout.children[0].location.y, 10.0000);
6095    }
6096
6097    #[test]
6098    fn flex_direction_row_reverse() {
6099        let layout = stretch::compute(
6100            &stretch::style::Node {
6101                flex_direction: stretch::style::FlexDirection::RowReverse,
6102                size: stretch::geometry::Size {
6103                    width: stretch::style::Dimension::Points(100.0000),
6104                    height: stretch::style::Dimension::Points(100.0000),
6105                    ..Default::default()
6106                },
6107                children: vec![
6108                    stretch::style::Node {
6109                        size: stretch::geometry::Size {
6110                            width: stretch::style::Dimension::Points(10.0000),
6111                            ..Default::default()
6112                        },
6113                        ..Default::default()
6114                    },
6115                    stretch::style::Node {
6116                        size: stretch::geometry::Size {
6117                            width: stretch::style::Dimension::Points(10.0000),
6118                            ..Default::default()
6119                        },
6120                        ..Default::default()
6121                    },
6122                    stretch::style::Node {
6123                        size: stretch::geometry::Size {
6124                            width: stretch::style::Dimension::Points(10.0000),
6125                            ..Default::default()
6126                        },
6127                        ..Default::default()
6128                    },
6129                ],
6130                ..Default::default()
6131            },
6132            stretch::geometry::Size::undefined(),
6133        )
6134        .unwrap();
6135
6136        assert_eq!(layout.size.width, 100.0000);
6137        assert_eq!(layout.size.height, 100.0000);
6138        assert_eq!(layout.location.x, 0.0000);
6139        assert_eq!(layout.location.y, 0.0000);
6140
6141        assert_eq!(layout.children[0].size.width, 10.0000);
6142        assert_eq!(layout.children[0].size.height, 100.0000);
6143        assert_eq!(layout.children[0].location.x, 90.0000);
6144        assert_eq!(layout.children[0].location.y, 0.0000);
6145
6146        assert_eq!(layout.children[1].size.width, 10.0000);
6147        assert_eq!(layout.children[1].size.height, 100.0000);
6148        assert_eq!(layout.children[1].location.x, 80.0000);
6149        assert_eq!(layout.children[1].location.y, 0.0000);
6150
6151        assert_eq!(layout.children[2].size.width, 10.0000);
6152        assert_eq!(layout.children[2].size.height, 100.0000);
6153        assert_eq!(layout.children[2].location.x, 70.0000);
6154        assert_eq!(layout.children[2].location.y, 0.0000);
6155    }
6156
6157    #[test]
6158    fn percentage_size_based_on_parent_inner_size() {
6159        let layout = stretch::compute(
6160            &stretch::style::Node {
6161                flex_direction: stretch::style::FlexDirection::Column,
6162                size: stretch::geometry::Size {
6163                    width: stretch::style::Dimension::Points(200.0000),
6164                    height: stretch::style::Dimension::Points(400.0000),
6165                    ..Default::default()
6166                },
6167                padding: stretch::geometry::Rect {
6168                    start: stretch::style::Dimension::Points(20.0000),
6169                    end: stretch::style::Dimension::Points(20.0000),
6170                    top: stretch::style::Dimension::Points(20.0000),
6171                    bottom: stretch::style::Dimension::Points(20.0000),
6172                    ..Default::default()
6173                },
6174                children: vec![stretch::style::Node {
6175                    size: stretch::geometry::Size {
6176                        width: stretch::style::Dimension::Percent(0.5000),
6177                        height: stretch::style::Dimension::Percent(0.5000),
6178                        ..Default::default()
6179                    },
6180                    ..Default::default()
6181                }],
6182                ..Default::default()
6183            },
6184            stretch::geometry::Size::undefined(),
6185        )
6186        .unwrap();
6187
6188        assert_eq!(layout.size.width, 200.0000);
6189        assert_eq!(layout.size.height, 400.0000);
6190        assert_eq!(layout.location.x, 0.0000);
6191        assert_eq!(layout.location.y, 0.0000);
6192
6193        assert_eq!(layout.children[0].size.width, 80.0000);
6194        assert_eq!(layout.children[0].size.height, 180.0000);
6195        assert_eq!(layout.children[0].location.x, 20.0000);
6196        assert_eq!(layout.children[0].location.y, 20.0000);
6197    }
6198
6199    #[test]
6200    fn wrap_reverse_row_align_content_stretch() {
6201        let layout = stretch::compute(
6202            &stretch::style::Node {
6203                flex_wrap: stretch::style::FlexWrap::WrapReverse,
6204                size: stretch::geometry::Size {
6205                    width: stretch::style::Dimension::Points(100.0000),
6206                    ..Default::default()
6207                },
6208                children: vec![
6209                    stretch::style::Node {
6210                        size: stretch::geometry::Size {
6211                            width: stretch::style::Dimension::Points(30.0000),
6212                            height: stretch::style::Dimension::Points(10.0000),
6213                            ..Default::default()
6214                        },
6215                        ..Default::default()
6216                    },
6217                    stretch::style::Node {
6218                        size: stretch::geometry::Size {
6219                            width: stretch::style::Dimension::Points(30.0000),
6220                            height: stretch::style::Dimension::Points(20.0000),
6221                            ..Default::default()
6222                        },
6223                        ..Default::default()
6224                    },
6225                    stretch::style::Node {
6226                        size: stretch::geometry::Size {
6227                            width: stretch::style::Dimension::Points(30.0000),
6228                            height: stretch::style::Dimension::Points(30.0000),
6229                            ..Default::default()
6230                        },
6231                        ..Default::default()
6232                    },
6233                    stretch::style::Node {
6234                        size: stretch::geometry::Size {
6235                            width: stretch::style::Dimension::Points(30.0000),
6236                            height: stretch::style::Dimension::Points(40.0000),
6237                            ..Default::default()
6238                        },
6239                        ..Default::default()
6240                    },
6241                    stretch::style::Node {
6242                        size: stretch::geometry::Size {
6243                            width: stretch::style::Dimension::Points(30.0000),
6244                            height: stretch::style::Dimension::Points(50.0000),
6245                            ..Default::default()
6246                        },
6247                        ..Default::default()
6248                    },
6249                ],
6250                ..Default::default()
6251            },
6252            stretch::geometry::Size::undefined(),
6253        )
6254        .unwrap();
6255
6256        assert_eq!(layout.size.width, 100.0000);
6257        assert_eq!(layout.size.height, 80.0000);
6258        assert_eq!(layout.location.x, 0.0000);
6259        assert_eq!(layout.location.y, 0.0000);
6260
6261        assert_eq!(layout.children[0].size.width, 30.0000);
6262        assert_eq!(layout.children[0].size.height, 10.0000);
6263        assert_eq!(layout.children[0].location.x, 0.0000);
6264        assert_eq!(layout.children[0].location.y, 70.0000);
6265
6266        assert_eq!(layout.children[1].size.width, 30.0000);
6267        assert_eq!(layout.children[1].size.height, 20.0000);
6268        assert_eq!(layout.children[1].location.x, 30.0000);
6269        assert_eq!(layout.children[1].location.y, 60.0000);
6270
6271        assert_eq!(layout.children[2].size.width, 30.0000);
6272        assert_eq!(layout.children[2].size.height, 30.0000);
6273        assert_eq!(layout.children[2].location.x, 60.0000);
6274        assert_eq!(layout.children[2].location.y, 50.0000);
6275
6276        assert_eq!(layout.children[3].size.width, 30.0000);
6277        assert_eq!(layout.children[3].size.height, 40.0000);
6278        assert_eq!(layout.children[3].location.x, 0.0000);
6279        assert_eq!(layout.children[3].location.y, 10.0000);
6280
6281        assert_eq!(layout.children[4].size.width, 30.0000);
6282        assert_eq!(layout.children[4].size.height, 50.0000);
6283        assert_eq!(layout.children[4].location.x, 30.0000);
6284        assert_eq!(layout.children[4].location.y, 0.0000);
6285    }
6286
6287    #[test]
6288    fn margin_auto_top() {
6289        let layout = stretch::compute(
6290            &stretch::style::Node {
6291                align_items: stretch::style::AlignItems::Center,
6292                size: stretch::geometry::Size {
6293                    width: stretch::style::Dimension::Points(200.0000),
6294                    height: stretch::style::Dimension::Points(200.0000),
6295                    ..Default::default()
6296                },
6297                children: vec![
6298                    stretch::style::Node {
6299                        size: stretch::geometry::Size {
6300                            width: stretch::style::Dimension::Points(50.0000),
6301                            height: stretch::style::Dimension::Points(50.0000),
6302                            ..Default::default()
6303                        },
6304                        margin: stretch::geometry::Rect { top: stretch::style::Dimension::Auto, ..Default::default() },
6305                        ..Default::default()
6306                    },
6307                    stretch::style::Node {
6308                        size: stretch::geometry::Size {
6309                            width: stretch::style::Dimension::Points(50.0000),
6310                            height: stretch::style::Dimension::Points(50.0000),
6311                            ..Default::default()
6312                        },
6313                        ..Default::default()
6314                    },
6315                ],
6316                ..Default::default()
6317            },
6318            stretch::geometry::Size::undefined(),
6319        )
6320        .unwrap();
6321
6322        assert_eq!(layout.size.width, 200.0000);
6323        assert_eq!(layout.size.height, 200.0000);
6324        assert_eq!(layout.location.x, 0.0000);
6325        assert_eq!(layout.location.y, 0.0000);
6326
6327        assert_eq!(layout.children[0].size.width, 50.0000);
6328        assert_eq!(layout.children[0].size.height, 50.0000);
6329        assert_eq!(layout.children[0].location.x, 0.0000);
6330        assert_eq!(layout.children[0].location.y, 150.0000);
6331
6332        assert_eq!(layout.children[1].size.width, 50.0000);
6333        assert_eq!(layout.children[1].size.height, 50.0000);
6334        assert_eq!(layout.children[1].location.x, 50.0000);
6335        assert_eq!(layout.children[1].location.y, 75.0000);
6336    }
6337
6338    #[test]
6339    fn flex_grow_within_constrained_max_row() {
6340        let layout = stretch::compute(
6341            &stretch::style::Node {
6342                flex_direction: stretch::style::FlexDirection::Column,
6343                size: stretch::geometry::Size {
6344                    width: stretch::style::Dimension::Points(200.0000),
6345                    ..Default::default()
6346                },
6347                children: vec![stretch::style::Node {
6348                    size: stretch::geometry::Size {
6349                        height: stretch::style::Dimension::Points(100.0000),
6350                        ..Default::default()
6351                    },
6352                    max_size: stretch::geometry::Size {
6353                        width: stretch::style::Dimension::Points(100.0000),
6354                        ..Default::default()
6355                    },
6356                    children: vec![
6357                        stretch::style::Node {
6358                            flex_shrink: 1.0000,
6359                            flex_basis: stretch::style::Dimension::Points(100.0000),
6360                            ..Default::default()
6361                        },
6362                        stretch::style::Node {
6363                            size: stretch::geometry::Size {
6364                                width: stretch::style::Dimension::Points(50.0000),
6365                                ..Default::default()
6366                            },
6367                            ..Default::default()
6368                        },
6369                    ],
6370                    ..Default::default()
6371                }],
6372                ..Default::default()
6373            },
6374            stretch::geometry::Size::undefined(),
6375        )
6376        .unwrap();
6377
6378        assert_eq!(layout.size.width, 200.0000);
6379        assert_eq!(layout.size.height, 100.0000);
6380        assert_eq!(layout.location.x, 0.0000);
6381        assert_eq!(layout.location.y, 0.0000);
6382
6383        assert_eq!(layout.children[0].size.width, 100.0000);
6384        assert_eq!(layout.children[0].size.height, 100.0000);
6385        assert_eq!(layout.children[0].location.x, 0.0000);
6386        assert_eq!(layout.children[0].location.y, 0.0000);
6387
6388        assert_eq!(layout.children[0].children[0].size.width, 67.0000);
6389        assert_eq!(layout.children[0].children[0].size.height, 100.0000);
6390        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
6391        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
6392
6393        assert_eq!(layout.children[0].children[1].size.width, 33.0000);
6394        assert_eq!(layout.children[0].children[1].size.height, 100.0000);
6395        assert_eq!(layout.children[0].children[1].location.x, 67.0000);
6396        assert_eq!(layout.children[0].children[1].location.y, 0.0000);
6397    }
6398
6399    #[test]
6400    fn absolute_layout_align_items_and_justify_content_center() {
6401        let layout = stretch::compute(
6402            &stretch::style::Node {
6403                align_items: stretch::style::AlignItems::Center,
6404                justify_content: stretch::style::JustifyContent::Center,
6405                size: stretch::geometry::Size {
6406                    width: stretch::style::Dimension::Points(110.0000),
6407                    height: stretch::style::Dimension::Points(100.0000),
6408                    ..Default::default()
6409                },
6410                children: vec![stretch::style::Node {
6411                    position_type: stretch::style::PositionType::Absolute,
6412                    size: stretch::geometry::Size {
6413                        width: stretch::style::Dimension::Points(60.0000),
6414                        height: stretch::style::Dimension::Points(40.0000),
6415                        ..Default::default()
6416                    },
6417                    ..Default::default()
6418                }],
6419                ..Default::default()
6420            },
6421            stretch::geometry::Size::undefined(),
6422        )
6423        .unwrap();
6424
6425        assert_eq!(layout.size.width, 110.0000);
6426        assert_eq!(layout.size.height, 100.0000);
6427        assert_eq!(layout.location.x, 0.0000);
6428        assert_eq!(layout.location.y, 0.0000);
6429
6430        assert_eq!(layout.children[0].size.width, 60.0000);
6431        assert_eq!(layout.children[0].size.height, 40.0000);
6432        assert_eq!(layout.children[0].location.x, 25.0000);
6433        assert_eq!(layout.children[0].location.y, 30.0000);
6434    }
6435
6436    #[test]
6437    fn align_self_flex_end() {
6438        let layout = stretch::compute(
6439            &stretch::style::Node {
6440                size: stretch::geometry::Size {
6441                    width: stretch::style::Dimension::Points(100.0000),
6442                    height: stretch::style::Dimension::Points(100.0000),
6443                    ..Default::default()
6444                },
6445                children: vec![stretch::style::Node {
6446                    align_self: stretch::style::AlignSelf::FlexEnd,
6447                    size: stretch::geometry::Size {
6448                        width: stretch::style::Dimension::Points(10.0000),
6449                        height: stretch::style::Dimension::Points(10.0000),
6450                        ..Default::default()
6451                    },
6452                    ..Default::default()
6453                }],
6454                ..Default::default()
6455            },
6456            stretch::geometry::Size::undefined(),
6457        )
6458        .unwrap();
6459
6460        assert_eq!(layout.size.width, 100.0000);
6461        assert_eq!(layout.size.height, 100.0000);
6462        assert_eq!(layout.location.x, 0.0000);
6463        assert_eq!(layout.location.y, 0.0000);
6464
6465        assert_eq!(layout.children[0].size.width, 10.0000);
6466        assert_eq!(layout.children[0].size.height, 10.0000);
6467        assert_eq!(layout.children[0].location.x, 0.0000);
6468        assert_eq!(layout.children[0].location.y, 90.0000);
6469    }
6470
6471    #[test]
6472    fn margin_auto_left_child_bigger_than_parent() {
6473        let layout = stretch::compute(
6474            &stretch::style::Node {
6475                justify_content: stretch::style::JustifyContent::Center,
6476                size: stretch::geometry::Size {
6477                    width: stretch::style::Dimension::Points(52.0000),
6478                    height: stretch::style::Dimension::Points(52.0000),
6479                    ..Default::default()
6480                },
6481                children: vec![stretch::style::Node {
6482                    size: stretch::geometry::Size {
6483                        width: stretch::style::Dimension::Points(72.0000),
6484                        height: stretch::style::Dimension::Points(72.0000),
6485                        ..Default::default()
6486                    },
6487                    margin: stretch::geometry::Rect { start: stretch::style::Dimension::Auto, ..Default::default() },
6488                    ..Default::default()
6489                }],
6490                ..Default::default()
6491            },
6492            stretch::geometry::Size::undefined(),
6493        )
6494        .unwrap();
6495
6496        assert_eq!(layout.size.width, 52.0000);
6497        assert_eq!(layout.size.height, 52.0000);
6498        assert_eq!(layout.location.x, 0.0000);
6499        assert_eq!(layout.location.y, 0.0000);
6500
6501        assert_eq!(layout.children[0].size.width, 52.0000);
6502        assert_eq!(layout.children[0].size.height, 72.0000);
6503        assert_eq!(layout.children[0].location.x, 0.0000);
6504        assert_eq!(layout.children[0].location.y, 0.0000);
6505    }
6506
6507    #[test]
6508    fn wrapped_row_within_align_items_flex_end() {
6509        let layout = stretch::compute(
6510            &stretch::style::Node {
6511                flex_direction: stretch::style::FlexDirection::Column,
6512                align_items: stretch::style::AlignItems::FlexEnd,
6513                size: stretch::geometry::Size {
6514                    width: stretch::style::Dimension::Points(200.0000),
6515                    height: stretch::style::Dimension::Points(200.0000),
6516                    ..Default::default()
6517                },
6518                children: vec![stretch::style::Node {
6519                    flex_wrap: stretch::style::FlexWrap::Wrap,
6520                    children: vec![
6521                        stretch::style::Node {
6522                            size: stretch::geometry::Size {
6523                                width: stretch::style::Dimension::Points(150.0000),
6524                                height: stretch::style::Dimension::Points(80.0000),
6525                                ..Default::default()
6526                            },
6527                            ..Default::default()
6528                        },
6529                        stretch::style::Node {
6530                            size: stretch::geometry::Size {
6531                                width: stretch::style::Dimension::Points(80.0000),
6532                                height: stretch::style::Dimension::Points(80.0000),
6533                                ..Default::default()
6534                            },
6535                            ..Default::default()
6536                        },
6537                    ],
6538                    ..Default::default()
6539                }],
6540                ..Default::default()
6541            },
6542            stretch::geometry::Size::undefined(),
6543        )
6544        .unwrap();
6545
6546        assert_eq!(layout.size.width, 200.0000);
6547        assert_eq!(layout.size.height, 200.0000);
6548        assert_eq!(layout.location.x, 0.0000);
6549        assert_eq!(layout.location.y, 0.0000);
6550
6551        assert_eq!(layout.children[0].size.width, 200.0000);
6552        assert_eq!(layout.children[0].size.height, 160.0000);
6553        assert_eq!(layout.children[0].location.x, 0.0000);
6554        assert_eq!(layout.children[0].location.y, 0.0000);
6555
6556        assert_eq!(layout.children[0].children[0].size.width, 150.0000);
6557        assert_eq!(layout.children[0].children[0].size.height, 80.0000);
6558        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
6559        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
6560
6561        assert_eq!(layout.children[0].children[1].size.width, 80.0000);
6562        assert_eq!(layout.children[0].children[1].size.height, 80.0000);
6563        assert_eq!(layout.children[0].children[1].location.x, 0.0000);
6564        assert_eq!(layout.children[0].children[1].location.y, 80.0000);
6565    }
6566
6567    #[test]
6568    fn min_height_overrides_height() {
6569        let layout = stretch::compute(
6570            &stretch::style::Node {
6571                children: vec![stretch::style::Node {
6572                    size: stretch::geometry::Size {
6573                        height: stretch::style::Dimension::Points(50.0000),
6574                        ..Default::default()
6575                    },
6576                    min_size: stretch::geometry::Size {
6577                        height: stretch::style::Dimension::Points(100.0000),
6578                        ..Default::default()
6579                    },
6580                    ..Default::default()
6581                }],
6582                ..Default::default()
6583            },
6584            stretch::geometry::Size::undefined(),
6585        )
6586        .unwrap();
6587
6588        assert_eq!(layout.size.width, 0.0000);
6589        assert_eq!(layout.size.height, 100.0000);
6590        assert_eq!(layout.location.x, 0.0000);
6591        assert_eq!(layout.location.y, 0.0000);
6592
6593        assert_eq!(layout.children[0].size.width, 0.0000);
6594        assert_eq!(layout.children[0].size.height, 100.0000);
6595        assert_eq!(layout.children[0].location.x, 0.0000);
6596        assert_eq!(layout.children[0].location.y, 0.0000);
6597    }
6598
6599    #[test]
6600    fn align_strech_should_size_based_on_parent() {
6601        let layout = stretch::compute(
6602            &stretch::style::Node {
6603                size: stretch::geometry::Size {
6604                    width: stretch::style::Dimension::Points(100.0000),
6605                    height: stretch::style::Dimension::Points(100.0000),
6606                    ..Default::default()
6607                },
6608                children: vec![stretch::style::Node {
6609                    justify_content: stretch::style::JustifyContent::Center,
6610                    flex_grow: 0.0000,
6611                    flex_shrink: 1.0000,
6612                    children: vec![stretch::style::Node {
6613                        flex_grow: 1.0000,
6614                        flex_shrink: 1.0000,
6615                        children: vec![stretch::style::Node {
6616                            size: stretch::geometry::Size {
6617                                width: stretch::style::Dimension::Points(20.0000),
6618                                height: stretch::style::Dimension::Points(20.0000),
6619                                ..Default::default()
6620                            },
6621                            ..Default::default()
6622                        }],
6623                        ..Default::default()
6624                    }],
6625                    ..Default::default()
6626                }],
6627                ..Default::default()
6628            },
6629            stretch::geometry::Size::undefined(),
6630        )
6631        .unwrap();
6632
6633        assert_eq!(layout.size.width, 100.0000);
6634        assert_eq!(layout.size.height, 100.0000);
6635        assert_eq!(layout.location.x, 0.0000);
6636        assert_eq!(layout.location.y, 0.0000);
6637
6638        assert_eq!(layout.children[0].size.width, 20.0000);
6639        assert_eq!(layout.children[0].size.height, 100.0000);
6640        assert_eq!(layout.children[0].location.x, 0.0000);
6641        assert_eq!(layout.children[0].location.y, 0.0000);
6642
6643        assert_eq!(layout.children[0].children[0].size.width, 20.0000);
6644        assert_eq!(layout.children[0].children[0].size.height, 100.0000);
6645        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
6646        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
6647
6648        assert_eq!(layout.children[0].children[0].children[0].size.width, 20.0000);
6649        assert_eq!(layout.children[0].children[0].children[0].size.height, 20.0000);
6650        assert_eq!(layout.children[0].children[0].children[0].location.x, 0.0000);
6651        assert_eq!(layout.children[0].children[0].children[0].location.y, 0.0000);
6652    }
6653
6654    #[test]
6655    fn wrap_row_align_items_flex_end() {
6656        let layout = stretch::compute(
6657            &stretch::style::Node {
6658                flex_wrap: stretch::style::FlexWrap::Wrap,
6659                align_items: stretch::style::AlignItems::FlexEnd,
6660                size: stretch::geometry::Size {
6661                    width: stretch::style::Dimension::Points(100.0000),
6662                    ..Default::default()
6663                },
6664                children: vec![
6665                    stretch::style::Node {
6666                        size: stretch::geometry::Size {
6667                            width: stretch::style::Dimension::Points(30.0000),
6668                            height: stretch::style::Dimension::Points(10.0000),
6669                            ..Default::default()
6670                        },
6671                        ..Default::default()
6672                    },
6673                    stretch::style::Node {
6674                        size: stretch::geometry::Size {
6675                            width: stretch::style::Dimension::Points(30.0000),
6676                            height: stretch::style::Dimension::Points(20.0000),
6677                            ..Default::default()
6678                        },
6679                        ..Default::default()
6680                    },
6681                    stretch::style::Node {
6682                        size: stretch::geometry::Size {
6683                            width: stretch::style::Dimension::Points(30.0000),
6684                            height: stretch::style::Dimension::Points(30.0000),
6685                            ..Default::default()
6686                        },
6687                        ..Default::default()
6688                    },
6689                    stretch::style::Node {
6690                        size: stretch::geometry::Size {
6691                            width: stretch::style::Dimension::Points(30.0000),
6692                            height: stretch::style::Dimension::Points(30.0000),
6693                            ..Default::default()
6694                        },
6695                        ..Default::default()
6696                    },
6697                ],
6698                ..Default::default()
6699            },
6700            stretch::geometry::Size::undefined(),
6701        )
6702        .unwrap();
6703
6704        assert_eq!(layout.size.width, 100.0000);
6705        assert_eq!(layout.size.height, 60.0000);
6706        assert_eq!(layout.location.x, 0.0000);
6707        assert_eq!(layout.location.y, 0.0000);
6708
6709        assert_eq!(layout.children[0].size.width, 30.0000);
6710        assert_eq!(layout.children[0].size.height, 10.0000);
6711        assert_eq!(layout.children[0].location.x, 0.0000);
6712        assert_eq!(layout.children[0].location.y, 20.0000);
6713
6714        assert_eq!(layout.children[1].size.width, 30.0000);
6715        assert_eq!(layout.children[1].size.height, 20.0000);
6716        assert_eq!(layout.children[1].location.x, 30.0000);
6717        assert_eq!(layout.children[1].location.y, 10.0000);
6718
6719        assert_eq!(layout.children[2].size.width, 30.0000);
6720        assert_eq!(layout.children[2].size.height, 30.0000);
6721        assert_eq!(layout.children[2].location.x, 60.0000);
6722        assert_eq!(layout.children[2].location.y, 0.0000);
6723
6724        assert_eq!(layout.children[3].size.width, 30.0000);
6725        assert_eq!(layout.children[3].size.height, 30.0000);
6726        assert_eq!(layout.children[3].location.x, 0.0000);
6727        assert_eq!(layout.children[3].location.y, 30.0000);
6728    }
6729
6730    #[test]
6731    fn size_defined_by_child_with_border() {
6732        let layout = stretch::compute(
6733            &stretch::style::Node {
6734                border: stretch::geometry::Rect {
6735                    start: stretch::style::Dimension::Points(10.0000),
6736                    end: stretch::style::Dimension::Points(10.0000),
6737                    top: stretch::style::Dimension::Points(10.0000),
6738                    bottom: stretch::style::Dimension::Points(10.0000),
6739                    ..Default::default()
6740                },
6741                children: vec![stretch::style::Node {
6742                    size: stretch::geometry::Size {
6743                        width: stretch::style::Dimension::Points(10.0000),
6744                        height: stretch::style::Dimension::Points(10.0000),
6745                        ..Default::default()
6746                    },
6747                    ..Default::default()
6748                }],
6749                ..Default::default()
6750            },
6751            stretch::geometry::Size::undefined(),
6752        )
6753        .unwrap();
6754
6755        assert_eq!(layout.size.width, 30.0000);
6756        assert_eq!(layout.size.height, 30.0000);
6757        assert_eq!(layout.location.x, 0.0000);
6758        assert_eq!(layout.location.y, 0.0000);
6759
6760        assert_eq!(layout.children[0].size.width, 10.0000);
6761        assert_eq!(layout.children[0].size.height, 10.0000);
6762        assert_eq!(layout.children[0].location.x, 10.0000);
6763        assert_eq!(layout.children[0].location.y, 10.0000);
6764    }
6765
6766    #[test]
6767    fn margin_auto_bottom_and_top_justify_center() {
6768        let layout = stretch::compute(
6769            &stretch::style::Node {
6770                justify_content: stretch::style::JustifyContent::Center,
6771                size: stretch::geometry::Size {
6772                    width: stretch::style::Dimension::Points(200.0000),
6773                    height: stretch::style::Dimension::Points(200.0000),
6774                    ..Default::default()
6775                },
6776                children: vec![
6777                    stretch::style::Node {
6778                        size: stretch::geometry::Size {
6779                            width: stretch::style::Dimension::Points(50.0000),
6780                            height: stretch::style::Dimension::Points(50.0000),
6781                            ..Default::default()
6782                        },
6783                        margin: stretch::geometry::Rect {
6784                            top: stretch::style::Dimension::Auto,
6785                            bottom: stretch::style::Dimension::Auto,
6786                            ..Default::default()
6787                        },
6788                        ..Default::default()
6789                    },
6790                    stretch::style::Node {
6791                        size: stretch::geometry::Size {
6792                            width: stretch::style::Dimension::Points(50.0000),
6793                            height: stretch::style::Dimension::Points(50.0000),
6794                            ..Default::default()
6795                        },
6796                        ..Default::default()
6797                    },
6798                ],
6799                ..Default::default()
6800            },
6801            stretch::geometry::Size::undefined(),
6802        )
6803        .unwrap();
6804
6805        assert_eq!(layout.size.width, 200.0000);
6806        assert_eq!(layout.size.height, 200.0000);
6807        assert_eq!(layout.location.x, 0.0000);
6808        assert_eq!(layout.location.y, 0.0000);
6809
6810        assert_eq!(layout.children[0].size.width, 50.0000);
6811        assert_eq!(layout.children[0].size.height, 50.0000);
6812        assert_eq!(layout.children[0].location.x, 50.0000);
6813        assert_eq!(layout.children[0].location.y, 75.0000);
6814
6815        assert_eq!(layout.children[1].size.width, 50.0000);
6816        assert_eq!(layout.children[1].size.height, 50.0000);
6817        assert_eq!(layout.children[1].location.x, 100.0000);
6818        assert_eq!(layout.children[1].location.y, 0.0000);
6819    }
6820
6821    #[test]
6822    fn flex_basis_overrides_main_size() {
6823        let layout = stretch::compute(
6824            &stretch::style::Node {
6825                size: stretch::geometry::Size {
6826                    width: stretch::style::Dimension::Points(100.0000),
6827                    height: stretch::style::Dimension::Points(100.0000),
6828                    ..Default::default()
6829                },
6830                children: vec![
6831                    stretch::style::Node {
6832                        flex_grow: 1.0000,
6833                        flex_basis: stretch::style::Dimension::Points(50.0000),
6834                        size: stretch::geometry::Size {
6835                            width: stretch::style::Dimension::Points(20.0000),
6836                            ..Default::default()
6837                        },
6838                        ..Default::default()
6839                    },
6840                    stretch::style::Node {
6841                        flex_grow: 1.0000,
6842                        size: stretch::geometry::Size {
6843                            width: stretch::style::Dimension::Points(10.0000),
6844                            ..Default::default()
6845                        },
6846                        ..Default::default()
6847                    },
6848                    stretch::style::Node {
6849                        flex_grow: 1.0000,
6850                        size: stretch::geometry::Size {
6851                            width: stretch::style::Dimension::Points(10.0000),
6852                            ..Default::default()
6853                        },
6854                        ..Default::default()
6855                    },
6856                ],
6857                ..Default::default()
6858            },
6859            stretch::geometry::Size::undefined(),
6860        )
6861        .unwrap();
6862
6863        assert_eq!(layout.size.width, 100.0000);
6864        assert_eq!(layout.size.height, 100.0000);
6865        assert_eq!(layout.location.x, 0.0000);
6866        assert_eq!(layout.location.y, 0.0000);
6867
6868        assert_eq!(layout.children[0].size.width, 60.0000);
6869        assert_eq!(layout.children[0].size.height, 100.0000);
6870        assert_eq!(layout.children[0].location.x, 0.0000);
6871        assert_eq!(layout.children[0].location.y, 0.0000);
6872
6873        assert_eq!(layout.children[1].size.width, 20.0000);
6874        assert_eq!(layout.children[1].size.height, 100.0000);
6875        assert_eq!(layout.children[1].location.x, 60.0000);
6876        assert_eq!(layout.children[1].location.y, 0.0000);
6877
6878        assert_eq!(layout.children[2].size.width, 20.0000);
6879        assert_eq!(layout.children[2].size.height, 100.0000);
6880        assert_eq!(layout.children[2].location.x, 80.0000);
6881        assert_eq!(layout.children[2].location.y, 0.0000);
6882    }
6883
6884    #[test]
6885    fn wrapped_row_within_align_items_flex_start() {
6886        let layout = stretch::compute(
6887            &stretch::style::Node {
6888                flex_direction: stretch::style::FlexDirection::Column,
6889                align_items: stretch::style::AlignItems::FlexStart,
6890                size: stretch::geometry::Size {
6891                    width: stretch::style::Dimension::Points(200.0000),
6892                    height: stretch::style::Dimension::Points(200.0000),
6893                    ..Default::default()
6894                },
6895                children: vec![stretch::style::Node {
6896                    flex_wrap: stretch::style::FlexWrap::Wrap,
6897                    children: vec![
6898                        stretch::style::Node {
6899                            size: stretch::geometry::Size {
6900                                width: stretch::style::Dimension::Points(150.0000),
6901                                height: stretch::style::Dimension::Points(80.0000),
6902                                ..Default::default()
6903                            },
6904                            ..Default::default()
6905                        },
6906                        stretch::style::Node {
6907                            size: stretch::geometry::Size {
6908                                width: stretch::style::Dimension::Points(80.0000),
6909                                height: stretch::style::Dimension::Points(80.0000),
6910                                ..Default::default()
6911                            },
6912                            ..Default::default()
6913                        },
6914                    ],
6915                    ..Default::default()
6916                }],
6917                ..Default::default()
6918            },
6919            stretch::geometry::Size::undefined(),
6920        )
6921        .unwrap();
6922
6923        assert_eq!(layout.size.width, 200.0000);
6924        assert_eq!(layout.size.height, 200.0000);
6925        assert_eq!(layout.location.x, 0.0000);
6926        assert_eq!(layout.location.y, 0.0000);
6927
6928        assert_eq!(layout.children[0].size.width, 200.0000);
6929        assert_eq!(layout.children[0].size.height, 160.0000);
6930        assert_eq!(layout.children[0].location.x, 0.0000);
6931        assert_eq!(layout.children[0].location.y, 0.0000);
6932
6933        assert_eq!(layout.children[0].children[0].size.width, 150.0000);
6934        assert_eq!(layout.children[0].children[0].size.height, 80.0000);
6935        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
6936        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
6937
6938        assert_eq!(layout.children[0].children[1].size.width, 80.0000);
6939        assert_eq!(layout.children[0].children[1].size.height, 80.0000);
6940        assert_eq!(layout.children[0].children[1].location.x, 0.0000);
6941        assert_eq!(layout.children[0].children[1].location.y, 80.0000);
6942    }
6943
6944    #[test]
6945    fn align_center_should_size_based_on_content() {
6946        let layout = stretch::compute(
6947            &stretch::style::Node {
6948                align_items: stretch::style::AlignItems::Center,
6949                size: stretch::geometry::Size {
6950                    width: stretch::style::Dimension::Points(100.0000),
6951                    height: stretch::style::Dimension::Points(100.0000),
6952                    ..Default::default()
6953                },
6954                children: vec![stretch::style::Node {
6955                    justify_content: stretch::style::JustifyContent::Center,
6956                    flex_grow: 0.0000,
6957                    flex_shrink: 1.0000,
6958                    children: vec![stretch::style::Node {
6959                        flex_grow: 1.0000,
6960                        flex_shrink: 1.0000,
6961                        children: vec![stretch::style::Node {
6962                            size: stretch::geometry::Size {
6963                                width: stretch::style::Dimension::Points(20.0000),
6964                                height: stretch::style::Dimension::Points(20.0000),
6965                                ..Default::default()
6966                            },
6967                            ..Default::default()
6968                        }],
6969                        ..Default::default()
6970                    }],
6971                    ..Default::default()
6972                }],
6973                ..Default::default()
6974            },
6975            stretch::geometry::Size::undefined(),
6976        )
6977        .unwrap();
6978
6979        assert_eq!(layout.size.width, 100.0000);
6980        assert_eq!(layout.size.height, 100.0000);
6981        assert_eq!(layout.location.x, 0.0000);
6982        assert_eq!(layout.location.y, 0.0000);
6983
6984        assert_eq!(layout.children[0].size.width, 20.0000);
6985        assert_eq!(layout.children[0].size.height, 20.0000);
6986        assert_eq!(layout.children[0].location.x, 0.0000);
6987        assert_eq!(layout.children[0].location.y, 40.0000);
6988
6989        assert_eq!(layout.children[0].children[0].size.width, 20.0000);
6990        assert_eq!(layout.children[0].children[0].size.height, 20.0000);
6991        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
6992        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
6993
6994        assert_eq!(layout.children[0].children[0].children[0].size.width, 20.0000);
6995        assert_eq!(layout.children[0].children[0].children[0].size.height, 20.0000);
6996        assert_eq!(layout.children[0].children[0].children[0].location.x, 0.0000);
6997        assert_eq!(layout.children[0].children[0].children[0].location.y, 0.0000);
6998    }
6999
7000    #[test]
7001    fn margin_auto_right() {
7002        let layout = stretch::compute(
7003            &stretch::style::Node {
7004                align_items: stretch::style::AlignItems::Center,
7005                size: stretch::geometry::Size {
7006                    width: stretch::style::Dimension::Points(200.0000),
7007                    height: stretch::style::Dimension::Points(200.0000),
7008                    ..Default::default()
7009                },
7010                children: vec![
7011                    stretch::style::Node {
7012                        size: stretch::geometry::Size {
7013                            width: stretch::style::Dimension::Points(50.0000),
7014                            height: stretch::style::Dimension::Points(50.0000),
7015                            ..Default::default()
7016                        },
7017                        margin: stretch::geometry::Rect { end: stretch::style::Dimension::Auto, ..Default::default() },
7018                        ..Default::default()
7019                    },
7020                    stretch::style::Node {
7021                        size: stretch::geometry::Size {
7022                            width: stretch::style::Dimension::Points(50.0000),
7023                            height: stretch::style::Dimension::Points(50.0000),
7024                            ..Default::default()
7025                        },
7026                        ..Default::default()
7027                    },
7028                ],
7029                ..Default::default()
7030            },
7031            stretch::geometry::Size::undefined(),
7032        )
7033        .unwrap();
7034
7035        assert_eq!(layout.size.width, 200.0000);
7036        assert_eq!(layout.size.height, 200.0000);
7037        assert_eq!(layout.location.x, 0.0000);
7038        assert_eq!(layout.location.y, 0.0000);
7039
7040        assert_eq!(layout.children[0].size.width, 50.0000);
7041        assert_eq!(layout.children[0].size.height, 50.0000);
7042        assert_eq!(layout.children[0].location.x, 0.0000);
7043        assert_eq!(layout.children[0].location.y, 75.0000);
7044
7045        assert_eq!(layout.children[1].size.width, 50.0000);
7046        assert_eq!(layout.children[1].size.height, 50.0000);
7047        assert_eq!(layout.children[1].location.x, 150.0000);
7048        assert_eq!(layout.children[1].location.y, 75.0000);
7049    }
7050
7051    #[test]
7052    fn wrap_reverse_row_align_content_center() {
7053        let layout = stretch::compute(
7054            &stretch::style::Node {
7055                flex_wrap: stretch::style::FlexWrap::WrapReverse,
7056                align_content: stretch::style::AlignContent::Center,
7057                size: stretch::geometry::Size {
7058                    width: stretch::style::Dimension::Points(100.0000),
7059                    ..Default::default()
7060                },
7061                children: vec![
7062                    stretch::style::Node {
7063                        size: stretch::geometry::Size {
7064                            width: stretch::style::Dimension::Points(30.0000),
7065                            height: stretch::style::Dimension::Points(10.0000),
7066                            ..Default::default()
7067                        },
7068                        ..Default::default()
7069                    },
7070                    stretch::style::Node {
7071                        size: stretch::geometry::Size {
7072                            width: stretch::style::Dimension::Points(30.0000),
7073                            height: stretch::style::Dimension::Points(20.0000),
7074                            ..Default::default()
7075                        },
7076                        ..Default::default()
7077                    },
7078                    stretch::style::Node {
7079                        size: stretch::geometry::Size {
7080                            width: stretch::style::Dimension::Points(30.0000),
7081                            height: stretch::style::Dimension::Points(30.0000),
7082                            ..Default::default()
7083                        },
7084                        ..Default::default()
7085                    },
7086                    stretch::style::Node {
7087                        size: stretch::geometry::Size {
7088                            width: stretch::style::Dimension::Points(30.0000),
7089                            height: stretch::style::Dimension::Points(40.0000),
7090                            ..Default::default()
7091                        },
7092                        ..Default::default()
7093                    },
7094                    stretch::style::Node {
7095                        size: stretch::geometry::Size {
7096                            width: stretch::style::Dimension::Points(30.0000),
7097                            height: stretch::style::Dimension::Points(50.0000),
7098                            ..Default::default()
7099                        },
7100                        ..Default::default()
7101                    },
7102                ],
7103                ..Default::default()
7104            },
7105            stretch::geometry::Size::undefined(),
7106        )
7107        .unwrap();
7108
7109        assert_eq!(layout.size.width, 100.0000);
7110        assert_eq!(layout.size.height, 80.0000);
7111        assert_eq!(layout.location.x, 0.0000);
7112        assert_eq!(layout.location.y, 0.0000);
7113
7114        assert_eq!(layout.children[0].size.width, 30.0000);
7115        assert_eq!(layout.children[0].size.height, 10.0000);
7116        assert_eq!(layout.children[0].location.x, 0.0000);
7117        assert_eq!(layout.children[0].location.y, 70.0000);
7118
7119        assert_eq!(layout.children[1].size.width, 30.0000);
7120        assert_eq!(layout.children[1].size.height, 20.0000);
7121        assert_eq!(layout.children[1].location.x, 30.0000);
7122        assert_eq!(layout.children[1].location.y, 60.0000);
7123
7124        assert_eq!(layout.children[2].size.width, 30.0000);
7125        assert_eq!(layout.children[2].size.height, 30.0000);
7126        assert_eq!(layout.children[2].location.x, 60.0000);
7127        assert_eq!(layout.children[2].location.y, 50.0000);
7128
7129        assert_eq!(layout.children[3].size.width, 30.0000);
7130        assert_eq!(layout.children[3].size.height, 40.0000);
7131        assert_eq!(layout.children[3].location.x, 0.0000);
7132        assert_eq!(layout.children[3].location.y, 10.0000);
7133
7134        assert_eq!(layout.children[4].size.width, 30.0000);
7135        assert_eq!(layout.children[4].size.height, 50.0000);
7136        assert_eq!(layout.children[4].location.x, 30.0000);
7137        assert_eq!(layout.children[4].location.y, 0.0000);
7138    }
7139
7140    #[test]
7141    fn padding_no_child() {
7142        let layout = stretch::compute(
7143            &stretch::style::Node {
7144                padding: stretch::geometry::Rect {
7145                    start: stretch::style::Dimension::Points(10.0000),
7146                    end: stretch::style::Dimension::Points(10.0000),
7147                    top: stretch::style::Dimension::Points(10.0000),
7148                    bottom: stretch::style::Dimension::Points(10.0000),
7149                    ..Default::default()
7150                },
7151                ..Default::default()
7152            },
7153            stretch::geometry::Size::undefined(),
7154        )
7155        .unwrap();
7156
7157        assert_eq!(layout.size.width, 20.0000);
7158        assert_eq!(layout.size.height, 20.0000);
7159        assert_eq!(layout.location.x, 0.0000);
7160        assert_eq!(layout.location.y, 0.0000);
7161    }
7162
7163    #[test]
7164    fn margin_with_sibling_column() {
7165        let layout = stretch::compute(
7166            &stretch::style::Node {
7167                flex_direction: stretch::style::FlexDirection::Column,
7168                size: stretch::geometry::Size {
7169                    width: stretch::style::Dimension::Points(100.0000),
7170                    height: stretch::style::Dimension::Points(100.0000),
7171                    ..Default::default()
7172                },
7173                children: vec![
7174                    stretch::style::Node {
7175                        flex_grow: 1.0000,
7176                        margin: stretch::geometry::Rect {
7177                            bottom: stretch::style::Dimension::Points(10.0000),
7178                            ..Default::default()
7179                        },
7180                        ..Default::default()
7181                    },
7182                    stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
7183                ],
7184                ..Default::default()
7185            },
7186            stretch::geometry::Size::undefined(),
7187        )
7188        .unwrap();
7189
7190        assert_eq!(layout.size.width, 100.0000);
7191        assert_eq!(layout.size.height, 100.0000);
7192        assert_eq!(layout.location.x, 0.0000);
7193        assert_eq!(layout.location.y, 0.0000);
7194
7195        assert_eq!(layout.children[0].size.width, 100.0000);
7196        assert_eq!(layout.children[0].size.height, 45.0000);
7197        assert_eq!(layout.children[0].location.x, 0.0000);
7198        assert_eq!(layout.children[0].location.y, 0.0000);
7199
7200        assert_eq!(layout.children[1].size.width, 100.0000);
7201        assert_eq!(layout.children[1].size.height, 45.0000);
7202        assert_eq!(layout.children[1].location.x, 0.0000);
7203        assert_eq!(layout.children[1].location.y, 55.0000);
7204    }
7205
7206    #[test]
7207    fn flex_direction_row_no_width() {
7208        let layout = stretch::compute(
7209            &stretch::style::Node {
7210                size: stretch::geometry::Size {
7211                    height: stretch::style::Dimension::Points(100.0000),
7212                    ..Default::default()
7213                },
7214                children: vec![
7215                    stretch::style::Node {
7216                        size: stretch::geometry::Size {
7217                            width: stretch::style::Dimension::Points(10.0000),
7218                            ..Default::default()
7219                        },
7220                        ..Default::default()
7221                    },
7222                    stretch::style::Node {
7223                        size: stretch::geometry::Size {
7224                            width: stretch::style::Dimension::Points(10.0000),
7225                            ..Default::default()
7226                        },
7227                        ..Default::default()
7228                    },
7229                    stretch::style::Node {
7230                        size: stretch::geometry::Size {
7231                            width: stretch::style::Dimension::Points(10.0000),
7232                            ..Default::default()
7233                        },
7234                        ..Default::default()
7235                    },
7236                ],
7237                ..Default::default()
7238            },
7239            stretch::geometry::Size::undefined(),
7240        )
7241        .unwrap();
7242
7243        assert_eq!(layout.size.width, 30.0000);
7244        assert_eq!(layout.size.height, 100.0000);
7245        assert_eq!(layout.location.x, 0.0000);
7246        assert_eq!(layout.location.y, 0.0000);
7247
7248        assert_eq!(layout.children[0].size.width, 10.0000);
7249        assert_eq!(layout.children[0].size.height, 100.0000);
7250        assert_eq!(layout.children[0].location.x, 0.0000);
7251        assert_eq!(layout.children[0].location.y, 0.0000);
7252
7253        assert_eq!(layout.children[1].size.width, 10.0000);
7254        assert_eq!(layout.children[1].size.height, 100.0000);
7255        assert_eq!(layout.children[1].location.x, 10.0000);
7256        assert_eq!(layout.children[1].location.y, 0.0000);
7257
7258        assert_eq!(layout.children[2].size.width, 10.0000);
7259        assert_eq!(layout.children[2].size.height, 100.0000);
7260        assert_eq!(layout.children[2].location.x, 20.0000);
7261        assert_eq!(layout.children[2].location.y, 0.0000);
7262    }
7263
7264    #[test]
7265    fn max_width_overrides_width_on_root() {
7266        let layout = stretch::compute(
7267            &stretch::style::Node {
7268                size: stretch::geometry::Size {
7269                    width: stretch::style::Dimension::Points(200.0000),
7270                    ..Default::default()
7271                },
7272                max_size: stretch::geometry::Size {
7273                    width: stretch::style::Dimension::Points(100.0000),
7274                    ..Default::default()
7275                },
7276                ..Default::default()
7277            },
7278            stretch::geometry::Size::undefined(),
7279        )
7280        .unwrap();
7281
7282        assert_eq!(layout.size.width, 100.0000);
7283        assert_eq!(layout.size.height, 0.0000);
7284        assert_eq!(layout.location.x, 0.0000);
7285        assert_eq!(layout.location.y, 0.0000);
7286    }
7287
7288    #[test]
7289    fn margin_auto_left_and_right() {
7290        let layout = stretch::compute(
7291            &stretch::style::Node {
7292                size: stretch::geometry::Size {
7293                    width: stretch::style::Dimension::Points(200.0000),
7294                    height: stretch::style::Dimension::Points(200.0000),
7295                    ..Default::default()
7296                },
7297                children: vec![
7298                    stretch::style::Node {
7299                        size: stretch::geometry::Size {
7300                            width: stretch::style::Dimension::Points(50.0000),
7301                            height: stretch::style::Dimension::Points(50.0000),
7302                            ..Default::default()
7303                        },
7304                        margin: stretch::geometry::Rect {
7305                            start: stretch::style::Dimension::Auto,
7306                            end: stretch::style::Dimension::Auto,
7307                            ..Default::default()
7308                        },
7309                        ..Default::default()
7310                    },
7311                    stretch::style::Node {
7312                        size: stretch::geometry::Size {
7313                            width: stretch::style::Dimension::Points(50.0000),
7314                            height: stretch::style::Dimension::Points(50.0000),
7315                            ..Default::default()
7316                        },
7317                        ..Default::default()
7318                    },
7319                ],
7320                ..Default::default()
7321            },
7322            stretch::geometry::Size::undefined(),
7323        )
7324        .unwrap();
7325
7326        assert_eq!(layout.size.width, 200.0000);
7327        assert_eq!(layout.size.height, 200.0000);
7328        assert_eq!(layout.location.x, 0.0000);
7329        assert_eq!(layout.location.y, 0.0000);
7330
7331        assert_eq!(layout.children[0].size.width, 50.0000);
7332        assert_eq!(layout.children[0].size.height, 50.0000);
7333        assert_eq!(layout.children[0].location.x, 50.0000);
7334        assert_eq!(layout.children[0].location.y, 0.0000);
7335
7336        assert_eq!(layout.children[1].size.width, 50.0000);
7337        assert_eq!(layout.children[1].size.height, 50.0000);
7338        assert_eq!(layout.children[1].location.x, 150.0000);
7339        assert_eq!(layout.children[1].location.y, 0.0000);
7340    }
7341
7342    #[test]
7343    fn flex_direction_column_no_height() {
7344        let layout = stretch::compute(
7345            &stretch::style::Node {
7346                flex_direction: stretch::style::FlexDirection::Column,
7347                size: stretch::geometry::Size {
7348                    width: stretch::style::Dimension::Points(100.0000),
7349                    ..Default::default()
7350                },
7351                children: vec![
7352                    stretch::style::Node {
7353                        size: stretch::geometry::Size {
7354                            height: stretch::style::Dimension::Points(10.0000),
7355                            ..Default::default()
7356                        },
7357                        ..Default::default()
7358                    },
7359                    stretch::style::Node {
7360                        size: stretch::geometry::Size {
7361                            height: stretch::style::Dimension::Points(10.0000),
7362                            ..Default::default()
7363                        },
7364                        ..Default::default()
7365                    },
7366                    stretch::style::Node {
7367                        size: stretch::geometry::Size {
7368                            height: stretch::style::Dimension::Points(10.0000),
7369                            ..Default::default()
7370                        },
7371                        ..Default::default()
7372                    },
7373                ],
7374                ..Default::default()
7375            },
7376            stretch::geometry::Size::undefined(),
7377        )
7378        .unwrap();
7379
7380        assert_eq!(layout.size.width, 100.0000);
7381        assert_eq!(layout.size.height, 30.0000);
7382        assert_eq!(layout.location.x, 0.0000);
7383        assert_eq!(layout.location.y, 0.0000);
7384
7385        assert_eq!(layout.children[0].size.width, 100.0000);
7386        assert_eq!(layout.children[0].size.height, 10.0000);
7387        assert_eq!(layout.children[0].location.x, 0.0000);
7388        assert_eq!(layout.children[0].location.y, 0.0000);
7389
7390        assert_eq!(layout.children[1].size.width, 100.0000);
7391        assert_eq!(layout.children[1].size.height, 10.0000);
7392        assert_eq!(layout.children[1].location.x, 0.0000);
7393        assert_eq!(layout.children[1].location.y, 10.0000);
7394
7395        assert_eq!(layout.children[2].size.width, 100.0000);
7396        assert_eq!(layout.children[2].size.height, 10.0000);
7397        assert_eq!(layout.children[2].location.x, 0.0000);
7398        assert_eq!(layout.children[2].location.y, 20.0000);
7399    }
7400
7401    #[test]
7402    fn flex_basis_unconstraint_column() {
7403        let layout = stretch::compute(
7404            &stretch::style::Node {
7405                flex_direction: stretch::style::FlexDirection::Column,
7406                children: vec![stretch::style::Node {
7407                    flex_basis: stretch::style::Dimension::Points(50.0000),
7408                    size: stretch::geometry::Size {
7409                        width: stretch::style::Dimension::Points(100.0000),
7410                        ..Default::default()
7411                    },
7412                    ..Default::default()
7413                }],
7414                ..Default::default()
7415            },
7416            stretch::geometry::Size::undefined(),
7417        )
7418        .unwrap();
7419
7420        assert_eq!(layout.size.width, 100.0000);
7421        assert_eq!(layout.size.height, 50.0000);
7422        assert_eq!(layout.location.x, 0.0000);
7423        assert_eq!(layout.location.y, 0.0000);
7424
7425        assert_eq!(layout.children[0].size.width, 100.0000);
7426        assert_eq!(layout.children[0].size.height, 50.0000);
7427        assert_eq!(layout.children[0].location.x, 0.0000);
7428        assert_eq!(layout.children[0].location.y, 0.0000);
7429    }
7430
7431    #[test]
7432    fn width_smaller_then_content_with_flex_grow_small_size() {
7433        let layout = stretch::compute(
7434            &stretch::style::Node {
7435                size: stretch::geometry::Size {
7436                    width: stretch::style::Dimension::Points(10.0000),
7437                    ..Default::default()
7438                },
7439                children: vec![
7440                    stretch::style::Node {
7441                        flex_direction: stretch::style::FlexDirection::Column,
7442                        flex_grow: 1.0000,
7443                        size: stretch::geometry::Size {
7444                            width: stretch::style::Dimension::Points(0.0000),
7445                            ..Default::default()
7446                        },
7447                        children: vec![stretch::style::Node {
7448                            size: stretch::geometry::Size {
7449                                width: stretch::style::Dimension::Points(70.0000),
7450                                height: stretch::style::Dimension::Points(100.0000),
7451                                ..Default::default()
7452                            },
7453                            ..Default::default()
7454                        }],
7455                        ..Default::default()
7456                    },
7457                    stretch::style::Node {
7458                        flex_direction: stretch::style::FlexDirection::Column,
7459                        flex_grow: 1.0000,
7460                        size: stretch::geometry::Size {
7461                            width: stretch::style::Dimension::Points(0.0000),
7462                            ..Default::default()
7463                        },
7464                        children: vec![stretch::style::Node {
7465                            size: stretch::geometry::Size {
7466                                width: stretch::style::Dimension::Points(20.0000),
7467                                height: stretch::style::Dimension::Points(100.0000),
7468                                ..Default::default()
7469                            },
7470                            ..Default::default()
7471                        }],
7472                        ..Default::default()
7473                    },
7474                ],
7475                ..Default::default()
7476            },
7477            stretch::geometry::Size::undefined(),
7478        )
7479        .unwrap();
7480
7481        assert_eq!(layout.size.width, 10.0000);
7482        assert_eq!(layout.size.height, 100.0000);
7483        assert_eq!(layout.location.x, 0.0000);
7484        assert_eq!(layout.location.y, 0.0000);
7485
7486        assert_eq!(layout.children[0].size.width, 5.0000);
7487        assert_eq!(layout.children[0].size.height, 100.0000);
7488        assert_eq!(layout.children[0].location.x, 0.0000);
7489        assert_eq!(layout.children[0].location.y, 0.0000);
7490
7491        assert_eq!(layout.children[0].children[0].size.width, 70.0000);
7492        assert_eq!(layout.children[0].children[0].size.height, 100.0000);
7493        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
7494        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
7495
7496        assert_eq!(layout.children[1].size.width, 5.0000);
7497        assert_eq!(layout.children[1].size.height, 100.0000);
7498        assert_eq!(layout.children[1].location.x, 5.0000);
7499        assert_eq!(layout.children[1].location.y, 0.0000);
7500
7501        assert_eq!(layout.children[1].children[0].size.width, 20.0000);
7502        assert_eq!(layout.children[1].children[0].size.height, 100.0000);
7503        assert_eq!(layout.children[1].children[0].location.x, 0.0000);
7504        assert_eq!(layout.children[1].children[0].location.y, 0.0000);
7505    }
7506
7507    #[test]
7508    fn absolute_layout_in_wrap_reverse_row_container() {
7509        let layout = stretch::compute(
7510            &stretch::style::Node {
7511                flex_wrap: stretch::style::FlexWrap::WrapReverse,
7512                size: stretch::geometry::Size {
7513                    width: stretch::style::Dimension::Points(100.0000),
7514                    height: stretch::style::Dimension::Points(100.0000),
7515                    ..Default::default()
7516                },
7517                children: vec![stretch::style::Node {
7518                    position_type: stretch::style::PositionType::Absolute,
7519                    size: stretch::geometry::Size {
7520                        width: stretch::style::Dimension::Points(20.0000),
7521                        height: stretch::style::Dimension::Points(20.0000),
7522                        ..Default::default()
7523                    },
7524                    ..Default::default()
7525                }],
7526                ..Default::default()
7527            },
7528            stretch::geometry::Size::undefined(),
7529        )
7530        .unwrap();
7531
7532        assert_eq!(layout.size.width, 100.0000);
7533        assert_eq!(layout.size.height, 100.0000);
7534        assert_eq!(layout.location.x, 0.0000);
7535        assert_eq!(layout.location.y, 0.0000);
7536
7537        assert_eq!(layout.children[0].size.width, 20.0000);
7538        assert_eq!(layout.children[0].size.height, 20.0000);
7539        assert_eq!(layout.children[0].location.x, 0.0000);
7540        assert_eq!(layout.children[0].location.y, 80.0000);
7541    }
7542
7543    #[test]
7544    fn flex_basis_and_main_dimen_set_when_flexing() {
7545        let layout = stretch::compute(
7546            &stretch::style::Node {
7547                size: stretch::geometry::Size {
7548                    width: stretch::style::Dimension::Points(100.0000),
7549                    ..Default::default()
7550                },
7551                children: vec![
7552                    stretch::style::Node {
7553                        flex_grow: 1.0000,
7554                        flex_basis: stretch::style::Dimension::Points(10.0000),
7555                        size: stretch::geometry::Size {
7556                            width: stretch::style::Dimension::Points(50.0000),
7557                            height: stretch::style::Dimension::Points(50.0000),
7558                            ..Default::default()
7559                        },
7560                        ..Default::default()
7561                    },
7562                    stretch::style::Node {
7563                        flex_grow: 1.0000,
7564                        flex_basis: stretch::style::Dimension::Points(10.0000),
7565                        size: stretch::geometry::Size {
7566                            width: stretch::style::Dimension::Points(0.0000),
7567                            height: stretch::style::Dimension::Points(50.0000),
7568                            ..Default::default()
7569                        },
7570                        ..Default::default()
7571                    },
7572                ],
7573                ..Default::default()
7574            },
7575            stretch::geometry::Size::undefined(),
7576        )
7577        .unwrap();
7578
7579        assert_eq!(layout.size.width, 100.0000);
7580        assert_eq!(layout.size.height, 50.0000);
7581        assert_eq!(layout.location.x, 0.0000);
7582        assert_eq!(layout.location.y, 0.0000);
7583
7584        assert_eq!(layout.children[0].size.width, 50.0000);
7585        assert_eq!(layout.children[0].size.height, 50.0000);
7586        assert_eq!(layout.children[0].location.x, 0.0000);
7587        assert_eq!(layout.children[0].location.y, 0.0000);
7588
7589        assert_eq!(layout.children[1].size.width, 50.0000);
7590        assert_eq!(layout.children[1].size.height, 50.0000);
7591        assert_eq!(layout.children[1].location.x, 50.0000);
7592        assert_eq!(layout.children[1].location.y, 0.0000);
7593    }
7594
7595    #[test]
7596    fn flex_basis_smaller_than_main_dimen_column() {
7597        let layout = stretch::compute(
7598            &stretch::style::Node {
7599                flex_direction: stretch::style::FlexDirection::Column,
7600                size: stretch::geometry::Size {
7601                    height: stretch::style::Dimension::Points(100.0000),
7602                    ..Default::default()
7603                },
7604                children: vec![stretch::style::Node {
7605                    flex_basis: stretch::style::Dimension::Points(10.0000),
7606                    size: stretch::geometry::Size {
7607                        width: stretch::style::Dimension::Points(50.0000),
7608                        height: stretch::style::Dimension::Points(50.0000),
7609                        ..Default::default()
7610                    },
7611                    ..Default::default()
7612                }],
7613                ..Default::default()
7614            },
7615            stretch::geometry::Size::undefined(),
7616        )
7617        .unwrap();
7618
7619        assert_eq!(layout.size.width, 50.0000);
7620        assert_eq!(layout.size.height, 100.0000);
7621        assert_eq!(layout.location.x, 0.0000);
7622        assert_eq!(layout.location.y, 0.0000);
7623
7624        assert_eq!(layout.children[0].size.width, 50.0000);
7625        assert_eq!(layout.children[0].size.height, 10.0000);
7626        assert_eq!(layout.children[0].location.x, 0.0000);
7627        assert_eq!(layout.children[0].location.y, 0.0000);
7628    }
7629
7630    #[test]
7631    fn percentage_margin_should_calculate_based_only_on_width() {
7632        let layout = stretch::compute(
7633            &stretch::style::Node {
7634                flex_direction: stretch::style::FlexDirection::Column,
7635                size: stretch::geometry::Size {
7636                    width: stretch::style::Dimension::Points(200.0000),
7637                    height: stretch::style::Dimension::Points(100.0000),
7638                    ..Default::default()
7639                },
7640                children: vec![stretch::style::Node {
7641                    flex_direction: stretch::style::FlexDirection::Column,
7642                    flex_grow: 1.0000,
7643                    margin: stretch::geometry::Rect {
7644                        start: stretch::style::Dimension::Percent(0.1000),
7645                        end: stretch::style::Dimension::Percent(0.1000),
7646                        top: stretch::style::Dimension::Percent(0.1000),
7647                        bottom: stretch::style::Dimension::Percent(0.1000),
7648                        ..Default::default()
7649                    },
7650                    children: vec![stretch::style::Node {
7651                        size: stretch::geometry::Size {
7652                            width: stretch::style::Dimension::Points(10.0000),
7653                            height: stretch::style::Dimension::Points(10.0000),
7654                            ..Default::default()
7655                        },
7656                        ..Default::default()
7657                    }],
7658                    ..Default::default()
7659                }],
7660                ..Default::default()
7661            },
7662            stretch::geometry::Size::undefined(),
7663        )
7664        .unwrap();
7665
7666        assert_eq!(layout.size.width, 200.0000);
7667        assert_eq!(layout.size.height, 100.0000);
7668        assert_eq!(layout.location.x, 0.0000);
7669        assert_eq!(layout.location.y, 0.0000);
7670
7671        assert_eq!(layout.children[0].size.width, 160.0000);
7672        assert_eq!(layout.children[0].size.height, 60.0000);
7673        assert_eq!(layout.children[0].location.x, 20.0000);
7674        assert_eq!(layout.children[0].location.y, 20.0000);
7675
7676        assert_eq!(layout.children[0].children[0].size.width, 10.0000);
7677        assert_eq!(layout.children[0].children[0].size.height, 10.0000);
7678        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
7679        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
7680    }
7681
7682    #[test]
7683    fn absolute_layout_start_top_end_bottom() {
7684        let layout = stretch::compute(
7685            &stretch::style::Node {
7686                size: stretch::geometry::Size {
7687                    width: stretch::style::Dimension::Points(100.0000),
7688                    height: stretch::style::Dimension::Points(100.0000),
7689                    ..Default::default()
7690                },
7691                children: vec![stretch::style::Node {
7692                    position_type: stretch::style::PositionType::Absolute,
7693                    position: stretch::geometry::Rect {
7694                        start: stretch::style::Dimension::Points(10.0000),
7695                        end: stretch::style::Dimension::Points(10.0000),
7696                        top: stretch::style::Dimension::Points(10.0000),
7697                        bottom: stretch::style::Dimension::Points(10.0000),
7698                        ..Default::default()
7699                    },
7700                    ..Default::default()
7701                }],
7702                ..Default::default()
7703            },
7704            stretch::geometry::Size::undefined(),
7705        )
7706        .unwrap();
7707
7708        assert_eq!(layout.size.width, 100.0000);
7709        assert_eq!(layout.size.height, 100.0000);
7710        assert_eq!(layout.location.x, 0.0000);
7711        assert_eq!(layout.location.y, 0.0000);
7712
7713        assert_eq!(layout.children[0].size.width, 80.0000);
7714        assert_eq!(layout.children[0].size.height, 80.0000);
7715        assert_eq!(layout.children[0].location.x, 10.0000);
7716        assert_eq!(layout.children[0].location.y, 10.0000);
7717    }
7718
7719    #[test]
7720    fn min_width() {
7721        let layout = stretch::compute(
7722            &stretch::style::Node {
7723                size: stretch::geometry::Size {
7724                    width: stretch::style::Dimension::Points(100.0000),
7725                    height: stretch::style::Dimension::Points(100.0000),
7726                    ..Default::default()
7727                },
7728                children: vec![
7729                    stretch::style::Node {
7730                        flex_grow: 1.0000,
7731                        min_size: stretch::geometry::Size {
7732                            width: stretch::style::Dimension::Points(60.0000),
7733                            ..Default::default()
7734                        },
7735                        ..Default::default()
7736                    },
7737                    stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
7738                ],
7739                ..Default::default()
7740            },
7741            stretch::geometry::Size::undefined(),
7742        )
7743        .unwrap();
7744
7745        assert_eq!(layout.size.width, 100.0000);
7746        assert_eq!(layout.size.height, 100.0000);
7747        assert_eq!(layout.location.x, 0.0000);
7748        assert_eq!(layout.location.y, 0.0000);
7749
7750        assert_eq!(layout.children[0].size.width, 80.0000);
7751        assert_eq!(layout.children[0].size.height, 100.0000);
7752        assert_eq!(layout.children[0].location.x, 0.0000);
7753        assert_eq!(layout.children[0].location.y, 0.0000);
7754
7755        assert_eq!(layout.children[1].size.width, 20.0000);
7756        assert_eq!(layout.children[1].size.height, 100.0000);
7757        assert_eq!(layout.children[1].location.x, 80.0000);
7758        assert_eq!(layout.children[1].location.y, 0.0000);
7759    }
7760
7761    #[test]
7762    fn min_height_overrides_height_on_root() {
7763        let layout = stretch::compute(
7764            &stretch::style::Node {
7765                size: stretch::geometry::Size {
7766                    height: stretch::style::Dimension::Points(50.0000),
7767                    ..Default::default()
7768                },
7769                min_size: stretch::geometry::Size {
7770                    height: stretch::style::Dimension::Points(100.0000),
7771                    ..Default::default()
7772                },
7773                ..Default::default()
7774            },
7775            stretch::geometry::Size::undefined(),
7776        )
7777        .unwrap();
7778
7779        assert_eq!(layout.size.width, 0.0000);
7780        assert_eq!(layout.size.height, 100.0000);
7781        assert_eq!(layout.location.x, 0.0000);
7782        assert_eq!(layout.location.y, 0.0000);
7783    }
7784
7785    #[test]
7786    fn absolute_layout_width_height_end_bottom() {
7787        let layout = stretch::compute(
7788            &stretch::style::Node {
7789                size: stretch::geometry::Size {
7790                    width: stretch::style::Dimension::Points(100.0000),
7791                    height: stretch::style::Dimension::Points(100.0000),
7792                    ..Default::default()
7793                },
7794                children: vec![stretch::style::Node {
7795                    position_type: stretch::style::PositionType::Absolute,
7796                    size: stretch::geometry::Size {
7797                        width: stretch::style::Dimension::Points(10.0000),
7798                        height: stretch::style::Dimension::Points(10.0000),
7799                        ..Default::default()
7800                    },
7801                    position: stretch::geometry::Rect {
7802                        end: stretch::style::Dimension::Points(10.0000),
7803                        bottom: stretch::style::Dimension::Points(10.0000),
7804                        ..Default::default()
7805                    },
7806                    ..Default::default()
7807                }],
7808                ..Default::default()
7809            },
7810            stretch::geometry::Size::undefined(),
7811        )
7812        .unwrap();
7813
7814        assert_eq!(layout.size.width, 100.0000);
7815        assert_eq!(layout.size.height, 100.0000);
7816        assert_eq!(layout.location.x, 0.0000);
7817        assert_eq!(layout.location.y, 0.0000);
7818
7819        assert_eq!(layout.children[0].size.width, 10.0000);
7820        assert_eq!(layout.children[0].size.height, 10.0000);
7821        assert_eq!(layout.children[0].location.x, 80.0000);
7822        assert_eq!(layout.children[0].location.y, 80.0000);
7823    }
7824
7825    #[test]
7826    fn align_self_center() {
7827        let layout = stretch::compute(
7828            &stretch::style::Node {
7829                size: stretch::geometry::Size {
7830                    width: stretch::style::Dimension::Points(100.0000),
7831                    height: stretch::style::Dimension::Points(100.0000),
7832                    ..Default::default()
7833                },
7834                children: vec![stretch::style::Node {
7835                    align_self: stretch::style::AlignSelf::Center,
7836                    size: stretch::geometry::Size {
7837                        width: stretch::style::Dimension::Points(10.0000),
7838                        height: stretch::style::Dimension::Points(10.0000),
7839                        ..Default::default()
7840                    },
7841                    ..Default::default()
7842                }],
7843                ..Default::default()
7844            },
7845            stretch::geometry::Size::undefined(),
7846        )
7847        .unwrap();
7848
7849        assert_eq!(layout.size.width, 100.0000);
7850        assert_eq!(layout.size.height, 100.0000);
7851        assert_eq!(layout.location.x, 0.0000);
7852        assert_eq!(layout.location.y, 0.0000);
7853
7854        assert_eq!(layout.children[0].size.width, 10.0000);
7855        assert_eq!(layout.children[0].size.height, 10.0000);
7856        assert_eq!(layout.children[0].location.x, 0.0000);
7857        assert_eq!(layout.children[0].location.y, 45.0000);
7858    }
7859
7860    #[test]
7861    fn wrapped_column_max_height() {
7862        let layout = stretch::compute(
7863            &stretch::style::Node {
7864                flex_direction: stretch::style::FlexDirection::Column,
7865                flex_wrap: stretch::style::FlexWrap::Wrap,
7866                align_items: stretch::style::AlignItems::Center,
7867                align_content: stretch::style::AlignContent::Center,
7868                justify_content: stretch::style::JustifyContent::Center,
7869                size: stretch::geometry::Size {
7870                    width: stretch::style::Dimension::Points(700.0000),
7871                    height: stretch::style::Dimension::Points(500.0000),
7872                    ..Default::default()
7873                },
7874                children: vec![
7875                    stretch::style::Node {
7876                        size: stretch::geometry::Size {
7877                            width: stretch::style::Dimension::Points(100.0000),
7878                            height: stretch::style::Dimension::Points(500.0000),
7879                            ..Default::default()
7880                        },
7881                        max_size: stretch::geometry::Size {
7882                            height: stretch::style::Dimension::Points(200.0000),
7883                            ..Default::default()
7884                        },
7885                        ..Default::default()
7886                    },
7887                    stretch::style::Node {
7888                        size: stretch::geometry::Size {
7889                            width: stretch::style::Dimension::Points(200.0000),
7890                            height: stretch::style::Dimension::Points(200.0000),
7891                            ..Default::default()
7892                        },
7893                        margin: stretch::geometry::Rect {
7894                            start: stretch::style::Dimension::Points(20.0000),
7895                            end: stretch::style::Dimension::Points(20.0000),
7896                            top: stretch::style::Dimension::Points(20.0000),
7897                            bottom: stretch::style::Dimension::Points(20.0000),
7898                            ..Default::default()
7899                        },
7900                        ..Default::default()
7901                    },
7902                    stretch::style::Node {
7903                        size: stretch::geometry::Size {
7904                            width: stretch::style::Dimension::Points(100.0000),
7905                            height: stretch::style::Dimension::Points(100.0000),
7906                            ..Default::default()
7907                        },
7908                        ..Default::default()
7909                    },
7910                ],
7911                ..Default::default()
7912            },
7913            stretch::geometry::Size::undefined(),
7914        )
7915        .unwrap();
7916
7917        assert_eq!(layout.size.width, 700.0000);
7918        assert_eq!(layout.size.height, 500.0000);
7919        assert_eq!(layout.location.x, 0.0000);
7920        assert_eq!(layout.location.y, 0.0000);
7921
7922        assert_eq!(layout.children[0].size.width, 100.0000);
7923        assert_eq!(layout.children[0].size.height, 200.0000);
7924        assert_eq!(layout.children[0].location.x, 250.0000);
7925        assert_eq!(layout.children[0].location.y, 30.0000);
7926
7927        assert_eq!(layout.children[1].size.width, 200.0000);
7928        assert_eq!(layout.children[1].size.height, 200.0000);
7929        assert_eq!(layout.children[1].location.x, 200.0000);
7930        assert_eq!(layout.children[1].location.y, 250.0000);
7931
7932        assert_eq!(layout.children[2].size.width, 100.0000);
7933        assert_eq!(layout.children[2].size.height, 100.0000);
7934        assert_eq!(layout.children[2].location.x, 420.0000);
7935        assert_eq!(layout.children[2].location.y, 200.0000);
7936    }
7937
7938    #[test]
7939    fn wrap_row() {
7940        let layout = stretch::compute(
7941            &stretch::style::Node {
7942                flex_wrap: stretch::style::FlexWrap::Wrap,
7943                size: stretch::geometry::Size {
7944                    width: stretch::style::Dimension::Points(100.0000),
7945                    ..Default::default()
7946                },
7947                children: vec![
7948                    stretch::style::Node {
7949                        size: stretch::geometry::Size {
7950                            width: stretch::style::Dimension::Points(31.0000),
7951                            height: stretch::style::Dimension::Points(30.0000),
7952                            ..Default::default()
7953                        },
7954                        ..Default::default()
7955                    },
7956                    stretch::style::Node {
7957                        size: stretch::geometry::Size {
7958                            width: stretch::style::Dimension::Points(32.0000),
7959                            height: stretch::style::Dimension::Points(30.0000),
7960                            ..Default::default()
7961                        },
7962                        ..Default::default()
7963                    },
7964                    stretch::style::Node {
7965                        size: stretch::geometry::Size {
7966                            width: stretch::style::Dimension::Points(33.0000),
7967                            height: stretch::style::Dimension::Points(30.0000),
7968                            ..Default::default()
7969                        },
7970                        ..Default::default()
7971                    },
7972                    stretch::style::Node {
7973                        size: stretch::geometry::Size {
7974                            width: stretch::style::Dimension::Points(34.0000),
7975                            height: stretch::style::Dimension::Points(30.0000),
7976                            ..Default::default()
7977                        },
7978                        ..Default::default()
7979                    },
7980                ],
7981                ..Default::default()
7982            },
7983            stretch::geometry::Size::undefined(),
7984        )
7985        .unwrap();
7986
7987        assert_eq!(layout.size.width, 100.0000);
7988        assert_eq!(layout.size.height, 60.0000);
7989        assert_eq!(layout.location.x, 0.0000);
7990        assert_eq!(layout.location.y, 0.0000);
7991
7992        assert_eq!(layout.children[0].size.width, 31.0000);
7993        assert_eq!(layout.children[0].size.height, 30.0000);
7994        assert_eq!(layout.children[0].location.x, 0.0000);
7995        assert_eq!(layout.children[0].location.y, 0.0000);
7996
7997        assert_eq!(layout.children[1].size.width, 32.0000);
7998        assert_eq!(layout.children[1].size.height, 30.0000);
7999        assert_eq!(layout.children[1].location.x, 31.0000);
8000        assert_eq!(layout.children[1].location.y, 0.0000);
8001
8002        assert_eq!(layout.children[2].size.width, 33.0000);
8003        assert_eq!(layout.children[2].size.height, 30.0000);
8004        assert_eq!(layout.children[2].location.x, 63.0000);
8005        assert_eq!(layout.children[2].location.y, 0.0000);
8006
8007        assert_eq!(layout.children[3].size.width, 34.0000);
8008        assert_eq!(layout.children[3].size.height, 30.0000);
8009        assert_eq!(layout.children[3].location.x, 0.0000);
8010        assert_eq!(layout.children[3].location.y, 30.0000);
8011    }
8012
8013    #[test]
8014    fn max_height() {
8015        let layout = stretch::compute(
8016            &stretch::style::Node {
8017                size: stretch::geometry::Size {
8018                    width: stretch::style::Dimension::Points(100.0000),
8019                    height: stretch::style::Dimension::Points(100.0000),
8020                    ..Default::default()
8021                },
8022                children: vec![stretch::style::Node {
8023                    size: stretch::geometry::Size {
8024                        width: stretch::style::Dimension::Points(10.0000),
8025                        ..Default::default()
8026                    },
8027                    max_size: stretch::geometry::Size {
8028                        height: stretch::style::Dimension::Points(50.0000),
8029                        ..Default::default()
8030                    },
8031                    ..Default::default()
8032                }],
8033                ..Default::default()
8034            },
8035            stretch::geometry::Size::undefined(),
8036        )
8037        .unwrap();
8038
8039        assert_eq!(layout.size.width, 100.0000);
8040        assert_eq!(layout.size.height, 100.0000);
8041        assert_eq!(layout.location.x, 0.0000);
8042        assert_eq!(layout.location.y, 0.0000);
8043
8044        assert_eq!(layout.children[0].size.width, 10.0000);
8045        assert_eq!(layout.children[0].size.height, 50.0000);
8046        assert_eq!(layout.children[0].location.x, 0.0000);
8047        assert_eq!(layout.children[0].location.y, 0.0000);
8048    }
8049
8050    #[test]
8051    fn flex_grow_child() {
8052        let layout = stretch::compute(
8053            &stretch::style::Node {
8054                children: vec![stretch::style::Node {
8055                    flex_grow: 1.0000,
8056                    flex_basis: stretch::style::Dimension::Points(0.0000),
8057                    size: stretch::geometry::Size {
8058                        height: stretch::style::Dimension::Points(100.0000),
8059                        ..Default::default()
8060                    },
8061                    ..Default::default()
8062                }],
8063                ..Default::default()
8064            },
8065            stretch::geometry::Size::undefined(),
8066        )
8067        .unwrap();
8068
8069        assert_eq!(layout.size.width, 0.0000);
8070        assert_eq!(layout.size.height, 100.0000);
8071        assert_eq!(layout.location.x, 0.0000);
8072        assert_eq!(layout.location.y, 0.0000);
8073
8074        assert_eq!(layout.children[0].size.width, 0.0000);
8075        assert_eq!(layout.children[0].size.height, 100.0000);
8076        assert_eq!(layout.children[0].location.x, 0.0000);
8077        assert_eq!(layout.children[0].location.y, 0.0000);
8078    }
8079
8080    #[test]
8081    fn percentage_size_of_flex_basis() {
8082        let layout = stretch::compute(
8083            &stretch::style::Node {
8084                size: stretch::geometry::Size {
8085                    width: stretch::style::Dimension::Points(100.0000),
8086                    ..Default::default()
8087                },
8088                children: vec![stretch::style::Node {
8089                    flex_basis: stretch::style::Dimension::Points(50.0000),
8090                    children: vec![stretch::style::Node {
8091                        size: stretch::geometry::Size {
8092                            width: stretch::style::Dimension::Percent(1.0000),
8093                            height: stretch::style::Dimension::Points(100.0000),
8094                            ..Default::default()
8095                        },
8096                        ..Default::default()
8097                    }],
8098                    ..Default::default()
8099                }],
8100                ..Default::default()
8101            },
8102            stretch::geometry::Size::undefined(),
8103        )
8104        .unwrap();
8105
8106        assert_eq!(layout.size.width, 100.0000);
8107        assert_eq!(layout.size.height, 100.0000);
8108        assert_eq!(layout.location.x, 0.0000);
8109        assert_eq!(layout.location.y, 0.0000);
8110
8111        assert_eq!(layout.children[0].size.width, 50.0000);
8112        assert_eq!(layout.children[0].size.height, 100.0000);
8113        assert_eq!(layout.children[0].location.x, 0.0000);
8114        assert_eq!(layout.children[0].location.y, 0.0000);
8115
8116        assert_eq!(layout.children[0].children[0].size.width, 50.0000);
8117        assert_eq!(layout.children[0].children[0].size.height, 100.0000);
8118        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
8119        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
8120    }
8121
8122    #[test]
8123    fn align_items_flex_end_child_with_margin_bigger_than_parent() {
8124        let layout = stretch::compute(
8125            &stretch::style::Node {
8126                align_items: stretch::style::AlignItems::Center,
8127                justify_content: stretch::style::JustifyContent::Center,
8128                size: stretch::geometry::Size {
8129                    width: stretch::style::Dimension::Points(50.0000),
8130                    height: stretch::style::Dimension::Points(50.0000),
8131                    ..Default::default()
8132                },
8133                children: vec![stretch::style::Node {
8134                    align_items: stretch::style::AlignItems::FlexEnd,
8135                    children: vec![stretch::style::Node {
8136                        size: stretch::geometry::Size {
8137                            width: stretch::style::Dimension::Points(50.0000),
8138                            height: stretch::style::Dimension::Points(50.0000),
8139                            ..Default::default()
8140                        },
8141                        margin: stretch::geometry::Rect {
8142                            start: stretch::style::Dimension::Points(10.0000),
8143                            end: stretch::style::Dimension::Points(10.0000),
8144                            ..Default::default()
8145                        },
8146                        ..Default::default()
8147                    }],
8148                    ..Default::default()
8149                }],
8150                ..Default::default()
8151            },
8152            stretch::geometry::Size::undefined(),
8153        )
8154        .unwrap();
8155
8156        assert_eq!(layout.size.width, 50.0000);
8157        assert_eq!(layout.size.height, 50.0000);
8158        assert_eq!(layout.location.x, 0.0000);
8159        assert_eq!(layout.location.y, 0.0000);
8160
8161        assert_eq!(layout.children[0].size.width, 70.0000);
8162        assert_eq!(layout.children[0].size.height, 50.0000);
8163        assert_eq!(layout.children[0].location.x, -10.0000);
8164        assert_eq!(layout.children[0].location.y, 0.0000);
8165
8166        assert_eq!(layout.children[0].children[0].size.width, 50.0000);
8167        assert_eq!(layout.children[0].children[0].size.height, 50.0000);
8168        assert_eq!(layout.children[0].children[0].location.x, 10.0000);
8169        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
8170    }
8171
8172    #[test]
8173    fn justify_content_row_max_width_and_margin() {
8174        let layout = stretch::compute(
8175            &stretch::style::Node {
8176                justify_content: stretch::style::JustifyContent::Center,
8177                size: stretch::geometry::Size {
8178                    width: stretch::style::Dimension::Points(100.0000),
8179                    ..Default::default()
8180                },
8181                max_size: stretch::geometry::Size {
8182                    width: stretch::style::Dimension::Points(80.0000),
8183                    ..Default::default()
8184                },
8185                children: vec![stretch::style::Node {
8186                    size: stretch::geometry::Size {
8187                        width: stretch::style::Dimension::Points(20.0000),
8188                        height: stretch::style::Dimension::Points(20.0000),
8189                        ..Default::default()
8190                    },
8191                    margin: stretch::geometry::Rect {
8192                        start: stretch::style::Dimension::Points(100.0000),
8193                        ..Default::default()
8194                    },
8195                    ..Default::default()
8196                }],
8197                ..Default::default()
8198            },
8199            stretch::geometry::Size::undefined(),
8200        )
8201        .unwrap();
8202
8203        assert_eq!(layout.size.width, 80.0000);
8204        assert_eq!(layout.size.height, 20.0000);
8205        assert_eq!(layout.location.x, 0.0000);
8206        assert_eq!(layout.location.y, 0.0000);
8207
8208        assert_eq!(layout.children[0].size.width, 0.0000);
8209        assert_eq!(layout.children[0].size.height, 20.0000);
8210        assert_eq!(layout.children[0].location.x, 90.0000);
8211        assert_eq!(layout.children[0].location.y, 0.0000);
8212    }
8213
8214    #[test]
8215    fn margin_left() {
8216        let layout = stretch::compute(
8217            &stretch::style::Node {
8218                size: stretch::geometry::Size {
8219                    width: stretch::style::Dimension::Points(100.0000),
8220                    height: stretch::style::Dimension::Points(100.0000),
8221                    ..Default::default()
8222                },
8223                children: vec![stretch::style::Node {
8224                    size: stretch::geometry::Size {
8225                        width: stretch::style::Dimension::Points(10.0000),
8226                        ..Default::default()
8227                    },
8228                    margin: stretch::geometry::Rect {
8229                        start: stretch::style::Dimension::Points(10.0000),
8230                        ..Default::default()
8231                    },
8232                    ..Default::default()
8233                }],
8234                ..Default::default()
8235            },
8236            stretch::geometry::Size::undefined(),
8237        )
8238        .unwrap();
8239
8240        assert_eq!(layout.size.width, 100.0000);
8241        assert_eq!(layout.size.height, 100.0000);
8242        assert_eq!(layout.location.x, 0.0000);
8243        assert_eq!(layout.location.y, 0.0000);
8244
8245        assert_eq!(layout.children[0].size.width, 10.0000);
8246        assert_eq!(layout.children[0].size.height, 100.0000);
8247        assert_eq!(layout.children[0].location.x, 10.0000);
8248        assert_eq!(layout.children[0].location.y, 0.0000);
8249    }
8250
8251    #[test]
8252    fn size_defined_by_child() {
8253        let layout = stretch::compute(
8254            &stretch::style::Node {
8255                children: vec![stretch::style::Node {
8256                    size: stretch::geometry::Size {
8257                        width: stretch::style::Dimension::Points(100.0000),
8258                        height: stretch::style::Dimension::Points(100.0000),
8259                        ..Default::default()
8260                    },
8261                    ..Default::default()
8262                }],
8263                ..Default::default()
8264            },
8265            stretch::geometry::Size::undefined(),
8266        )
8267        .unwrap();
8268
8269        assert_eq!(layout.size.width, 100.0000);
8270        assert_eq!(layout.size.height, 100.0000);
8271        assert_eq!(layout.location.x, 0.0000);
8272        assert_eq!(layout.location.y, 0.0000);
8273
8274        assert_eq!(layout.children[0].size.width, 100.0000);
8275        assert_eq!(layout.children[0].size.height, 100.0000);
8276        assert_eq!(layout.children[0].location.x, 0.0000);
8277        assert_eq!(layout.children[0].location.y, 0.0000);
8278    }
8279
8280    #[test]
8281    fn rounding_total_fractial_nested() {
8282        let layout = stretch::compute(
8283            &stretch::style::Node {
8284                flex_direction: stretch::style::FlexDirection::Column,
8285                size: stretch::geometry::Size {
8286                    width: stretch::style::Dimension::Points(87.4000),
8287                    height: stretch::style::Dimension::Points(113.4000),
8288                    ..Default::default()
8289                },
8290                children: vec![
8291                    stretch::style::Node {
8292                        flex_direction: stretch::style::FlexDirection::Column,
8293                        flex_grow: 0.7000,
8294                        flex_basis: stretch::style::Dimension::Points(50.3000),
8295                        size: stretch::geometry::Size {
8296                            height: stretch::style::Dimension::Points(20.3000),
8297                            ..Default::default()
8298                        },
8299                        children: vec![
8300                            stretch::style::Node {
8301                                flex_grow: 1.0000,
8302                                flex_basis: stretch::style::Dimension::Points(0.3000),
8303                                size: stretch::geometry::Size {
8304                                    height: stretch::style::Dimension::Points(9.9000),
8305                                    ..Default::default()
8306                                },
8307                                position: stretch::geometry::Rect {
8308                                    bottom: stretch::style::Dimension::Points(13.3000),
8309                                    ..Default::default()
8310                                },
8311                                ..Default::default()
8312                            },
8313                            stretch::style::Node {
8314                                flex_grow: 4.0000,
8315                                flex_basis: stretch::style::Dimension::Points(0.3000),
8316                                size: stretch::geometry::Size {
8317                                    height: stretch::style::Dimension::Points(1.1000),
8318                                    ..Default::default()
8319                                },
8320                                position: stretch::geometry::Rect {
8321                                    top: stretch::style::Dimension::Points(13.3000),
8322                                    ..Default::default()
8323                                },
8324                                ..Default::default()
8325                            },
8326                        ],
8327                        ..Default::default()
8328                    },
8329                    stretch::style::Node {
8330                        flex_grow: 1.6000,
8331                        size: stretch::geometry::Size {
8332                            height: stretch::style::Dimension::Points(10.0000),
8333                            ..Default::default()
8334                        },
8335                        ..Default::default()
8336                    },
8337                    stretch::style::Node {
8338                        flex_grow: 1.1000,
8339                        size: stretch::geometry::Size {
8340                            height: stretch::style::Dimension::Points(10.7000),
8341                            ..Default::default()
8342                        },
8343                        ..Default::default()
8344                    },
8345                ],
8346                ..Default::default()
8347            },
8348            stretch::geometry::Size::undefined(),
8349        )
8350        .unwrap();
8351
8352        assert_eq!(layout.size.width, 87.0000);
8353        assert_eq!(layout.size.height, 113.0000);
8354        assert_eq!(layout.location.x, 0.0000);
8355        assert_eq!(layout.location.y, 0.0000);
8356
8357        assert_eq!(layout.children[0].size.width, 87.0000);
8358        assert_eq!(layout.children[0].size.height, 59.0000);
8359        assert_eq!(layout.children[0].location.x, 0.0000);
8360        assert_eq!(layout.children[0].location.y, 0.0000);
8361
8362        assert_eq!(layout.children[0].children[0].size.width, 87.0000);
8363        assert_eq!(layout.children[0].children[0].size.height, 12.0000);
8364        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
8365        assert_eq!(layout.children[0].children[0].location.y, -13.0000);
8366
8367        assert_eq!(layout.children[0].children[1].size.width, 87.0000);
8368        assert_eq!(layout.children[0].children[1].size.height, 47.0000);
8369        assert_eq!(layout.children[0].children[1].location.x, 0.0000);
8370        assert_eq!(layout.children[0].children[1].location.y, 25.0000);
8371
8372        assert_eq!(layout.children[1].size.width, 87.0000);
8373        assert_eq!(layout.children[1].size.height, 30.0000);
8374        assert_eq!(layout.children[1].location.x, 0.0000);
8375        assert_eq!(layout.children[1].location.y, 59.0000);
8376
8377        assert_eq!(layout.children[2].size.width, 87.0000);
8378        assert_eq!(layout.children[2].size.height, 24.0000);
8379        assert_eq!(layout.children[2].location.x, 0.0000);
8380        assert_eq!(layout.children[2].location.y, 89.0000);
8381    }
8382
8383    #[test]
8384    fn min_max_percent_no_width_height() {
8385        let layout = stretch::compute(
8386            &stretch::style::Node {
8387                flex_direction: stretch::style::FlexDirection::Column,
8388                align_items: stretch::style::AlignItems::FlexStart,
8389                size: stretch::geometry::Size {
8390                    width: stretch::style::Dimension::Points(100.0000),
8391                    height: stretch::style::Dimension::Points(100.0000),
8392                    ..Default::default()
8393                },
8394                children: vec![stretch::style::Node {
8395                    min_size: stretch::geometry::Size {
8396                        width: stretch::style::Dimension::Percent(0.1000),
8397                        height: stretch::style::Dimension::Percent(0.1000),
8398                        ..Default::default()
8399                    },
8400                    max_size: stretch::geometry::Size {
8401                        width: stretch::style::Dimension::Percent(0.1000),
8402                        height: stretch::style::Dimension::Percent(0.1000),
8403                        ..Default::default()
8404                    },
8405                    ..Default::default()
8406                }],
8407                ..Default::default()
8408            },
8409            stretch::geometry::Size::undefined(),
8410        )
8411        .unwrap();
8412
8413        assert_eq!(layout.size.width, 100.0000);
8414        assert_eq!(layout.size.height, 100.0000);
8415        assert_eq!(layout.location.x, 0.0000);
8416        assert_eq!(layout.location.y, 0.0000);
8417
8418        assert_eq!(layout.children[0].size.width, 10.0000);
8419        assert_eq!(layout.children[0].size.height, 10.0000);
8420        assert_eq!(layout.children[0].location.x, 0.0000);
8421        assert_eq!(layout.children[0].location.y, 0.0000);
8422    }
8423
8424    #[test]
8425    fn flex_basis_smaller_then_content_with_flex_grow_very_large_size() {
8426        let layout = stretch::compute(
8427            &stretch::style::Node {
8428                size: stretch::geometry::Size {
8429                    width: stretch::style::Dimension::Points(200.0000),
8430                    ..Default::default()
8431                },
8432                children: vec![
8433                    stretch::style::Node {
8434                        flex_direction: stretch::style::FlexDirection::Column,
8435                        flex_grow: 1.0000,
8436                        flex_basis: stretch::style::Dimension::Points(0.0000),
8437                        children: vec![stretch::style::Node {
8438                            size: stretch::geometry::Size {
8439                                width: stretch::style::Dimension::Points(70.0000),
8440                                height: stretch::style::Dimension::Points(100.0000),
8441                                ..Default::default()
8442                            },
8443                            ..Default::default()
8444                        }],
8445                        ..Default::default()
8446                    },
8447                    stretch::style::Node {
8448                        flex_direction: stretch::style::FlexDirection::Column,
8449                        flex_grow: 1.0000,
8450                        flex_basis: stretch::style::Dimension::Points(0.0000),
8451                        children: vec![stretch::style::Node {
8452                            size: stretch::geometry::Size {
8453                                width: stretch::style::Dimension::Points(20.0000),
8454                                height: stretch::style::Dimension::Points(100.0000),
8455                                ..Default::default()
8456                            },
8457                            ..Default::default()
8458                        }],
8459                        ..Default::default()
8460                    },
8461                ],
8462                ..Default::default()
8463            },
8464            stretch::geometry::Size::undefined(),
8465        )
8466        .unwrap();
8467
8468        assert_eq!(layout.size.width, 200.0000);
8469        assert_eq!(layout.size.height, 100.0000);
8470        assert_eq!(layout.location.x, 0.0000);
8471        assert_eq!(layout.location.y, 0.0000);
8472
8473        assert_eq!(layout.children[0].size.width, 100.0000);
8474        assert_eq!(layout.children[0].size.height, 100.0000);
8475        assert_eq!(layout.children[0].location.x, 0.0000);
8476        assert_eq!(layout.children[0].location.y, 0.0000);
8477
8478        assert_eq!(layout.children[0].children[0].size.width, 70.0000);
8479        assert_eq!(layout.children[0].children[0].size.height, 100.0000);
8480        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
8481        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
8482
8483        assert_eq!(layout.children[1].size.width, 100.0000);
8484        assert_eq!(layout.children[1].size.height, 100.0000);
8485        assert_eq!(layout.children[1].location.x, 100.0000);
8486        assert_eq!(layout.children[1].location.y, 0.0000);
8487
8488        assert_eq!(layout.children[1].children[0].size.width, 20.0000);
8489        assert_eq!(layout.children[1].children[0].size.height, 100.0000);
8490        assert_eq!(layout.children[1].children[0].location.x, 0.0000);
8491        assert_eq!(layout.children[1].children[0].location.y, 0.0000);
8492    }
8493
8494    #[test]
8495    fn percent_within_flex_grow() {
8496        let layout = stretch::compute(
8497            &stretch::style::Node {
8498                size: stretch::geometry::Size {
8499                    width: stretch::style::Dimension::Points(350.0000),
8500                    height: stretch::style::Dimension::Points(100.0000),
8501                    ..Default::default()
8502                },
8503                children: vec![
8504                    stretch::style::Node {
8505                        size: stretch::geometry::Size {
8506                            width: stretch::style::Dimension::Points(100.0000),
8507                            ..Default::default()
8508                        },
8509                        ..Default::default()
8510                    },
8511                    stretch::style::Node {
8512                        flex_direction: stretch::style::FlexDirection::Column,
8513                        flex_grow: 1.0000,
8514                        children: vec![stretch::style::Node {
8515                            size: stretch::geometry::Size {
8516                                width: stretch::style::Dimension::Percent(1.0000),
8517                                ..Default::default()
8518                            },
8519                            ..Default::default()
8520                        }],
8521                        ..Default::default()
8522                    },
8523                    stretch::style::Node {
8524                        size: stretch::geometry::Size {
8525                            width: stretch::style::Dimension::Points(100.0000),
8526                            ..Default::default()
8527                        },
8528                        ..Default::default()
8529                    },
8530                ],
8531                ..Default::default()
8532            },
8533            stretch::geometry::Size::undefined(),
8534        )
8535        .unwrap();
8536
8537        assert_eq!(layout.size.width, 350.0000);
8538        assert_eq!(layout.size.height, 100.0000);
8539        assert_eq!(layout.location.x, 0.0000);
8540        assert_eq!(layout.location.y, 0.0000);
8541
8542        assert_eq!(layout.children[0].size.width, 100.0000);
8543        assert_eq!(layout.children[0].size.height, 100.0000);
8544        assert_eq!(layout.children[0].location.x, 0.0000);
8545        assert_eq!(layout.children[0].location.y, 0.0000);
8546
8547        assert_eq!(layout.children[1].size.width, 150.0000);
8548        assert_eq!(layout.children[1].size.height, 100.0000);
8549        assert_eq!(layout.children[1].location.x, 100.0000);
8550        assert_eq!(layout.children[1].location.y, 0.0000);
8551
8552        assert_eq!(layout.children[1].children[0].size.width, 150.0000);
8553        assert_eq!(layout.children[1].children[0].size.height, 0.0000);
8554        assert_eq!(layout.children[1].children[0].location.x, 0.0000);
8555        assert_eq!(layout.children[1].children[0].location.y, 0.0000);
8556
8557        assert_eq!(layout.children[2].size.width, 100.0000);
8558        assert_eq!(layout.children[2].size.height, 100.0000);
8559        assert_eq!(layout.children[2].location.x, 250.0000);
8560        assert_eq!(layout.children[2].location.y, 0.0000);
8561    }
8562
8563    #[test]
8564    fn margin_and_stretch_row() {
8565        let layout = stretch::compute(
8566            &stretch::style::Node {
8567                size: stretch::geometry::Size {
8568                    width: stretch::style::Dimension::Points(100.0000),
8569                    height: stretch::style::Dimension::Points(100.0000),
8570                    ..Default::default()
8571                },
8572                children: vec![stretch::style::Node {
8573                    flex_grow: 1.0000,
8574                    margin: stretch::geometry::Rect {
8575                        top: stretch::style::Dimension::Points(10.0000),
8576                        bottom: stretch::style::Dimension::Points(10.0000),
8577                        ..Default::default()
8578                    },
8579                    ..Default::default()
8580                }],
8581                ..Default::default()
8582            },
8583            stretch::geometry::Size::undefined(),
8584        )
8585        .unwrap();
8586
8587        assert_eq!(layout.size.width, 100.0000);
8588        assert_eq!(layout.size.height, 100.0000);
8589        assert_eq!(layout.location.x, 0.0000);
8590        assert_eq!(layout.location.y, 0.0000);
8591
8592        assert_eq!(layout.children[0].size.width, 100.0000);
8593        assert_eq!(layout.children[0].size.height, 80.0000);
8594        assert_eq!(layout.children[0].location.x, 0.0000);
8595        assert_eq!(layout.children[0].location.y, 10.0000);
8596    }
8597
8598    #[test]
8599    fn margin_top() {
8600        let layout = stretch::compute(
8601            &stretch::style::Node {
8602                flex_direction: stretch::style::FlexDirection::Column,
8603                size: stretch::geometry::Size {
8604                    width: stretch::style::Dimension::Points(100.0000),
8605                    height: stretch::style::Dimension::Points(100.0000),
8606                    ..Default::default()
8607                },
8608                children: vec![stretch::style::Node {
8609                    size: stretch::geometry::Size {
8610                        height: stretch::style::Dimension::Points(10.0000),
8611                        ..Default::default()
8612                    },
8613                    margin: stretch::geometry::Rect {
8614                        top: stretch::style::Dimension::Points(10.0000),
8615                        ..Default::default()
8616                    },
8617                    ..Default::default()
8618                }],
8619                ..Default::default()
8620            },
8621            stretch::geometry::Size::undefined(),
8622        )
8623        .unwrap();
8624
8625        assert_eq!(layout.size.width, 100.0000);
8626        assert_eq!(layout.size.height, 100.0000);
8627        assert_eq!(layout.location.x, 0.0000);
8628        assert_eq!(layout.location.y, 0.0000);
8629
8630        assert_eq!(layout.children[0].size.width, 100.0000);
8631        assert_eq!(layout.children[0].size.height, 10.0000);
8632        assert_eq!(layout.children[0].location.x, 0.0000);
8633        assert_eq!(layout.children[0].location.y, 10.0000);
8634    }
8635
8636    #[test]
8637    fn percentage_flex_basis_main_max_height() {
8638        let layout = stretch::compute(
8639            &stretch::style::Node {
8640                size: stretch::geometry::Size {
8641                    width: stretch::style::Dimension::Points(200.0000),
8642                    height: stretch::style::Dimension::Points(400.0000),
8643                    ..Default::default()
8644                },
8645                children: vec![
8646                    stretch::style::Node {
8647                        flex_grow: 1.0000,
8648                        flex_basis: stretch::style::Dimension::Percent(0.1000),
8649                        max_size: stretch::geometry::Size {
8650                            height: stretch::style::Dimension::Percent(0.6000),
8651                            ..Default::default()
8652                        },
8653                        ..Default::default()
8654                    },
8655                    stretch::style::Node {
8656                        flex_grow: 4.0000,
8657                        flex_basis: stretch::style::Dimension::Percent(0.1000),
8658                        max_size: stretch::geometry::Size {
8659                            height: stretch::style::Dimension::Percent(0.2000),
8660                            ..Default::default()
8661                        },
8662                        ..Default::default()
8663                    },
8664                ],
8665                ..Default::default()
8666            },
8667            stretch::geometry::Size::undefined(),
8668        )
8669        .unwrap();
8670
8671        assert_eq!(layout.size.width, 200.0000);
8672        assert_eq!(layout.size.height, 400.0000);
8673        assert_eq!(layout.location.x, 0.0000);
8674        assert_eq!(layout.location.y, 0.0000);
8675
8676        assert_eq!(layout.children[0].size.width, 52.0000);
8677        assert_eq!(layout.children[0].size.height, 240.0000);
8678        assert_eq!(layout.children[0].location.x, 0.0000);
8679        assert_eq!(layout.children[0].location.y, 0.0000);
8680
8681        assert_eq!(layout.children[1].size.width, 148.0000);
8682        assert_eq!(layout.children[1].size.height, 80.0000);
8683        assert_eq!(layout.children[1].location.x, 52.0000);
8684        assert_eq!(layout.children[1].location.y, 0.0000);
8685    }
8686
8687    #[test]
8688    fn margin_auto_left_and_right_column() {
8689        let layout = stretch::compute(
8690            &stretch::style::Node {
8691                align_items: stretch::style::AlignItems::Center,
8692                size: stretch::geometry::Size {
8693                    width: stretch::style::Dimension::Points(200.0000),
8694                    height: stretch::style::Dimension::Points(200.0000),
8695                    ..Default::default()
8696                },
8697                children: vec![
8698                    stretch::style::Node {
8699                        size: stretch::geometry::Size {
8700                            width: stretch::style::Dimension::Points(50.0000),
8701                            height: stretch::style::Dimension::Points(50.0000),
8702                            ..Default::default()
8703                        },
8704                        margin: stretch::geometry::Rect {
8705                            start: stretch::style::Dimension::Auto,
8706                            end: stretch::style::Dimension::Auto,
8707                            ..Default::default()
8708                        },
8709                        ..Default::default()
8710                    },
8711                    stretch::style::Node {
8712                        size: stretch::geometry::Size {
8713                            width: stretch::style::Dimension::Points(50.0000),
8714                            height: stretch::style::Dimension::Points(50.0000),
8715                            ..Default::default()
8716                        },
8717                        ..Default::default()
8718                    },
8719                ],
8720                ..Default::default()
8721            },
8722            stretch::geometry::Size::undefined(),
8723        )
8724        .unwrap();
8725
8726        assert_eq!(layout.size.width, 200.0000);
8727        assert_eq!(layout.size.height, 200.0000);
8728        assert_eq!(layout.location.x, 0.0000);
8729        assert_eq!(layout.location.y, 0.0000);
8730
8731        assert_eq!(layout.children[0].size.width, 50.0000);
8732        assert_eq!(layout.children[0].size.height, 50.0000);
8733        assert_eq!(layout.children[0].location.x, 50.0000);
8734        assert_eq!(layout.children[0].location.y, 75.0000);
8735
8736        assert_eq!(layout.children[1].size.width, 50.0000);
8737        assert_eq!(layout.children[1].size.height, 50.0000);
8738        assert_eq!(layout.children[1].location.x, 150.0000);
8739        assert_eq!(layout.children[1].location.y, 75.0000);
8740    }
8741
8742    #[test]
8743    fn margin_and_flex_row() {
8744        let layout = stretch::compute(
8745            &stretch::style::Node {
8746                size: stretch::geometry::Size {
8747                    width: stretch::style::Dimension::Points(100.0000),
8748                    height: stretch::style::Dimension::Points(100.0000),
8749                    ..Default::default()
8750                },
8751                children: vec![stretch::style::Node {
8752                    flex_grow: 1.0000,
8753                    margin: stretch::geometry::Rect {
8754                        start: stretch::style::Dimension::Points(10.0000),
8755                        end: stretch::style::Dimension::Points(10.0000),
8756                        ..Default::default()
8757                    },
8758                    ..Default::default()
8759                }],
8760                ..Default::default()
8761            },
8762            stretch::geometry::Size::undefined(),
8763        )
8764        .unwrap();
8765
8766        assert_eq!(layout.size.width, 100.0000);
8767        assert_eq!(layout.size.height, 100.0000);
8768        assert_eq!(layout.location.x, 0.0000);
8769        assert_eq!(layout.location.y, 0.0000);
8770
8771        assert_eq!(layout.children[0].size.width, 80.0000);
8772        assert_eq!(layout.children[0].size.height, 100.0000);
8773        assert_eq!(layout.children[0].location.x, 10.0000);
8774        assert_eq!(layout.children[0].location.y, 0.0000);
8775    }
8776
8777    #[test]
8778    fn flex_wrap_children_with_min_main_overriding_flex_basis() {
8779        let layout = stretch::compute(
8780            &stretch::style::Node {
8781                flex_wrap: stretch::style::FlexWrap::Wrap,
8782                size: stretch::geometry::Size {
8783                    width: stretch::style::Dimension::Points(100.0000),
8784                    ..Default::default()
8785                },
8786                children: vec![
8787                    stretch::style::Node {
8788                        flex_basis: stretch::style::Dimension::Points(50.0000),
8789                        size: stretch::geometry::Size {
8790                            height: stretch::style::Dimension::Points(50.0000),
8791                            ..Default::default()
8792                        },
8793                        min_size: stretch::geometry::Size {
8794                            width: stretch::style::Dimension::Points(55.0000),
8795                            ..Default::default()
8796                        },
8797                        ..Default::default()
8798                    },
8799                    stretch::style::Node {
8800                        flex_basis: stretch::style::Dimension::Points(50.0000),
8801                        size: stretch::geometry::Size {
8802                            height: stretch::style::Dimension::Points(50.0000),
8803                            ..Default::default()
8804                        },
8805                        min_size: stretch::geometry::Size {
8806                            width: stretch::style::Dimension::Points(55.0000),
8807                            ..Default::default()
8808                        },
8809                        ..Default::default()
8810                    },
8811                ],
8812                ..Default::default()
8813            },
8814            stretch::geometry::Size::undefined(),
8815        )
8816        .unwrap();
8817
8818        assert_eq!(layout.size.width, 100.0000);
8819        assert_eq!(layout.size.height, 100.0000);
8820        assert_eq!(layout.location.x, 0.0000);
8821        assert_eq!(layout.location.y, 0.0000);
8822
8823        assert_eq!(layout.children[0].size.width, 55.0000);
8824        assert_eq!(layout.children[0].size.height, 50.0000);
8825        assert_eq!(layout.children[0].location.x, 0.0000);
8826        assert_eq!(layout.children[0].location.y, 0.0000);
8827
8828        assert_eq!(layout.children[1].size.width, 55.0000);
8829        assert_eq!(layout.children[1].size.height, 50.0000);
8830        assert_eq!(layout.children[1].location.x, 0.0000);
8831        assert_eq!(layout.children[1].location.y, 50.0000);
8832    }
8833
8834    #[test]
8835    fn wrap_row_align_items_center() {
8836        let layout = stretch::compute(
8837            &stretch::style::Node {
8838                flex_wrap: stretch::style::FlexWrap::Wrap,
8839                align_items: stretch::style::AlignItems::Center,
8840                size: stretch::geometry::Size {
8841                    width: stretch::style::Dimension::Points(100.0000),
8842                    ..Default::default()
8843                },
8844                children: vec![
8845                    stretch::style::Node {
8846                        size: stretch::geometry::Size {
8847                            width: stretch::style::Dimension::Points(30.0000),
8848                            height: stretch::style::Dimension::Points(10.0000),
8849                            ..Default::default()
8850                        },
8851                        ..Default::default()
8852                    },
8853                    stretch::style::Node {
8854                        size: stretch::geometry::Size {
8855                            width: stretch::style::Dimension::Points(30.0000),
8856                            height: stretch::style::Dimension::Points(20.0000),
8857                            ..Default::default()
8858                        },
8859                        ..Default::default()
8860                    },
8861                    stretch::style::Node {
8862                        size: stretch::geometry::Size {
8863                            width: stretch::style::Dimension::Points(30.0000),
8864                            height: stretch::style::Dimension::Points(30.0000),
8865                            ..Default::default()
8866                        },
8867                        ..Default::default()
8868                    },
8869                    stretch::style::Node {
8870                        size: stretch::geometry::Size {
8871                            width: stretch::style::Dimension::Points(30.0000),
8872                            height: stretch::style::Dimension::Points(30.0000),
8873                            ..Default::default()
8874                        },
8875                        ..Default::default()
8876                    },
8877                ],
8878                ..Default::default()
8879            },
8880            stretch::geometry::Size::undefined(),
8881        )
8882        .unwrap();
8883
8884        assert_eq!(layout.size.width, 100.0000);
8885        assert_eq!(layout.size.height, 60.0000);
8886        assert_eq!(layout.location.x, 0.0000);
8887        assert_eq!(layout.location.y, 0.0000);
8888
8889        assert_eq!(layout.children[0].size.width, 30.0000);
8890        assert_eq!(layout.children[0].size.height, 10.0000);
8891        assert_eq!(layout.children[0].location.x, 0.0000);
8892        assert_eq!(layout.children[0].location.y, 10.0000);
8893
8894        assert_eq!(layout.children[1].size.width, 30.0000);
8895        assert_eq!(layout.children[1].size.height, 20.0000);
8896        assert_eq!(layout.children[1].location.x, 30.0000);
8897        assert_eq!(layout.children[1].location.y, 5.0000);
8898
8899        assert_eq!(layout.children[2].size.width, 30.0000);
8900        assert_eq!(layout.children[2].size.height, 30.0000);
8901        assert_eq!(layout.children[2].location.x, 60.0000);
8902        assert_eq!(layout.children[2].location.y, 0.0000);
8903
8904        assert_eq!(layout.children[3].size.width, 30.0000);
8905        assert_eq!(layout.children[3].size.height, 30.0000);
8906        assert_eq!(layout.children[3].location.x, 0.0000);
8907        assert_eq!(layout.children[3].location.y, 30.0000);
8908    }
8909
8910    #[test]
8911    fn display_none_with_margin() {
8912        let layout = stretch::compute(
8913            &stretch::style::Node {
8914                size: stretch::geometry::Size {
8915                    width: stretch::style::Dimension::Points(100.0000),
8916                    height: stretch::style::Dimension::Points(100.0000),
8917                    ..Default::default()
8918                },
8919                children: vec![
8920                    stretch::style::Node {
8921                        display: stretch::style::Display::None,
8922                        size: stretch::geometry::Size {
8923                            width: stretch::style::Dimension::Points(20.0000),
8924                            height: stretch::style::Dimension::Points(20.0000),
8925                            ..Default::default()
8926                        },
8927                        margin: stretch::geometry::Rect {
8928                            start: stretch::style::Dimension::Points(10.0000),
8929                            end: stretch::style::Dimension::Points(10.0000),
8930                            top: stretch::style::Dimension::Points(10.0000),
8931                            bottom: stretch::style::Dimension::Points(10.0000),
8932                            ..Default::default()
8933                        },
8934                        ..Default::default()
8935                    },
8936                    stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
8937                ],
8938                ..Default::default()
8939            },
8940            stretch::geometry::Size::undefined(),
8941        )
8942        .unwrap();
8943
8944        assert_eq!(layout.size.width, 100.0000);
8945        assert_eq!(layout.size.height, 100.0000);
8946        assert_eq!(layout.location.x, 0.0000);
8947        assert_eq!(layout.location.y, 0.0000);
8948
8949        assert_eq!(layout.children[0].size.width, 0.0000);
8950        assert_eq!(layout.children[0].size.height, 0.0000);
8951        assert_eq!(layout.children[0].location.x, 0.0000);
8952        assert_eq!(layout.children[0].location.y, 0.0000);
8953
8954        assert_eq!(layout.children[1].size.width, 100.0000);
8955        assert_eq!(layout.children[1].size.height, 100.0000);
8956        assert_eq!(layout.children[1].location.x, 0.0000);
8957        assert_eq!(layout.children[1].location.y, 0.0000);
8958    }
8959
8960    #[test]
8961    fn flex_basis_flex_grow_column() {
8962        let layout = stretch::compute(
8963            &stretch::style::Node {
8964                flex_direction: stretch::style::FlexDirection::Column,
8965                size: stretch::geometry::Size {
8966                    width: stretch::style::Dimension::Points(100.0000),
8967                    height: stretch::style::Dimension::Points(100.0000),
8968                    ..Default::default()
8969                },
8970                children: vec![
8971                    stretch::style::Node {
8972                        flex_grow: 1.0000,
8973                        flex_basis: stretch::style::Dimension::Points(50.0000),
8974                        ..Default::default()
8975                    },
8976                    stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
8977                ],
8978                ..Default::default()
8979            },
8980            stretch::geometry::Size::undefined(),
8981        )
8982        .unwrap();
8983
8984        assert_eq!(layout.size.width, 100.0000);
8985        assert_eq!(layout.size.height, 100.0000);
8986        assert_eq!(layout.location.x, 0.0000);
8987        assert_eq!(layout.location.y, 0.0000);
8988
8989        assert_eq!(layout.children[0].size.width, 100.0000);
8990        assert_eq!(layout.children[0].size.height, 75.0000);
8991        assert_eq!(layout.children[0].location.x, 0.0000);
8992        assert_eq!(layout.children[0].location.y, 0.0000);
8993
8994        assert_eq!(layout.children[1].size.width, 100.0000);
8995        assert_eq!(layout.children[1].size.height, 25.0000);
8996        assert_eq!(layout.children[1].location.x, 0.0000);
8997        assert_eq!(layout.children[1].location.y, 75.0000);
8998    }
8999
9000    #[test]
9001    fn absolute_layout_align_items_and_justify_content_center_and_right_position() {
9002        let layout = stretch::compute(
9003            &stretch::style::Node {
9004                align_items: stretch::style::AlignItems::Center,
9005                justify_content: stretch::style::JustifyContent::Center,
9006                size: stretch::geometry::Size {
9007                    width: stretch::style::Dimension::Points(110.0000),
9008                    height: stretch::style::Dimension::Points(100.0000),
9009                    ..Default::default()
9010                },
9011                children: vec![stretch::style::Node {
9012                    position_type: stretch::style::PositionType::Absolute,
9013                    size: stretch::geometry::Size {
9014                        width: stretch::style::Dimension::Points(60.0000),
9015                        height: stretch::style::Dimension::Points(40.0000),
9016                        ..Default::default()
9017                    },
9018                    position: stretch::geometry::Rect {
9019                        end: stretch::style::Dimension::Points(5.0000),
9020                        ..Default::default()
9021                    },
9022                    ..Default::default()
9023                }],
9024                ..Default::default()
9025            },
9026            stretch::geometry::Size::undefined(),
9027        )
9028        .unwrap();
9029
9030        assert_eq!(layout.size.width, 110.0000);
9031        assert_eq!(layout.size.height, 100.0000);
9032        assert_eq!(layout.location.x, 0.0000);
9033        assert_eq!(layout.location.y, 0.0000);
9034
9035        assert_eq!(layout.children[0].size.width, 60.0000);
9036        assert_eq!(layout.children[0].size.height, 40.0000);
9037        assert_eq!(layout.children[0].location.x, 45.0000);
9038        assert_eq!(layout.children[0].location.y, 30.0000);
9039    }
9040
9041    #[test]
9042    fn overflow_cross_axis() {
9043        let layout = stretch::compute(
9044            &stretch::style::Node {
9045                size: stretch::geometry::Size {
9046                    width: stretch::style::Dimension::Points(100.0000),
9047                    height: stretch::style::Dimension::Points(100.0000),
9048                    ..Default::default()
9049                },
9050                children: vec![stretch::style::Node {
9051                    size: stretch::geometry::Size {
9052                        width: stretch::style::Dimension::Points(100.0000),
9053                        height: stretch::style::Dimension::Points(200.0000),
9054                        ..Default::default()
9055                    },
9056                    ..Default::default()
9057                }],
9058                ..Default::default()
9059            },
9060            stretch::geometry::Size::undefined(),
9061        )
9062        .unwrap();
9063
9064        assert_eq!(layout.size.width, 100.0000);
9065        assert_eq!(layout.size.height, 100.0000);
9066        assert_eq!(layout.location.x, 0.0000);
9067        assert_eq!(layout.location.y, 0.0000);
9068
9069        assert_eq!(layout.children[0].size.width, 100.0000);
9070        assert_eq!(layout.children[0].size.height, 200.0000);
9071        assert_eq!(layout.children[0].location.x, 0.0000);
9072        assert_eq!(layout.children[0].location.y, 0.0000);
9073    }
9074
9075    #[test]
9076    fn display_none_with_position() {
9077        let layout = stretch::compute(
9078            &stretch::style::Node {
9079                size: stretch::geometry::Size {
9080                    width: stretch::style::Dimension::Points(100.0000),
9081                    height: stretch::style::Dimension::Points(100.0000),
9082                    ..Default::default()
9083                },
9084                children: vec![
9085                    stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
9086                    stretch::style::Node {
9087                        display: stretch::style::Display::None,
9088                        flex_grow: 1.0000,
9089                        position: stretch::geometry::Rect {
9090                            top: stretch::style::Dimension::Points(10.0000),
9091                            ..Default::default()
9092                        },
9093                        ..Default::default()
9094                    },
9095                ],
9096                ..Default::default()
9097            },
9098            stretch::geometry::Size::undefined(),
9099        )
9100        .unwrap();
9101
9102        assert_eq!(layout.size.width, 100.0000);
9103        assert_eq!(layout.size.height, 100.0000);
9104        assert_eq!(layout.location.x, 0.0000);
9105        assert_eq!(layout.location.y, 0.0000);
9106
9107        assert_eq!(layout.children[0].size.width, 100.0000);
9108        assert_eq!(layout.children[0].size.height, 100.0000);
9109        assert_eq!(layout.children[0].location.x, 0.0000);
9110        assert_eq!(layout.children[0].location.y, 0.0000);
9111
9112        assert_eq!(layout.children[1].size.width, 0.0000);
9113        assert_eq!(layout.children[1].size.height, 0.0000);
9114        assert_eq!(layout.children[1].location.x, 0.0000);
9115        assert_eq!(layout.children[1].location.y, 0.0000);
9116    }
9117
9118    #[test]
9119    fn wrap_column() {
9120        let layout = stretch::compute(
9121            &stretch::style::Node {
9122                flex_direction: stretch::style::FlexDirection::Column,
9123                flex_wrap: stretch::style::FlexWrap::Wrap,
9124                size: stretch::geometry::Size {
9125                    width: stretch::style::Dimension::Points(100.0000),
9126                    height: stretch::style::Dimension::Points(100.0000),
9127                    ..Default::default()
9128                },
9129                children: vec![
9130                    stretch::style::Node {
9131                        size: stretch::geometry::Size {
9132                            width: stretch::style::Dimension::Points(30.0000),
9133                            height: stretch::style::Dimension::Points(31.0000),
9134                            ..Default::default()
9135                        },
9136                        ..Default::default()
9137                    },
9138                    stretch::style::Node {
9139                        size: stretch::geometry::Size {
9140                            width: stretch::style::Dimension::Points(30.0000),
9141                            height: stretch::style::Dimension::Points(32.0000),
9142                            ..Default::default()
9143                        },
9144                        ..Default::default()
9145                    },
9146                    stretch::style::Node {
9147                        size: stretch::geometry::Size {
9148                            width: stretch::style::Dimension::Points(30.0000),
9149                            height: stretch::style::Dimension::Points(33.0000),
9150                            ..Default::default()
9151                        },
9152                        ..Default::default()
9153                    },
9154                    stretch::style::Node {
9155                        size: stretch::geometry::Size {
9156                            width: stretch::style::Dimension::Points(30.0000),
9157                            height: stretch::style::Dimension::Points(34.0000),
9158                            ..Default::default()
9159                        },
9160                        ..Default::default()
9161                    },
9162                ],
9163                ..Default::default()
9164            },
9165            stretch::geometry::Size::undefined(),
9166        )
9167        .unwrap();
9168
9169        assert_eq!(layout.size.width, 100.0000);
9170        assert_eq!(layout.size.height, 100.0000);
9171        assert_eq!(layout.location.x, 0.0000);
9172        assert_eq!(layout.location.y, 0.0000);
9173
9174        assert_eq!(layout.children[0].size.width, 30.0000);
9175        assert_eq!(layout.children[0].size.height, 31.0000);
9176        assert_eq!(layout.children[0].location.x, 0.0000);
9177        assert_eq!(layout.children[0].location.y, 0.0000);
9178
9179        assert_eq!(layout.children[1].size.width, 30.0000);
9180        assert_eq!(layout.children[1].size.height, 32.0000);
9181        assert_eq!(layout.children[1].location.x, 0.0000);
9182        assert_eq!(layout.children[1].location.y, 31.0000);
9183
9184        assert_eq!(layout.children[2].size.width, 30.0000);
9185        assert_eq!(layout.children[2].size.height, 33.0000);
9186        assert_eq!(layout.children[2].location.x, 0.0000);
9187        assert_eq!(layout.children[2].location.y, 63.0000);
9188
9189        assert_eq!(layout.children[3].size.width, 30.0000);
9190        assert_eq!(layout.children[3].size.height, 34.0000);
9191        assert_eq!(layout.children[3].location.x, 50.0000);
9192        assert_eq!(layout.children[3].location.y, 0.0000);
9193    }
9194
9195    #[test]
9196    fn justify_content_column_space_evenly() {
9197        let layout = stretch::compute(
9198            &stretch::style::Node {
9199                flex_direction: stretch::style::FlexDirection::Column,
9200                justify_content: stretch::style::JustifyContent::SpaceEvenly,
9201                size: stretch::geometry::Size {
9202                    width: stretch::style::Dimension::Points(100.0000),
9203                    height: stretch::style::Dimension::Points(100.0000),
9204                    ..Default::default()
9205                },
9206                children: vec![
9207                    stretch::style::Node {
9208                        size: stretch::geometry::Size {
9209                            height: stretch::style::Dimension::Points(10.0000),
9210                            ..Default::default()
9211                        },
9212                        ..Default::default()
9213                    },
9214                    stretch::style::Node {
9215                        size: stretch::geometry::Size {
9216                            height: stretch::style::Dimension::Points(10.0000),
9217                            ..Default::default()
9218                        },
9219                        ..Default::default()
9220                    },
9221                    stretch::style::Node {
9222                        size: stretch::geometry::Size {
9223                            height: stretch::style::Dimension::Points(10.0000),
9224                            ..Default::default()
9225                        },
9226                        ..Default::default()
9227                    },
9228                ],
9229                ..Default::default()
9230            },
9231            stretch::geometry::Size::undefined(),
9232        )
9233        .unwrap();
9234
9235        assert_eq!(layout.size.width, 100.0000);
9236        assert_eq!(layout.size.height, 100.0000);
9237        assert_eq!(layout.location.x, 0.0000);
9238        assert_eq!(layout.location.y, 0.0000);
9239
9240        assert_eq!(layout.children[0].size.width, 100.0000);
9241        assert_eq!(layout.children[0].size.height, 10.0000);
9242        assert_eq!(layout.children[0].location.x, 0.0000);
9243        assert_eq!(layout.children[0].location.y, 18.0000);
9244
9245        assert_eq!(layout.children[1].size.width, 100.0000);
9246        assert_eq!(layout.children[1].size.height, 10.0000);
9247        assert_eq!(layout.children[1].location.x, 0.0000);
9248        assert_eq!(layout.children[1].location.y, 45.0000);
9249
9250        assert_eq!(layout.children[2].size.width, 100.0000);
9251        assert_eq!(layout.children[2].size.height, 10.0000);
9252        assert_eq!(layout.children[2].location.x, 0.0000);
9253        assert_eq!(layout.children[2].location.y, 73.0000);
9254    }
9255
9256    #[test]
9257    fn flex_grow_within_constrained_max_column() {
9258        let layout = stretch::compute(
9259            &stretch::style::Node {
9260                flex_direction: stretch::style::FlexDirection::Column,
9261                size: stretch::geometry::Size {
9262                    width: stretch::style::Dimension::Points(100.0000),
9263                    ..Default::default()
9264                },
9265                max_size: stretch::geometry::Size {
9266                    height: stretch::style::Dimension::Points(100.0000),
9267                    ..Default::default()
9268                },
9269                children: vec![
9270                    stretch::style::Node {
9271                        flex_shrink: 1.0000,
9272                        flex_basis: stretch::style::Dimension::Points(100.0000),
9273                        ..Default::default()
9274                    },
9275                    stretch::style::Node {
9276                        size: stretch::geometry::Size {
9277                            height: stretch::style::Dimension::Points(50.0000),
9278                            ..Default::default()
9279                        },
9280                        ..Default::default()
9281                    },
9282                ],
9283                ..Default::default()
9284            },
9285            stretch::geometry::Size::undefined(),
9286        )
9287        .unwrap();
9288
9289        assert_eq!(layout.size.width, 100.0000);
9290        assert_eq!(layout.size.height, 100.0000);
9291        assert_eq!(layout.location.x, 0.0000);
9292        assert_eq!(layout.location.y, 0.0000);
9293
9294        assert_eq!(layout.children[0].size.width, 100.0000);
9295        assert_eq!(layout.children[0].size.height, 67.0000);
9296        assert_eq!(layout.children[0].location.x, 0.0000);
9297        assert_eq!(layout.children[0].location.y, 0.0000);
9298
9299        assert_eq!(layout.children[1].size.width, 100.0000);
9300        assert_eq!(layout.children[1].size.height, 33.0000);
9301        assert_eq!(layout.children[1].location.x, 0.0000);
9302        assert_eq!(layout.children[1].location.y, 67.0000);
9303    }
9304
9305    #[test]
9306    fn justify_content_column_space_around() {
9307        let layout = stretch::compute(
9308            &stretch::style::Node {
9309                flex_direction: stretch::style::FlexDirection::Column,
9310                justify_content: stretch::style::JustifyContent::SpaceAround,
9311                size: stretch::geometry::Size {
9312                    width: stretch::style::Dimension::Points(100.0000),
9313                    height: stretch::style::Dimension::Points(100.0000),
9314                    ..Default::default()
9315                },
9316                children: vec![
9317                    stretch::style::Node {
9318                        size: stretch::geometry::Size {
9319                            height: stretch::style::Dimension::Points(10.0000),
9320                            ..Default::default()
9321                        },
9322                        ..Default::default()
9323                    },
9324                    stretch::style::Node {
9325                        size: stretch::geometry::Size {
9326                            height: stretch::style::Dimension::Points(10.0000),
9327                            ..Default::default()
9328                        },
9329                        ..Default::default()
9330                    },
9331                    stretch::style::Node {
9332                        size: stretch::geometry::Size {
9333                            height: stretch::style::Dimension::Points(10.0000),
9334                            ..Default::default()
9335                        },
9336                        ..Default::default()
9337                    },
9338                ],
9339                ..Default::default()
9340            },
9341            stretch::geometry::Size::undefined(),
9342        )
9343        .unwrap();
9344
9345        assert_eq!(layout.size.width, 100.0000);
9346        assert_eq!(layout.size.height, 100.0000);
9347        assert_eq!(layout.location.x, 0.0000);
9348        assert_eq!(layout.location.y, 0.0000);
9349
9350        assert_eq!(layout.children[0].size.width, 100.0000);
9351        assert_eq!(layout.children[0].size.height, 10.0000);
9352        assert_eq!(layout.children[0].location.x, 0.0000);
9353        assert_eq!(layout.children[0].location.y, 12.0000);
9354
9355        assert_eq!(layout.children[1].size.width, 100.0000);
9356        assert_eq!(layout.children[1].size.height, 10.0000);
9357        assert_eq!(layout.children[1].location.x, 0.0000);
9358        assert_eq!(layout.children[1].location.y, 45.0000);
9359
9360        assert_eq!(layout.children[2].size.width, 100.0000);
9361        assert_eq!(layout.children[2].size.height, 10.0000);
9362        assert_eq!(layout.children[2].location.x, 0.0000);
9363        assert_eq!(layout.children[2].location.y, 78.0000);
9364    }
9365
9366    #[test]
9367    fn flex_basis_larger_than_content_row() {
9368        let layout = stretch::compute(
9369            &stretch::style::Node {
9370                size: stretch::geometry::Size {
9371                    width: stretch::style::Dimension::Points(100.0000),
9372                    ..Default::default()
9373                },
9374                children: vec![stretch::style::Node {
9375                    flex_direction: stretch::style::FlexDirection::Column,
9376                    flex_basis: stretch::style::Dimension::Points(50.0000),
9377                    children: vec![stretch::style::Node {
9378                        size: stretch::geometry::Size {
9379                            width: stretch::style::Dimension::Points(10.0000),
9380                            height: stretch::style::Dimension::Points(100.0000),
9381                            ..Default::default()
9382                        },
9383                        ..Default::default()
9384                    }],
9385                    ..Default::default()
9386                }],
9387                ..Default::default()
9388            },
9389            stretch::geometry::Size::undefined(),
9390        )
9391        .unwrap();
9392
9393        assert_eq!(layout.size.width, 100.0000);
9394        assert_eq!(layout.size.height, 100.0000);
9395        assert_eq!(layout.location.x, 0.0000);
9396        assert_eq!(layout.location.y, 0.0000);
9397
9398        assert_eq!(layout.children[0].size.width, 50.0000);
9399        assert_eq!(layout.children[0].size.height, 100.0000);
9400        assert_eq!(layout.children[0].location.x, 0.0000);
9401        assert_eq!(layout.children[0].location.y, 0.0000);
9402
9403        assert_eq!(layout.children[0].children[0].size.width, 10.0000);
9404        assert_eq!(layout.children[0].children[0].size.height, 100.0000);
9405        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
9406        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
9407    }
9408
9409    #[test]
9410    fn absolute_layout_align_items_and_justify_content_center_and_left_position() {
9411        let layout = stretch::compute(
9412            &stretch::style::Node {
9413                align_items: stretch::style::AlignItems::Center,
9414                justify_content: stretch::style::JustifyContent::Center,
9415                size: stretch::geometry::Size {
9416                    width: stretch::style::Dimension::Points(110.0000),
9417                    height: stretch::style::Dimension::Points(100.0000),
9418                    ..Default::default()
9419                },
9420                children: vec![stretch::style::Node {
9421                    position_type: stretch::style::PositionType::Absolute,
9422                    size: stretch::geometry::Size {
9423                        width: stretch::style::Dimension::Points(60.0000),
9424                        height: stretch::style::Dimension::Points(40.0000),
9425                        ..Default::default()
9426                    },
9427                    position: stretch::geometry::Rect {
9428                        start: stretch::style::Dimension::Points(5.0000),
9429                        ..Default::default()
9430                    },
9431                    ..Default::default()
9432                }],
9433                ..Default::default()
9434            },
9435            stretch::geometry::Size::undefined(),
9436        )
9437        .unwrap();
9438
9439        assert_eq!(layout.size.width, 110.0000);
9440        assert_eq!(layout.size.height, 100.0000);
9441        assert_eq!(layout.location.x, 0.0000);
9442        assert_eq!(layout.location.y, 0.0000);
9443
9444        assert_eq!(layout.children[0].size.width, 60.0000);
9445        assert_eq!(layout.children[0].size.height, 40.0000);
9446        assert_eq!(layout.children[0].location.x, 5.0000);
9447        assert_eq!(layout.children[0].location.y, 30.0000);
9448    }
9449
9450    #[test]
9451    fn percentage_flex_basis_main_min_width() {
9452        let layout = stretch::compute(
9453            &stretch::style::Node {
9454                size: stretch::geometry::Size {
9455                    width: stretch::style::Dimension::Points(200.0000),
9456                    height: stretch::style::Dimension::Points(400.0000),
9457                    ..Default::default()
9458                },
9459                children: vec![
9460                    stretch::style::Node {
9461                        flex_grow: 1.0000,
9462                        flex_basis: stretch::style::Dimension::Percent(0.1500),
9463                        min_size: stretch::geometry::Size {
9464                            width: stretch::style::Dimension::Percent(0.6000),
9465                            ..Default::default()
9466                        },
9467                        ..Default::default()
9468                    },
9469                    stretch::style::Node {
9470                        flex_grow: 4.0000,
9471                        flex_basis: stretch::style::Dimension::Percent(0.1000),
9472                        min_size: stretch::geometry::Size {
9473                            width: stretch::style::Dimension::Percent(0.2000),
9474                            ..Default::default()
9475                        },
9476                        ..Default::default()
9477                    },
9478                ],
9479                ..Default::default()
9480            },
9481            stretch::geometry::Size::undefined(),
9482        )
9483        .unwrap();
9484
9485        assert_eq!(layout.size.width, 200.0000);
9486        assert_eq!(layout.size.height, 400.0000);
9487        assert_eq!(layout.location.x, 0.0000);
9488        assert_eq!(layout.location.y, 0.0000);
9489
9490        assert_eq!(layout.children[0].size.width, 120.0000);
9491        assert_eq!(layout.children[0].size.height, 400.0000);
9492        assert_eq!(layout.children[0].location.x, 0.0000);
9493        assert_eq!(layout.children[0].location.y, 0.0000);
9494
9495        assert_eq!(layout.children[1].size.width, 80.0000);
9496        assert_eq!(layout.children[1].size.height, 400.0000);
9497        assert_eq!(layout.children[1].location.x, 120.0000);
9498        assert_eq!(layout.children[1].location.y, 0.0000);
9499    }
9500
9501    #[test]
9502    fn margin_auto_bottom() {
9503        let layout = stretch::compute(
9504            &stretch::style::Node {
9505                align_items: stretch::style::AlignItems::Center,
9506                size: stretch::geometry::Size {
9507                    width: stretch::style::Dimension::Points(200.0000),
9508                    height: stretch::style::Dimension::Points(200.0000),
9509                    ..Default::default()
9510                },
9511                children: vec![
9512                    stretch::style::Node {
9513                        size: stretch::geometry::Size {
9514                            width: stretch::style::Dimension::Points(50.0000),
9515                            height: stretch::style::Dimension::Points(50.0000),
9516                            ..Default::default()
9517                        },
9518                        margin: stretch::geometry::Rect {
9519                            bottom: stretch::style::Dimension::Auto,
9520                            ..Default::default()
9521                        },
9522                        ..Default::default()
9523                    },
9524                    stretch::style::Node {
9525                        size: stretch::geometry::Size {
9526                            width: stretch::style::Dimension::Points(50.0000),
9527                            height: stretch::style::Dimension::Points(50.0000),
9528                            ..Default::default()
9529                        },
9530                        ..Default::default()
9531                    },
9532                ],
9533                ..Default::default()
9534            },
9535            stretch::geometry::Size::undefined(),
9536        )
9537        .unwrap();
9538
9539        assert_eq!(layout.size.width, 200.0000);
9540        assert_eq!(layout.size.height, 200.0000);
9541        assert_eq!(layout.location.x, 0.0000);
9542        assert_eq!(layout.location.y, 0.0000);
9543
9544        assert_eq!(layout.children[0].size.width, 50.0000);
9545        assert_eq!(layout.children[0].size.height, 50.0000);
9546        assert_eq!(layout.children[0].location.x, 0.0000);
9547        assert_eq!(layout.children[0].location.y, 0.0000);
9548
9549        assert_eq!(layout.children[1].size.width, 50.0000);
9550        assert_eq!(layout.children[1].size.height, 50.0000);
9551        assert_eq!(layout.children[1].location.x, 50.0000);
9552        assert_eq!(layout.children[1].location.y, 75.0000);
9553    }
9554
9555    #[test]
9556    fn flex_grow_shrink_at_most() {
9557        let layout = stretch::compute(
9558            &stretch::style::Node {
9559                size: stretch::geometry::Size {
9560                    width: stretch::style::Dimension::Points(100.0000),
9561                    height: stretch::style::Dimension::Points(100.0000),
9562                    ..Default::default()
9563                },
9564                children: vec![stretch::style::Node {
9565                    children: vec![stretch::style::Node {
9566                        flex_grow: 1.0000,
9567                        flex_shrink: 1.0000,
9568                        ..Default::default()
9569                    }],
9570                    ..Default::default()
9571                }],
9572                ..Default::default()
9573            },
9574            stretch::geometry::Size::undefined(),
9575        )
9576        .unwrap();
9577
9578        assert_eq!(layout.size.width, 100.0000);
9579        assert_eq!(layout.size.height, 100.0000);
9580        assert_eq!(layout.location.x, 0.0000);
9581        assert_eq!(layout.location.y, 0.0000);
9582
9583        assert_eq!(layout.children[0].size.width, 0.0000);
9584        assert_eq!(layout.children[0].size.height, 100.0000);
9585        assert_eq!(layout.children[0].location.x, 0.0000);
9586        assert_eq!(layout.children[0].location.y, 0.0000);
9587
9588        assert_eq!(layout.children[0].children[0].size.width, 0.0000);
9589        assert_eq!(layout.children[0].children[0].size.height, 100.0000);
9590        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
9591        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
9592    }
9593
9594    #[test]
9595    fn percentage_padding_should_calculate_based_only_on_width() {
9596        let layout = stretch::compute(
9597            &stretch::style::Node {
9598                flex_direction: stretch::style::FlexDirection::Column,
9599                size: stretch::geometry::Size {
9600                    width: stretch::style::Dimension::Points(200.0000),
9601                    height: stretch::style::Dimension::Points(100.0000),
9602                    ..Default::default()
9603                },
9604                children: vec![stretch::style::Node {
9605                    flex_direction: stretch::style::FlexDirection::Column,
9606                    flex_grow: 1.0000,
9607                    padding: stretch::geometry::Rect {
9608                        start: stretch::style::Dimension::Percent(0.1000),
9609                        end: stretch::style::Dimension::Percent(0.1000),
9610                        top: stretch::style::Dimension::Percent(0.1000),
9611                        bottom: stretch::style::Dimension::Percent(0.1000),
9612                        ..Default::default()
9613                    },
9614                    children: vec![stretch::style::Node {
9615                        size: stretch::geometry::Size {
9616                            width: stretch::style::Dimension::Points(10.0000),
9617                            height: stretch::style::Dimension::Points(10.0000),
9618                            ..Default::default()
9619                        },
9620                        ..Default::default()
9621                    }],
9622                    ..Default::default()
9623                }],
9624                ..Default::default()
9625            },
9626            stretch::geometry::Size::undefined(),
9627        )
9628        .unwrap();
9629
9630        assert_eq!(layout.size.width, 200.0000);
9631        assert_eq!(layout.size.height, 100.0000);
9632        assert_eq!(layout.location.x, 0.0000);
9633        assert_eq!(layout.location.y, 0.0000);
9634
9635        assert_eq!(layout.children[0].size.width, 200.0000);
9636        assert_eq!(layout.children[0].size.height, 100.0000);
9637        assert_eq!(layout.children[0].location.x, 0.0000);
9638        assert_eq!(layout.children[0].location.y, 0.0000);
9639
9640        assert_eq!(layout.children[0].children[0].size.width, 10.0000);
9641        assert_eq!(layout.children[0].children[0].size.height, 10.0000);
9642        assert_eq!(layout.children[0].children[0].location.x, 20.0000);
9643        assert_eq!(layout.children[0].children[0].location.y, 20.0000);
9644    }
9645
9646    #[test]
9647    fn flex_shrink_to_zero() {
9648        let layout = stretch::compute(
9649            &stretch::style::Node {
9650                size: stretch::geometry::Size {
9651                    width: stretch::style::Dimension::Points(75.0000),
9652                    ..Default::default()
9653                },
9654                children: vec![
9655                    stretch::style::Node {
9656                        flex_shrink: 0.0000,
9657                        size: stretch::geometry::Size {
9658                            width: stretch::style::Dimension::Points(50.0000),
9659                            height: stretch::style::Dimension::Points(50.0000),
9660                            ..Default::default()
9661                        },
9662                        ..Default::default()
9663                    },
9664                    stretch::style::Node {
9665                        flex_shrink: 1.0000,
9666                        size: stretch::geometry::Size {
9667                            width: stretch::style::Dimension::Points(50.0000),
9668                            height: stretch::style::Dimension::Points(50.0000),
9669                            ..Default::default()
9670                        },
9671                        ..Default::default()
9672                    },
9673                    stretch::style::Node {
9674                        flex_shrink: 0.0000,
9675                        size: stretch::geometry::Size {
9676                            width: stretch::style::Dimension::Points(50.0000),
9677                            height: stretch::style::Dimension::Points(50.0000),
9678                            ..Default::default()
9679                        },
9680                        ..Default::default()
9681                    },
9682                ],
9683                ..Default::default()
9684            },
9685            stretch::geometry::Size::undefined(),
9686        )
9687        .unwrap();
9688
9689        assert_eq!(layout.size.width, 75.0000);
9690        assert_eq!(layout.size.height, 50.0000);
9691        assert_eq!(layout.location.x, 0.0000);
9692        assert_eq!(layout.location.y, 0.0000);
9693
9694        assert_eq!(layout.children[0].size.width, 50.0000);
9695        assert_eq!(layout.children[0].size.height, 50.0000);
9696        assert_eq!(layout.children[0].location.x, 0.0000);
9697        assert_eq!(layout.children[0].location.y, 0.0000);
9698
9699        assert_eq!(layout.children[1].size.width, 0.0000);
9700        assert_eq!(layout.children[1].size.height, 50.0000);
9701        assert_eq!(layout.children[1].location.x, 50.0000);
9702        assert_eq!(layout.children[1].location.y, 0.0000);
9703
9704        assert_eq!(layout.children[2].size.width, 50.0000);
9705        assert_eq!(layout.children[2].size.height, 50.0000);
9706        assert_eq!(layout.children[2].location.x, 50.0000);
9707        assert_eq!(layout.children[2].location.y, 0.0000);
9708    }
9709
9710    #[test]
9711    fn margin_auto_mutiple_children_row() {
9712        let layout = stretch::compute(
9713            &stretch::style::Node {
9714                align_items: stretch::style::AlignItems::Center,
9715                size: stretch::geometry::Size {
9716                    width: stretch::style::Dimension::Points(200.0000),
9717                    height: stretch::style::Dimension::Points(200.0000),
9718                    ..Default::default()
9719                },
9720                children: vec![
9721                    stretch::style::Node {
9722                        size: stretch::geometry::Size {
9723                            width: stretch::style::Dimension::Points(50.0000),
9724                            height: stretch::style::Dimension::Points(50.0000),
9725                            ..Default::default()
9726                        },
9727                        margin: stretch::geometry::Rect { end: stretch::style::Dimension::Auto, ..Default::default() },
9728                        ..Default::default()
9729                    },
9730                    stretch::style::Node {
9731                        size: stretch::geometry::Size {
9732                            width: stretch::style::Dimension::Points(50.0000),
9733                            height: stretch::style::Dimension::Points(50.0000),
9734                            ..Default::default()
9735                        },
9736                        margin: stretch::geometry::Rect { end: stretch::style::Dimension::Auto, ..Default::default() },
9737                        ..Default::default()
9738                    },
9739                    stretch::style::Node {
9740                        size: stretch::geometry::Size {
9741                            width: stretch::style::Dimension::Points(50.0000),
9742                            height: stretch::style::Dimension::Points(50.0000),
9743                            ..Default::default()
9744                        },
9745                        ..Default::default()
9746                    },
9747                ],
9748                ..Default::default()
9749            },
9750            stretch::geometry::Size::undefined(),
9751        )
9752        .unwrap();
9753
9754        assert_eq!(layout.size.width, 200.0000);
9755        assert_eq!(layout.size.height, 200.0000);
9756        assert_eq!(layout.location.x, 0.0000);
9757        assert_eq!(layout.location.y, 0.0000);
9758
9759        assert_eq!(layout.children[0].size.width, 50.0000);
9760        assert_eq!(layout.children[0].size.height, 50.0000);
9761        assert_eq!(layout.children[0].location.x, 0.0000);
9762        assert_eq!(layout.children[0].location.y, 75.0000);
9763
9764        assert_eq!(layout.children[1].size.width, 50.0000);
9765        assert_eq!(layout.children[1].size.height, 50.0000);
9766        assert_eq!(layout.children[1].location.x, 75.0000);
9767        assert_eq!(layout.children[1].location.y, 75.0000);
9768
9769        assert_eq!(layout.children[2].size.width, 50.0000);
9770        assert_eq!(layout.children[2].size.height, 50.0000);
9771        assert_eq!(layout.children[2].location.x, 150.0000);
9772        assert_eq!(layout.children[2].location.y, 75.0000);
9773    }
9774
9775    #[test]
9776    fn justify_content_min_width_with_padding_child_width_lower_than_parent() {
9777        let layout = stretch::compute(
9778            &stretch::style::Node {
9779                flex_direction: stretch::style::FlexDirection::Column,
9780                size: stretch::geometry::Size {
9781                    width: stretch::style::Dimension::Points(1080.0000),
9782                    height: stretch::style::Dimension::Points(1584.0000),
9783                    ..Default::default()
9784                },
9785                children: vec![stretch::style::Node {
9786                    children: vec![stretch::style::Node {
9787                        justify_content: stretch::style::JustifyContent::Center,
9788                        min_size: stretch::geometry::Size {
9789                            width: stretch::style::Dimension::Points(400.0000),
9790                            ..Default::default()
9791                        },
9792                        padding: stretch::geometry::Rect {
9793                            start: stretch::style::Dimension::Points(100.0000),
9794                            end: stretch::style::Dimension::Points(100.0000),
9795                            ..Default::default()
9796                        },
9797                        children: vec![stretch::style::Node {
9798                            size: stretch::geometry::Size {
9799                                width: stretch::style::Dimension::Points(199.0000),
9800                                height: stretch::style::Dimension::Points(100.0000),
9801                                ..Default::default()
9802                            },
9803                            ..Default::default()
9804                        }],
9805                        ..Default::default()
9806                    }],
9807                    ..Default::default()
9808                }],
9809                ..Default::default()
9810            },
9811            stretch::geometry::Size::undefined(),
9812        )
9813        .unwrap();
9814
9815        assert_eq!(layout.size.width, 1080.0000);
9816        assert_eq!(layout.size.height, 1584.0000);
9817        assert_eq!(layout.location.x, 0.0000);
9818        assert_eq!(layout.location.y, 0.0000);
9819
9820        assert_eq!(layout.children[0].size.width, 1080.0000);
9821        assert_eq!(layout.children[0].size.height, 100.0000);
9822        assert_eq!(layout.children[0].location.x, 0.0000);
9823        assert_eq!(layout.children[0].location.y, 0.0000);
9824
9825        assert_eq!(layout.children[0].children[0].size.width, 400.0000);
9826        assert_eq!(layout.children[0].children[0].size.height, 100.0000);
9827        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
9828        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
9829
9830        assert_eq!(layout.children[0].children[0].children[0].size.width, 199.0000);
9831        assert_eq!(layout.children[0].children[0].children[0].size.height, 100.0000);
9832        assert_eq!(layout.children[0].children[0].children[0].location.x, 101.0000);
9833        assert_eq!(layout.children[0].children[0].children[0].location.y, 0.0000);
9834    }
9835
9836    #[test]
9837    fn size_defined_by_grand_child() {
9838        let layout = stretch::compute(
9839            &stretch::style::Node {
9840                children: vec![stretch::style::Node {
9841                    children: vec![stretch::style::Node {
9842                        size: stretch::geometry::Size {
9843                            width: stretch::style::Dimension::Points(100.0000),
9844                            height: stretch::style::Dimension::Points(100.0000),
9845                            ..Default::default()
9846                        },
9847                        ..Default::default()
9848                    }],
9849                    ..Default::default()
9850                }],
9851                ..Default::default()
9852            },
9853            stretch::geometry::Size::undefined(),
9854        )
9855        .unwrap();
9856
9857        assert_eq!(layout.size.width, 100.0000);
9858        assert_eq!(layout.size.height, 100.0000);
9859        assert_eq!(layout.location.x, 0.0000);
9860        assert_eq!(layout.location.y, 0.0000);
9861
9862        assert_eq!(layout.children[0].size.width, 100.0000);
9863        assert_eq!(layout.children[0].size.height, 100.0000);
9864        assert_eq!(layout.children[0].location.x, 0.0000);
9865        assert_eq!(layout.children[0].location.y, 0.0000);
9866
9867        assert_eq!(layout.children[0].children[0].size.width, 100.0000);
9868        assert_eq!(layout.children[0].children[0].size.height, 100.0000);
9869        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
9870        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
9871    }
9872
9873    #[test]
9874    fn absolute_layout_align_items_and_justify_content_center_and_bottom_position() {
9875        let layout = stretch::compute(
9876            &stretch::style::Node {
9877                align_items: stretch::style::AlignItems::Center,
9878                justify_content: stretch::style::JustifyContent::Center,
9879                size: stretch::geometry::Size {
9880                    width: stretch::style::Dimension::Points(110.0000),
9881                    height: stretch::style::Dimension::Points(100.0000),
9882                    ..Default::default()
9883                },
9884                children: vec![stretch::style::Node {
9885                    position_type: stretch::style::PositionType::Absolute,
9886                    size: stretch::geometry::Size {
9887                        width: stretch::style::Dimension::Points(60.0000),
9888                        height: stretch::style::Dimension::Points(40.0000),
9889                        ..Default::default()
9890                    },
9891                    position: stretch::geometry::Rect {
9892                        bottom: stretch::style::Dimension::Points(10.0000),
9893                        ..Default::default()
9894                    },
9895                    ..Default::default()
9896                }],
9897                ..Default::default()
9898            },
9899            stretch::geometry::Size::undefined(),
9900        )
9901        .unwrap();
9902
9903        assert_eq!(layout.size.width, 110.0000);
9904        assert_eq!(layout.size.height, 100.0000);
9905        assert_eq!(layout.location.x, 0.0000);
9906        assert_eq!(layout.location.y, 0.0000);
9907
9908        assert_eq!(layout.children[0].size.width, 60.0000);
9909        assert_eq!(layout.children[0].size.height, 40.0000);
9910        assert_eq!(layout.children[0].location.x, 25.0000);
9911        assert_eq!(layout.children[0].location.y, 50.0000);
9912    }
9913
9914    #[test]
9915    fn justify_content_min_max() {
9916        let layout = stretch::compute(
9917            &stretch::style::Node {
9918                flex_direction: stretch::style::FlexDirection::Column,
9919                justify_content: stretch::style::JustifyContent::Center,
9920                size: stretch::geometry::Size {
9921                    width: stretch::style::Dimension::Points(100.0000),
9922                    ..Default::default()
9923                },
9924                min_size: stretch::geometry::Size {
9925                    height: stretch::style::Dimension::Points(100.0000),
9926                    ..Default::default()
9927                },
9928                max_size: stretch::geometry::Size {
9929                    height: stretch::style::Dimension::Points(200.0000),
9930                    ..Default::default()
9931                },
9932                children: vec![stretch::style::Node {
9933                    size: stretch::geometry::Size {
9934                        width: stretch::style::Dimension::Points(60.0000),
9935                        height: stretch::style::Dimension::Points(60.0000),
9936                        ..Default::default()
9937                    },
9938                    ..Default::default()
9939                }],
9940                ..Default::default()
9941            },
9942            stretch::geometry::Size::undefined(),
9943        )
9944        .unwrap();
9945
9946        assert_eq!(layout.size.width, 100.0000);
9947        assert_eq!(layout.size.height, 100.0000);
9948        assert_eq!(layout.location.x, 0.0000);
9949        assert_eq!(layout.location.y, 0.0000);
9950
9951        assert_eq!(layout.children[0].size.width, 60.0000);
9952        assert_eq!(layout.children[0].size.height, 60.0000);
9953        assert_eq!(layout.children[0].location.x, 0.0000);
9954        assert_eq!(layout.children[0].location.y, 20.0000);
9955    }
9956
9957    #[test]
9958    fn padding_align_end_child() {
9959        let layout = stretch::compute(
9960            &stretch::style::Node {
9961                align_items: stretch::style::AlignItems::FlexEnd,
9962                justify_content: stretch::style::JustifyContent::FlexEnd,
9963                size: stretch::geometry::Size {
9964                    width: stretch::style::Dimension::Points(200.0000),
9965                    height: stretch::style::Dimension::Points(200.0000),
9966                    ..Default::default()
9967                },
9968                children: vec![stretch::style::Node {
9969                    size: stretch::geometry::Size {
9970                        width: stretch::style::Dimension::Points(100.0000),
9971                        height: stretch::style::Dimension::Points(100.0000),
9972                        ..Default::default()
9973                    },
9974                    padding: stretch::geometry::Rect {
9975                        start: stretch::style::Dimension::Points(20.0000),
9976                        end: stretch::style::Dimension::Points(20.0000),
9977                        top: stretch::style::Dimension::Points(20.0000),
9978                        bottom: stretch::style::Dimension::Points(20.0000),
9979                        ..Default::default()
9980                    },
9981                    ..Default::default()
9982                }],
9983                ..Default::default()
9984            },
9985            stretch::geometry::Size::undefined(),
9986        )
9987        .unwrap();
9988
9989        assert_eq!(layout.size.width, 200.0000);
9990        assert_eq!(layout.size.height, 200.0000);
9991        assert_eq!(layout.location.x, 0.0000);
9992        assert_eq!(layout.location.y, 0.0000);
9993
9994        assert_eq!(layout.children[0].size.width, 100.0000);
9995        assert_eq!(layout.children[0].size.height, 100.0000);
9996        assert_eq!(layout.children[0].location.x, 100.0000);
9997        assert_eq!(layout.children[0].location.y, 100.0000);
9998    }
9999
10000    #[test]
10001    fn justify_content_row_space_between() {
10002        let layout = stretch::compute(
10003            &stretch::style::Node {
10004                justify_content: stretch::style::JustifyContent::SpaceBetween,
10005                size: stretch::geometry::Size {
10006                    width: stretch::style::Dimension::Points(100.0000),
10007                    height: stretch::style::Dimension::Points(100.0000),
10008                    ..Default::default()
10009                },
10010                children: vec![
10011                    stretch::style::Node {
10012                        size: stretch::geometry::Size {
10013                            width: stretch::style::Dimension::Points(10.0000),
10014                            ..Default::default()
10015                        },
10016                        ..Default::default()
10017                    },
10018                    stretch::style::Node {
10019                        size: stretch::geometry::Size {
10020                            width: stretch::style::Dimension::Points(10.0000),
10021                            ..Default::default()
10022                        },
10023                        ..Default::default()
10024                    },
10025                    stretch::style::Node {
10026                        size: stretch::geometry::Size {
10027                            width: stretch::style::Dimension::Points(10.0000),
10028                            ..Default::default()
10029                        },
10030                        ..Default::default()
10031                    },
10032                ],
10033                ..Default::default()
10034            },
10035            stretch::geometry::Size::undefined(),
10036        )
10037        .unwrap();
10038
10039        assert_eq!(layout.size.width, 100.0000);
10040        assert_eq!(layout.size.height, 100.0000);
10041        assert_eq!(layout.location.x, 0.0000);
10042        assert_eq!(layout.location.y, 0.0000);
10043
10044        assert_eq!(layout.children[0].size.width, 10.0000);
10045        assert_eq!(layout.children[0].size.height, 100.0000);
10046        assert_eq!(layout.children[0].location.x, 0.0000);
10047        assert_eq!(layout.children[0].location.y, 0.0000);
10048
10049        assert_eq!(layout.children[1].size.width, 10.0000);
10050        assert_eq!(layout.children[1].size.height, 100.0000);
10051        assert_eq!(layout.children[1].location.x, 45.0000);
10052        assert_eq!(layout.children[1].location.y, 0.0000);
10053
10054        assert_eq!(layout.children[2].size.width, 10.0000);
10055        assert_eq!(layout.children[2].size.height, 100.0000);
10056        assert_eq!(layout.children[2].location.x, 90.0000);
10057        assert_eq!(layout.children[2].location.y, 0.0000);
10058    }
10059
10060    #[test]
10061    fn align_self_baseline() {
10062        let layout = stretch::compute(
10063            &stretch::style::Node {
10064                size: stretch::geometry::Size {
10065                    width: stretch::style::Dimension::Points(100.0000),
10066                    height: stretch::style::Dimension::Points(100.0000),
10067                    ..Default::default()
10068                },
10069                children: vec![
10070                    stretch::style::Node {
10071                        align_self: stretch::style::AlignSelf::Baseline,
10072                        size: stretch::geometry::Size {
10073                            width: stretch::style::Dimension::Points(50.0000),
10074                            height: stretch::style::Dimension::Points(50.0000),
10075                            ..Default::default()
10076                        },
10077                        ..Default::default()
10078                    },
10079                    stretch::style::Node {
10080                        align_self: stretch::style::AlignSelf::Baseline,
10081                        size: stretch::geometry::Size {
10082                            width: stretch::style::Dimension::Points(50.0000),
10083                            height: stretch::style::Dimension::Points(20.0000),
10084                            ..Default::default()
10085                        },
10086                        children: vec![stretch::style::Node {
10087                            size: stretch::geometry::Size {
10088                                width: stretch::style::Dimension::Points(50.0000),
10089                                height: stretch::style::Dimension::Points(10.0000),
10090                                ..Default::default()
10091                            },
10092                            ..Default::default()
10093                        }],
10094                        ..Default::default()
10095                    },
10096                ],
10097                ..Default::default()
10098            },
10099            stretch::geometry::Size::undefined(),
10100        )
10101        .unwrap();
10102
10103        assert_eq!(layout.size.width, 100.0000);
10104        assert_eq!(layout.size.height, 100.0000);
10105        assert_eq!(layout.location.x, 0.0000);
10106        assert_eq!(layout.location.y, 0.0000);
10107
10108        assert_eq!(layout.children[0].size.width, 50.0000);
10109        assert_eq!(layout.children[0].size.height, 50.0000);
10110        assert_eq!(layout.children[0].location.x, 0.0000);
10111        assert_eq!(layout.children[0].location.y, 0.0000);
10112
10113        assert_eq!(layout.children[1].size.width, 50.0000);
10114        assert_eq!(layout.children[1].size.height, 20.0000);
10115        assert_eq!(layout.children[1].location.x, 50.0000);
10116        assert_eq!(layout.children[1].location.y, 40.0000);
10117
10118        assert_eq!(layout.children[1].children[0].size.width, 50.0000);
10119        assert_eq!(layout.children[1].children[0].size.height, 10.0000);
10120        assert_eq!(layout.children[1].children[0].location.x, 0.0000);
10121        assert_eq!(layout.children[1].children[0].location.y, 0.0000);
10122    }
10123
10124    #[test]
10125    fn rounding_fractial_input_1() {
10126        let layout = stretch::compute(
10127            &stretch::style::Node {
10128                flex_direction: stretch::style::FlexDirection::Column,
10129                size: stretch::geometry::Size {
10130                    width: stretch::style::Dimension::Points(100.0000),
10131                    height: stretch::style::Dimension::Points(113.4000),
10132                    ..Default::default()
10133                },
10134                children: vec![
10135                    stretch::style::Node {
10136                        flex_grow: 1.0000,
10137                        flex_basis: stretch::style::Dimension::Points(50.0000),
10138                        size: stretch::geometry::Size {
10139                            height: stretch::style::Dimension::Points(20.0000),
10140                            ..Default::default()
10141                        },
10142                        ..Default::default()
10143                    },
10144                    stretch::style::Node {
10145                        flex_grow: 1.0000,
10146                        size: stretch::geometry::Size {
10147                            height: stretch::style::Dimension::Points(10.0000),
10148                            ..Default::default()
10149                        },
10150                        ..Default::default()
10151                    },
10152                    stretch::style::Node {
10153                        flex_grow: 1.0000,
10154                        size: stretch::geometry::Size {
10155                            height: stretch::style::Dimension::Points(10.0000),
10156                            ..Default::default()
10157                        },
10158                        ..Default::default()
10159                    },
10160                ],
10161                ..Default::default()
10162            },
10163            stretch::geometry::Size::undefined(),
10164        )
10165        .unwrap();
10166
10167        assert_eq!(layout.size.width, 100.0000);
10168        assert_eq!(layout.size.height, 113.0000);
10169        assert_eq!(layout.location.x, 0.0000);
10170        assert_eq!(layout.location.y, 0.0000);
10171
10172        assert_eq!(layout.children[0].size.width, 100.0000);
10173        assert_eq!(layout.children[0].size.height, 64.0000);
10174        assert_eq!(layout.children[0].location.x, 0.0000);
10175        assert_eq!(layout.children[0].location.y, 0.0000);
10176
10177        assert_eq!(layout.children[1].size.width, 100.0000);
10178        assert_eq!(layout.children[1].size.height, 25.0000);
10179        assert_eq!(layout.children[1].location.x, 0.0000);
10180        assert_eq!(layout.children[1].location.y, 64.0000);
10181
10182        assert_eq!(layout.children[2].size.width, 100.0000);
10183        assert_eq!(layout.children[2].size.height, 24.0000);
10184        assert_eq!(layout.children[2].location.x, 0.0000);
10185        assert_eq!(layout.children[2].location.y, 89.0000);
10186    }
10187
10188    #[test]
10189    fn absolute_layout_align_items_center() {
10190        let layout = stretch::compute(
10191            &stretch::style::Node {
10192                align_items: stretch::style::AlignItems::Center,
10193                size: stretch::geometry::Size {
10194                    width: stretch::style::Dimension::Points(110.0000),
10195                    height: stretch::style::Dimension::Points(100.0000),
10196                    ..Default::default()
10197                },
10198                children: vec![stretch::style::Node {
10199                    position_type: stretch::style::PositionType::Absolute,
10200                    size: stretch::geometry::Size {
10201                        width: stretch::style::Dimension::Points(60.0000),
10202                        height: stretch::style::Dimension::Points(40.0000),
10203                        ..Default::default()
10204                    },
10205                    ..Default::default()
10206                }],
10207                ..Default::default()
10208            },
10209            stretch::geometry::Size::undefined(),
10210        )
10211        .unwrap();
10212
10213        assert_eq!(layout.size.width, 110.0000);
10214        assert_eq!(layout.size.height, 100.0000);
10215        assert_eq!(layout.location.x, 0.0000);
10216        assert_eq!(layout.location.y, 0.0000);
10217
10218        assert_eq!(layout.children[0].size.width, 60.0000);
10219        assert_eq!(layout.children[0].size.height, 40.0000);
10220        assert_eq!(layout.children[0].location.x, 0.0000);
10221        assert_eq!(layout.children[0].location.y, 30.0000);
10222    }
10223
10224    #[test]
10225    fn flex_basis_slightly_smaller_then_content_with_flex_grow_large_size() {
10226        let layout = stretch::compute(
10227            &stretch::style::Node {
10228                size: stretch::geometry::Size {
10229                    width: stretch::style::Dimension::Points(100.0000),
10230                    ..Default::default()
10231                },
10232                children: vec![
10233                    stretch::style::Node {
10234                        flex_direction: stretch::style::FlexDirection::Column,
10235                        flex_grow: 1.0000,
10236                        flex_basis: stretch::style::Dimension::Points(60.0000),
10237                        children: vec![stretch::style::Node {
10238                            size: stretch::geometry::Size {
10239                                width: stretch::style::Dimension::Points(70.0000),
10240                                height: stretch::style::Dimension::Points(100.0000),
10241                                ..Default::default()
10242                            },
10243                            ..Default::default()
10244                        }],
10245                        ..Default::default()
10246                    },
10247                    stretch::style::Node {
10248                        flex_direction: stretch::style::FlexDirection::Column,
10249                        flex_grow: 1.0000,
10250                        flex_basis: stretch::style::Dimension::Points(0.0000),
10251                        children: vec![stretch::style::Node {
10252                            size: stretch::geometry::Size {
10253                                width: stretch::style::Dimension::Points(20.0000),
10254                                height: stretch::style::Dimension::Points(100.0000),
10255                                ..Default::default()
10256                            },
10257                            ..Default::default()
10258                        }],
10259                        ..Default::default()
10260                    },
10261                ],
10262                ..Default::default()
10263            },
10264            stretch::geometry::Size::undefined(),
10265        )
10266        .unwrap();
10267
10268        assert_eq!(layout.size.width, 100.0000);
10269        assert_eq!(layout.size.height, 100.0000);
10270        assert_eq!(layout.location.x, 0.0000);
10271        assert_eq!(layout.location.y, 0.0000);
10272
10273        assert_eq!(layout.children[0].size.width, 80.0000);
10274        assert_eq!(layout.children[0].size.height, 100.0000);
10275        assert_eq!(layout.children[0].location.x, 0.0000);
10276        assert_eq!(layout.children[0].location.y, 0.0000);
10277
10278        assert_eq!(layout.children[0].children[0].size.width, 70.0000);
10279        assert_eq!(layout.children[0].children[0].size.height, 100.0000);
10280        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
10281        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
10282
10283        assert_eq!(layout.children[1].size.width, 20.0000);
10284        assert_eq!(layout.children[1].size.height, 100.0000);
10285        assert_eq!(layout.children[1].location.x, 80.0000);
10286        assert_eq!(layout.children[1].location.y, 0.0000);
10287
10288        assert_eq!(layout.children[1].children[0].size.width, 20.0000);
10289        assert_eq!(layout.children[1].children[0].size.height, 100.0000);
10290        assert_eq!(layout.children[1].children[0].location.x, 0.0000);
10291        assert_eq!(layout.children[1].children[0].location.y, 0.0000);
10292    }
10293
10294    #[test]
10295    fn percentage_flex_basis_cross_min_width() {
10296        let layout = stretch::compute(
10297            &stretch::style::Node {
10298                flex_direction: stretch::style::FlexDirection::Column,
10299                size: stretch::geometry::Size {
10300                    width: stretch::style::Dimension::Points(200.0000),
10301                    height: stretch::style::Dimension::Points(400.0000),
10302                    ..Default::default()
10303                },
10304                children: vec![
10305                    stretch::style::Node {
10306                        flex_grow: 1.0000,
10307                        flex_basis: stretch::style::Dimension::Percent(0.1000),
10308                        min_size: stretch::geometry::Size {
10309                            width: stretch::style::Dimension::Percent(0.6000),
10310                            ..Default::default()
10311                        },
10312                        ..Default::default()
10313                    },
10314                    stretch::style::Node {
10315                        flex_grow: 4.0000,
10316                        flex_basis: stretch::style::Dimension::Percent(0.1500),
10317                        min_size: stretch::geometry::Size {
10318                            width: stretch::style::Dimension::Percent(0.2000),
10319                            ..Default::default()
10320                        },
10321                        ..Default::default()
10322                    },
10323                ],
10324                ..Default::default()
10325            },
10326            stretch::geometry::Size::undefined(),
10327        )
10328        .unwrap();
10329
10330        assert_eq!(layout.size.width, 200.0000);
10331        assert_eq!(layout.size.height, 400.0000);
10332        assert_eq!(layout.location.x, 0.0000);
10333        assert_eq!(layout.location.y, 0.0000);
10334
10335        assert_eq!(layout.children[0].size.width, 200.0000);
10336        assert_eq!(layout.children[0].size.height, 100.0000);
10337        assert_eq!(layout.children[0].location.x, 0.0000);
10338        assert_eq!(layout.children[0].location.y, 0.0000);
10339
10340        assert_eq!(layout.children[1].size.width, 200.0000);
10341        assert_eq!(layout.children[1].size.height, 300.0000);
10342        assert_eq!(layout.children[1].location.x, 0.0000);
10343        assert_eq!(layout.children[1].location.y, 100.0000);
10344    }
10345
10346    #[test]
10347    fn margin_auto_left_and_right_column_and_center() {
10348        let layout = stretch::compute(
10349            &stretch::style::Node {
10350                align_items: stretch::style::AlignItems::Center,
10351                size: stretch::geometry::Size {
10352                    width: stretch::style::Dimension::Points(200.0000),
10353                    height: stretch::style::Dimension::Points(200.0000),
10354                    ..Default::default()
10355                },
10356                children: vec![
10357                    stretch::style::Node {
10358                        size: stretch::geometry::Size {
10359                            width: stretch::style::Dimension::Points(50.0000),
10360                            height: stretch::style::Dimension::Points(50.0000),
10361                            ..Default::default()
10362                        },
10363                        margin: stretch::geometry::Rect {
10364                            start: stretch::style::Dimension::Auto,
10365                            end: stretch::style::Dimension::Auto,
10366                            ..Default::default()
10367                        },
10368                        ..Default::default()
10369                    },
10370                    stretch::style::Node {
10371                        size: stretch::geometry::Size {
10372                            width: stretch::style::Dimension::Points(50.0000),
10373                            height: stretch::style::Dimension::Points(50.0000),
10374                            ..Default::default()
10375                        },
10376                        ..Default::default()
10377                    },
10378                ],
10379                ..Default::default()
10380            },
10381            stretch::geometry::Size::undefined(),
10382        )
10383        .unwrap();
10384
10385        assert_eq!(layout.size.width, 200.0000);
10386        assert_eq!(layout.size.height, 200.0000);
10387        assert_eq!(layout.location.x, 0.0000);
10388        assert_eq!(layout.location.y, 0.0000);
10389
10390        assert_eq!(layout.children[0].size.width, 50.0000);
10391        assert_eq!(layout.children[0].size.height, 50.0000);
10392        assert_eq!(layout.children[0].location.x, 50.0000);
10393        assert_eq!(layout.children[0].location.y, 75.0000);
10394
10395        assert_eq!(layout.children[1].size.width, 50.0000);
10396        assert_eq!(layout.children[1].size.height, 50.0000);
10397        assert_eq!(layout.children[1].location.x, 150.0000);
10398        assert_eq!(layout.children[1].location.y, 75.0000);
10399    }
10400
10401    #[test]
10402    fn flex_grow_less_than_factor_one() {
10403        let layout = stretch::compute(
10404            &stretch::style::Node {
10405                size: stretch::geometry::Size {
10406                    width: stretch::style::Dimension::Points(500.0000),
10407                    height: stretch::style::Dimension::Points(200.0000),
10408                    ..Default::default()
10409                },
10410                children: vec![
10411                    stretch::style::Node {
10412                        flex_grow: 0.2000,
10413                        flex_shrink: 0.0000,
10414                        flex_basis: stretch::style::Dimension::Points(40.0000),
10415                        ..Default::default()
10416                    },
10417                    stretch::style::Node { flex_grow: 0.2000, flex_shrink: 0.0000, ..Default::default() },
10418                    stretch::style::Node { flex_grow: 0.4000, flex_shrink: 0.0000, ..Default::default() },
10419                ],
10420                ..Default::default()
10421            },
10422            stretch::geometry::Size::undefined(),
10423        )
10424        .unwrap();
10425
10426        assert_eq!(layout.size.width, 500.0000);
10427        assert_eq!(layout.size.height, 200.0000);
10428        assert_eq!(layout.location.x, 0.0000);
10429        assert_eq!(layout.location.y, 0.0000);
10430
10431        assert_eq!(layout.children[0].size.width, 132.0000);
10432        assert_eq!(layout.children[0].size.height, 200.0000);
10433        assert_eq!(layout.children[0].location.x, 0.0000);
10434        assert_eq!(layout.children[0].location.y, 0.0000);
10435
10436        assert_eq!(layout.children[1].size.width, 92.0000);
10437        assert_eq!(layout.children[1].size.height, 200.0000);
10438        assert_eq!(layout.children[1].location.x, 132.0000);
10439        assert_eq!(layout.children[1].location.y, 0.0000);
10440
10441        assert_eq!(layout.children[2].size.width, 184.0000);
10442        assert_eq!(layout.children[2].size.height, 200.0000);
10443        assert_eq!(layout.children[2].location.x, 224.0000);
10444        assert_eq!(layout.children[2].location.y, 0.0000);
10445    }
10446
10447    #[test]
10448    fn flex_grow_within_constrained_min_max_column() {
10449        let layout = stretch::compute(
10450            &stretch::style::Node {
10451                min_size: stretch::geometry::Size {
10452                    height: stretch::style::Dimension::Points(100.0000),
10453                    ..Default::default()
10454                },
10455                children: vec![
10456                    stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
10457                    stretch::style::Node {
10458                        size: stretch::geometry::Size {
10459                            height: stretch::style::Dimension::Points(50.0000),
10460                            ..Default::default()
10461                        },
10462                        ..Default::default()
10463                    },
10464                ],
10465                ..Default::default()
10466            },
10467            stretch::geometry::Size::undefined(),
10468        )
10469        .unwrap();
10470
10471        assert_eq!(layout.size.width, 0.0000);
10472        assert_eq!(layout.size.height, 100.0000);
10473        assert_eq!(layout.location.x, 0.0000);
10474        assert_eq!(layout.location.y, 0.0000);
10475
10476        assert_eq!(layout.children[0].size.width, 0.0000);
10477        assert_eq!(layout.children[0].size.height, 100.0000);
10478        assert_eq!(layout.children[0].location.x, 0.0000);
10479        assert_eq!(layout.children[0].location.y, 0.0000);
10480
10481        assert_eq!(layout.children[1].size.width, 0.0000);
10482        assert_eq!(layout.children[1].size.height, 50.0000);
10483        assert_eq!(layout.children[1].location.x, 0.0000);
10484        assert_eq!(layout.children[1].location.y, 0.0000);
10485    }
10486
10487    #[test]
10488    fn percentage_flex_basis_cross_max_height() {
10489        let layout = stretch::compute(
10490            &stretch::style::Node {
10491                flex_direction: stretch::style::FlexDirection::Column,
10492                size: stretch::geometry::Size {
10493                    width: stretch::style::Dimension::Points(200.0000),
10494                    height: stretch::style::Dimension::Points(400.0000),
10495                    ..Default::default()
10496                },
10497                children: vec![
10498                    stretch::style::Node {
10499                        flex_grow: 1.0000,
10500                        flex_basis: stretch::style::Dimension::Percent(0.1000),
10501                        max_size: stretch::geometry::Size {
10502                            height: stretch::style::Dimension::Percent(0.6000),
10503                            ..Default::default()
10504                        },
10505                        ..Default::default()
10506                    },
10507                    stretch::style::Node {
10508                        flex_grow: 4.0000,
10509                        flex_basis: stretch::style::Dimension::Percent(0.1000),
10510                        max_size: stretch::geometry::Size {
10511                            height: stretch::style::Dimension::Percent(0.2000),
10512                            ..Default::default()
10513                        },
10514                        ..Default::default()
10515                    },
10516                ],
10517                ..Default::default()
10518            },
10519            stretch::geometry::Size::undefined(),
10520        )
10521        .unwrap();
10522
10523        assert_eq!(layout.size.width, 200.0000);
10524        assert_eq!(layout.size.height, 400.0000);
10525        assert_eq!(layout.location.x, 0.0000);
10526        assert_eq!(layout.location.y, 0.0000);
10527
10528        assert_eq!(layout.children[0].size.width, 200.0000);
10529        assert_eq!(layout.children[0].size.height, 240.0000);
10530        assert_eq!(layout.children[0].location.x, 0.0000);
10531        assert_eq!(layout.children[0].location.y, 0.0000);
10532
10533        assert_eq!(layout.children[1].size.width, 200.0000);
10534        assert_eq!(layout.children[1].size.height, 80.0000);
10535        assert_eq!(layout.children[1].location.x, 0.0000);
10536        assert_eq!(layout.children[1].location.y, 240.0000);
10537    }
10538
10539    #[test]
10540    fn justify_content_column_flex_end() {
10541        let layout = stretch::compute(
10542            &stretch::style::Node {
10543                flex_direction: stretch::style::FlexDirection::Column,
10544                justify_content: stretch::style::JustifyContent::FlexEnd,
10545                size: stretch::geometry::Size {
10546                    width: stretch::style::Dimension::Points(100.0000),
10547                    height: stretch::style::Dimension::Points(100.0000),
10548                    ..Default::default()
10549                },
10550                children: vec![
10551                    stretch::style::Node {
10552                        size: stretch::geometry::Size {
10553                            height: stretch::style::Dimension::Points(10.0000),
10554                            ..Default::default()
10555                        },
10556                        ..Default::default()
10557                    },
10558                    stretch::style::Node {
10559                        size: stretch::geometry::Size {
10560                            height: stretch::style::Dimension::Points(10.0000),
10561                            ..Default::default()
10562                        },
10563                        ..Default::default()
10564                    },
10565                    stretch::style::Node {
10566                        size: stretch::geometry::Size {
10567                            height: stretch::style::Dimension::Points(10.0000),
10568                            ..Default::default()
10569                        },
10570                        ..Default::default()
10571                    },
10572                ],
10573                ..Default::default()
10574            },
10575            stretch::geometry::Size::undefined(),
10576        )
10577        .unwrap();
10578
10579        assert_eq!(layout.size.width, 100.0000);
10580        assert_eq!(layout.size.height, 100.0000);
10581        assert_eq!(layout.location.x, 0.0000);
10582        assert_eq!(layout.location.y, 0.0000);
10583
10584        assert_eq!(layout.children[0].size.width, 100.0000);
10585        assert_eq!(layout.children[0].size.height, 10.0000);
10586        assert_eq!(layout.children[0].location.x, 0.0000);
10587        assert_eq!(layout.children[0].location.y, 70.0000);
10588
10589        assert_eq!(layout.children[1].size.width, 100.0000);
10590        assert_eq!(layout.children[1].size.height, 10.0000);
10591        assert_eq!(layout.children[1].location.x, 0.0000);
10592        assert_eq!(layout.children[1].location.y, 80.0000);
10593
10594        assert_eq!(layout.children[2].size.width, 100.0000);
10595        assert_eq!(layout.children[2].size.height, 10.0000);
10596        assert_eq!(layout.children[2].location.x, 0.0000);
10597        assert_eq!(layout.children[2].location.y, 90.0000);
10598    }
10599
10600    #[test]
10601    fn rounding_flex_basis_flex_grow_row_width_of_100() {
10602        let layout = stretch::compute(
10603            &stretch::style::Node {
10604                size: stretch::geometry::Size {
10605                    width: stretch::style::Dimension::Points(100.0000),
10606                    height: stretch::style::Dimension::Points(100.0000),
10607                    ..Default::default()
10608                },
10609                children: vec![
10610                    stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
10611                    stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
10612                    stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
10613                ],
10614                ..Default::default()
10615            },
10616            stretch::geometry::Size::undefined(),
10617        )
10618        .unwrap();
10619
10620        assert_eq!(layout.size.width, 100.0000);
10621        assert_eq!(layout.size.height, 100.0000);
10622        assert_eq!(layout.location.x, 0.0000);
10623        assert_eq!(layout.location.y, 0.0000);
10624
10625        assert_eq!(layout.children[0].size.width, 33.0000);
10626        assert_eq!(layout.children[0].size.height, 100.0000);
10627        assert_eq!(layout.children[0].location.x, 0.0000);
10628        assert_eq!(layout.children[0].location.y, 0.0000);
10629
10630        assert_eq!(layout.children[1].size.width, 34.0000);
10631        assert_eq!(layout.children[1].size.height, 100.0000);
10632        assert_eq!(layout.children[1].location.x, 33.0000);
10633        assert_eq!(layout.children[1].location.y, 0.0000);
10634
10635        assert_eq!(layout.children[2].size.width, 33.0000);
10636        assert_eq!(layout.children[2].size.height, 100.0000);
10637        assert_eq!(layout.children[2].location.x, 67.0000);
10638        assert_eq!(layout.children[2].location.y, 0.0000);
10639    }
10640
10641    #[test]
10642    fn display_none_fixed_size() {
10643        let layout = stretch::compute(
10644            &stretch::style::Node {
10645                size: stretch::geometry::Size {
10646                    width: stretch::style::Dimension::Points(100.0000),
10647                    height: stretch::style::Dimension::Points(100.0000),
10648                    ..Default::default()
10649                },
10650                children: vec![
10651                    stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
10652                    stretch::style::Node {
10653                        display: stretch::style::Display::None,
10654                        size: stretch::geometry::Size {
10655                            width: stretch::style::Dimension::Points(20.0000),
10656                            height: stretch::style::Dimension::Points(20.0000),
10657                            ..Default::default()
10658                        },
10659                        ..Default::default()
10660                    },
10661                ],
10662                ..Default::default()
10663            },
10664            stretch::geometry::Size::undefined(),
10665        )
10666        .unwrap();
10667
10668        assert_eq!(layout.size.width, 100.0000);
10669        assert_eq!(layout.size.height, 100.0000);
10670        assert_eq!(layout.location.x, 0.0000);
10671        assert_eq!(layout.location.y, 0.0000);
10672
10673        assert_eq!(layout.children[0].size.width, 100.0000);
10674        assert_eq!(layout.children[0].size.height, 100.0000);
10675        assert_eq!(layout.children[0].location.x, 0.0000);
10676        assert_eq!(layout.children[0].location.y, 0.0000);
10677
10678        assert_eq!(layout.children[1].size.width, 0.0000);
10679        assert_eq!(layout.children[1].size.height, 0.0000);
10680        assert_eq!(layout.children[1].location.x, 0.0000);
10681        assert_eq!(layout.children[1].location.y, 0.0000);
10682    }
10683
10684    #[test]
10685    fn wrap_reverse_row_align_content_flex_start() {
10686        let layout = stretch::compute(
10687            &stretch::style::Node {
10688                flex_wrap: stretch::style::FlexWrap::WrapReverse,
10689                align_content: stretch::style::AlignContent::FlexStart,
10690                size: stretch::geometry::Size {
10691                    width: stretch::style::Dimension::Points(100.0000),
10692                    ..Default::default()
10693                },
10694                children: vec![
10695                    stretch::style::Node {
10696                        size: stretch::geometry::Size {
10697                            width: stretch::style::Dimension::Points(30.0000),
10698                            height: stretch::style::Dimension::Points(10.0000),
10699                            ..Default::default()
10700                        },
10701                        ..Default::default()
10702                    },
10703                    stretch::style::Node {
10704                        size: stretch::geometry::Size {
10705                            width: stretch::style::Dimension::Points(30.0000),
10706                            height: stretch::style::Dimension::Points(20.0000),
10707                            ..Default::default()
10708                        },
10709                        ..Default::default()
10710                    },
10711                    stretch::style::Node {
10712                        size: stretch::geometry::Size {
10713                            width: stretch::style::Dimension::Points(30.0000),
10714                            height: stretch::style::Dimension::Points(30.0000),
10715                            ..Default::default()
10716                        },
10717                        ..Default::default()
10718                    },
10719                    stretch::style::Node {
10720                        size: stretch::geometry::Size {
10721                            width: stretch::style::Dimension::Points(30.0000),
10722                            height: stretch::style::Dimension::Points(40.0000),
10723                            ..Default::default()
10724                        },
10725                        ..Default::default()
10726                    },
10727                    stretch::style::Node {
10728                        size: stretch::geometry::Size {
10729                            width: stretch::style::Dimension::Points(30.0000),
10730                            height: stretch::style::Dimension::Points(50.0000),
10731                            ..Default::default()
10732                        },
10733                        ..Default::default()
10734                    },
10735                ],
10736                ..Default::default()
10737            },
10738            stretch::geometry::Size::undefined(),
10739        )
10740        .unwrap();
10741
10742        assert_eq!(layout.size.width, 100.0000);
10743        assert_eq!(layout.size.height, 80.0000);
10744        assert_eq!(layout.location.x, 0.0000);
10745        assert_eq!(layout.location.y, 0.0000);
10746
10747        assert_eq!(layout.children[0].size.width, 30.0000);
10748        assert_eq!(layout.children[0].size.height, 10.0000);
10749        assert_eq!(layout.children[0].location.x, 0.0000);
10750        assert_eq!(layout.children[0].location.y, 70.0000);
10751
10752        assert_eq!(layout.children[1].size.width, 30.0000);
10753        assert_eq!(layout.children[1].size.height, 20.0000);
10754        assert_eq!(layout.children[1].location.x, 30.0000);
10755        assert_eq!(layout.children[1].location.y, 60.0000);
10756
10757        assert_eq!(layout.children[2].size.width, 30.0000);
10758        assert_eq!(layout.children[2].size.height, 30.0000);
10759        assert_eq!(layout.children[2].location.x, 60.0000);
10760        assert_eq!(layout.children[2].location.y, 50.0000);
10761
10762        assert_eq!(layout.children[3].size.width, 30.0000);
10763        assert_eq!(layout.children[3].size.height, 40.0000);
10764        assert_eq!(layout.children[3].location.x, 0.0000);
10765        assert_eq!(layout.children[3].location.y, 10.0000);
10766
10767        assert_eq!(layout.children[4].size.width, 30.0000);
10768        assert_eq!(layout.children[4].size.height, 50.0000);
10769        assert_eq!(layout.children[4].location.x, 30.0000);
10770        assert_eq!(layout.children[4].location.y, 0.0000);
10771    }
10772
10773    #[test]
10774    fn flex_shrink_flex_grow_child_flex_shrink_other_child() {
10775        let layout = stretch::compute(
10776            &stretch::style::Node {
10777                size: stretch::geometry::Size {
10778                    width: stretch::style::Dimension::Points(500.0000),
10779                    height: stretch::style::Dimension::Points(500.0000),
10780                    ..Default::default()
10781                },
10782                children: vec![
10783                    stretch::style::Node {
10784                        flex_grow: 0.0000,
10785                        flex_shrink: 1.0000,
10786                        size: stretch::geometry::Size {
10787                            width: stretch::style::Dimension::Points(500.0000),
10788                            height: stretch::style::Dimension::Points(100.0000),
10789                            ..Default::default()
10790                        },
10791                        ..Default::default()
10792                    },
10793                    stretch::style::Node {
10794                        flex_grow: 1.0000,
10795                        flex_shrink: 1.0000,
10796                        size: stretch::geometry::Size {
10797                            width: stretch::style::Dimension::Points(500.0000),
10798                            height: stretch::style::Dimension::Points(100.0000),
10799                            ..Default::default()
10800                        },
10801                        ..Default::default()
10802                    },
10803                ],
10804                ..Default::default()
10805            },
10806            stretch::geometry::Size::undefined(),
10807        )
10808        .unwrap();
10809
10810        assert_eq!(layout.size.width, 500.0000);
10811        assert_eq!(layout.size.height, 500.0000);
10812        assert_eq!(layout.location.x, 0.0000);
10813        assert_eq!(layout.location.y, 0.0000);
10814
10815        assert_eq!(layout.children[0].size.width, 250.0000);
10816        assert_eq!(layout.children[0].size.height, 100.0000);
10817        assert_eq!(layout.children[0].location.x, 0.0000);
10818        assert_eq!(layout.children[0].location.y, 0.0000);
10819
10820        assert_eq!(layout.children[1].size.width, 250.0000);
10821        assert_eq!(layout.children[1].size.height, 100.0000);
10822        assert_eq!(layout.children[1].location.x, 250.0000);
10823        assert_eq!(layout.children[1].location.y, 0.0000);
10824    }
10825
10826    #[test]
10827    fn flex_basis_unconstraint_row() {
10828        let layout = stretch::compute(
10829            &stretch::style::Node {
10830                children: vec![stretch::style::Node {
10831                    flex_basis: stretch::style::Dimension::Points(50.0000),
10832                    size: stretch::geometry::Size {
10833                        height: stretch::style::Dimension::Points(100.0000),
10834                        ..Default::default()
10835                    },
10836                    ..Default::default()
10837                }],
10838                ..Default::default()
10839            },
10840            stretch::geometry::Size::undefined(),
10841        )
10842        .unwrap();
10843
10844        assert_eq!(layout.size.width, 0.0000);
10845        assert_eq!(layout.size.height, 100.0000);
10846        assert_eq!(layout.location.x, 0.0000);
10847        assert_eq!(layout.location.y, 0.0000);
10848
10849        assert_eq!(layout.children[0].size.width, 0.0000);
10850        assert_eq!(layout.children[0].size.height, 100.0000);
10851        assert_eq!(layout.children[0].location.x, 0.0000);
10852        assert_eq!(layout.children[0].location.y, 0.0000);
10853    }
10854
10855    #[test]
10856    fn align_items_flex_end() {
10857        let layout = stretch::compute(
10858            &stretch::style::Node {
10859                align_items: stretch::style::AlignItems::FlexEnd,
10860                size: stretch::geometry::Size {
10861                    width: stretch::style::Dimension::Points(100.0000),
10862                    height: stretch::style::Dimension::Points(100.0000),
10863                    ..Default::default()
10864                },
10865                children: vec![stretch::style::Node {
10866                    size: stretch::geometry::Size {
10867                        width: stretch::style::Dimension::Points(10.0000),
10868                        height: stretch::style::Dimension::Points(10.0000),
10869                        ..Default::default()
10870                    },
10871                    ..Default::default()
10872                }],
10873                ..Default::default()
10874            },
10875            stretch::geometry::Size::undefined(),
10876        )
10877        .unwrap();
10878
10879        assert_eq!(layout.size.width, 100.0000);
10880        assert_eq!(layout.size.height, 100.0000);
10881        assert_eq!(layout.location.x, 0.0000);
10882        assert_eq!(layout.location.y, 0.0000);
10883
10884        assert_eq!(layout.children[0].size.width, 10.0000);
10885        assert_eq!(layout.children[0].size.height, 10.0000);
10886        assert_eq!(layout.children[0].location.x, 0.0000);
10887        assert_eq!(layout.children[0].location.y, 90.0000);
10888    }
10889
10890    #[test]
10891    fn absolute_layout_width_height_start_top() {
10892        let layout = stretch::compute(
10893            &stretch::style::Node {
10894                size: stretch::geometry::Size {
10895                    width: stretch::style::Dimension::Points(100.0000),
10896                    height: stretch::style::Dimension::Points(100.0000),
10897                    ..Default::default()
10898                },
10899                children: vec![stretch::style::Node {
10900                    position_type: stretch::style::PositionType::Absolute,
10901                    size: stretch::geometry::Size {
10902                        width: stretch::style::Dimension::Points(10.0000),
10903                        height: stretch::style::Dimension::Points(10.0000),
10904                        ..Default::default()
10905                    },
10906                    position: stretch::geometry::Rect {
10907                        start: stretch::style::Dimension::Points(10.0000),
10908                        top: stretch::style::Dimension::Points(10.0000),
10909                        ..Default::default()
10910                    },
10911                    ..Default::default()
10912                }],
10913                ..Default::default()
10914            },
10915            stretch::geometry::Size::undefined(),
10916        )
10917        .unwrap();
10918
10919        assert_eq!(layout.size.width, 100.0000);
10920        assert_eq!(layout.size.height, 100.0000);
10921        assert_eq!(layout.location.x, 0.0000);
10922        assert_eq!(layout.location.y, 0.0000);
10923
10924        assert_eq!(layout.children[0].size.width, 10.0000);
10925        assert_eq!(layout.children[0].size.height, 10.0000);
10926        assert_eq!(layout.children[0].location.x, 10.0000);
10927        assert_eq!(layout.children[0].location.y, 10.0000);
10928    }
10929
10930    #[test]
10931    fn rounding_flex_basis_flex_shrink_row() {
10932        let layout = stretch::compute(
10933            &stretch::style::Node {
10934                size: stretch::geometry::Size {
10935                    width: stretch::style::Dimension::Points(101.0000),
10936                    height: stretch::style::Dimension::Points(100.0000),
10937                    ..Default::default()
10938                },
10939                children: vec![
10940                    stretch::style::Node {
10941                        flex_shrink: 1.0000,
10942                        flex_basis: stretch::style::Dimension::Points(100.0000),
10943                        ..Default::default()
10944                    },
10945                    stretch::style::Node {
10946                        flex_basis: stretch::style::Dimension::Points(25.0000),
10947                        ..Default::default()
10948                    },
10949                    stretch::style::Node {
10950                        flex_basis: stretch::style::Dimension::Points(25.0000),
10951                        ..Default::default()
10952                    },
10953                ],
10954                ..Default::default()
10955            },
10956            stretch::geometry::Size::undefined(),
10957        )
10958        .unwrap();
10959
10960        assert_eq!(layout.size.width, 101.0000);
10961        assert_eq!(layout.size.height, 100.0000);
10962        assert_eq!(layout.location.x, 0.0000);
10963        assert_eq!(layout.location.y, 0.0000);
10964
10965        assert_eq!(layout.children[0].size.width, 67.0000);
10966        assert_eq!(layout.children[0].size.height, 100.0000);
10967        assert_eq!(layout.children[0].location.x, 0.0000);
10968        assert_eq!(layout.children[0].location.y, 0.0000);
10969
10970        assert_eq!(layout.children[1].size.width, 17.0000);
10971        assert_eq!(layout.children[1].size.height, 100.0000);
10972        assert_eq!(layout.children[1].location.x, 67.0000);
10973        assert_eq!(layout.children[1].location.y, 0.0000);
10974
10975        assert_eq!(layout.children[2].size.width, 17.0000);
10976        assert_eq!(layout.children[2].size.height, 100.0000);
10977        assert_eq!(layout.children[2].location.x, 84.0000);
10978        assert_eq!(layout.children[2].location.y, 0.0000);
10979    }
10980
10981    #[test]
10982    fn border_center_child() {
10983        let layout = stretch::compute(
10984            &stretch::style::Node {
10985                align_items: stretch::style::AlignItems::Center,
10986                justify_content: stretch::style::JustifyContent::Center,
10987                size: stretch::geometry::Size {
10988                    width: stretch::style::Dimension::Points(100.0000),
10989                    height: stretch::style::Dimension::Points(100.0000),
10990                    ..Default::default()
10991                },
10992                border: stretch::geometry::Rect {
10993                    top: stretch::style::Dimension::Points(10.0000),
10994                    bottom: stretch::style::Dimension::Points(20.0000),
10995                    ..Default::default()
10996                },
10997                children: vec![stretch::style::Node {
10998                    size: stretch::geometry::Size {
10999                        width: stretch::style::Dimension::Points(10.0000),
11000                        height: stretch::style::Dimension::Points(10.0000),
11001                        ..Default::default()
11002                    },
11003                    ..Default::default()
11004                }],
11005                ..Default::default()
11006            },
11007            stretch::geometry::Size::undefined(),
11008        )
11009        .unwrap();
11010
11011        assert_eq!(layout.size.width, 100.0000);
11012        assert_eq!(layout.size.height, 100.0000);
11013        assert_eq!(layout.location.x, 0.0000);
11014        assert_eq!(layout.location.y, 0.0000);
11015
11016        assert_eq!(layout.children[0].size.width, 10.0000);
11017        assert_eq!(layout.children[0].size.height, 10.0000);
11018        assert_eq!(layout.children[0].location.x, 45.0000);
11019        assert_eq!(layout.children[0].location.y, 40.0000);
11020    }
11021
11022    #[test]
11023    fn align_items_flex_start() {
11024        let layout = stretch::compute(
11025            &stretch::style::Node {
11026                align_items: stretch::style::AlignItems::FlexStart,
11027                size: stretch::geometry::Size {
11028                    width: stretch::style::Dimension::Points(100.0000),
11029                    height: stretch::style::Dimension::Points(100.0000),
11030                    ..Default::default()
11031                },
11032                children: vec![stretch::style::Node {
11033                    size: stretch::geometry::Size {
11034                        width: stretch::style::Dimension::Points(10.0000),
11035                        height: stretch::style::Dimension::Points(10.0000),
11036                        ..Default::default()
11037                    },
11038                    ..Default::default()
11039                }],
11040                ..Default::default()
11041            },
11042            stretch::geometry::Size::undefined(),
11043        )
11044        .unwrap();
11045
11046        assert_eq!(layout.size.width, 100.0000);
11047        assert_eq!(layout.size.height, 100.0000);
11048        assert_eq!(layout.location.x, 0.0000);
11049        assert_eq!(layout.location.y, 0.0000);
11050
11051        assert_eq!(layout.children[0].size.width, 10.0000);
11052        assert_eq!(layout.children[0].size.height, 10.0000);
11053        assert_eq!(layout.children[0].location.x, 0.0000);
11054        assert_eq!(layout.children[0].location.y, 0.0000);
11055    }
11056
11057    #[test]
11058    fn border_no_child() {
11059        let layout = stretch::compute(
11060            &stretch::style::Node {
11061                border: stretch::geometry::Rect {
11062                    start: stretch::style::Dimension::Points(10.0000),
11063                    end: stretch::style::Dimension::Points(10.0000),
11064                    top: stretch::style::Dimension::Points(10.0000),
11065                    bottom: stretch::style::Dimension::Points(10.0000),
11066                    ..Default::default()
11067                },
11068                ..Default::default()
11069            },
11070            stretch::geometry::Size::undefined(),
11071        )
11072        .unwrap();
11073
11074        assert_eq!(layout.size.width, 20.0000);
11075        assert_eq!(layout.size.height, 20.0000);
11076        assert_eq!(layout.location.x, 0.0000);
11077        assert_eq!(layout.location.y, 0.0000);
11078    }
11079
11080    #[test]
11081    fn rounding_flex_basis_flex_grow_row_prime_number_width() {
11082        let layout = stretch::compute(
11083            &stretch::style::Node {
11084                size: stretch::geometry::Size {
11085                    width: stretch::style::Dimension::Points(113.0000),
11086                    height: stretch::style::Dimension::Points(100.0000),
11087                    ..Default::default()
11088                },
11089                children: vec![
11090                    stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
11091                    stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
11092                    stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
11093                    stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
11094                    stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
11095                ],
11096                ..Default::default()
11097            },
11098            stretch::geometry::Size::undefined(),
11099        )
11100        .unwrap();
11101
11102        assert_eq!(layout.size.width, 113.0000);
11103        assert_eq!(layout.size.height, 100.0000);
11104        assert_eq!(layout.location.x, 0.0000);
11105        assert_eq!(layout.location.y, 0.0000);
11106
11107        assert_eq!(layout.children[0].size.width, 23.0000);
11108        assert_eq!(layout.children[0].size.height, 100.0000);
11109        assert_eq!(layout.children[0].location.x, 0.0000);
11110        assert_eq!(layout.children[0].location.y, 0.0000);
11111
11112        assert_eq!(layout.children[1].size.width, 22.0000);
11113        assert_eq!(layout.children[1].size.height, 100.0000);
11114        assert_eq!(layout.children[1].location.x, 23.0000);
11115        assert_eq!(layout.children[1].location.y, 0.0000);
11116
11117        assert_eq!(layout.children[2].size.width, 23.0000);
11118        assert_eq!(layout.children[2].size.height, 100.0000);
11119        assert_eq!(layout.children[2].location.x, 45.0000);
11120        assert_eq!(layout.children[2].location.y, 0.0000);
11121
11122        assert_eq!(layout.children[3].size.width, 22.0000);
11123        assert_eq!(layout.children[3].size.height, 100.0000);
11124        assert_eq!(layout.children[3].location.x, 68.0000);
11125        assert_eq!(layout.children[3].location.y, 0.0000);
11126
11127        assert_eq!(layout.children[4].size.width, 23.0000);
11128        assert_eq!(layout.children[4].size.height, 100.0000);
11129        assert_eq!(layout.children[4].location.x, 90.0000);
11130        assert_eq!(layout.children[4].location.y, 0.0000);
11131    }
11132
11133    #[test]
11134    fn align_items_center_with_child_top() {
11135        let layout = stretch::compute(
11136            &stretch::style::Node {
11137                align_items: stretch::style::AlignItems::Center,
11138                size: stretch::geometry::Size {
11139                    width: stretch::style::Dimension::Points(100.0000),
11140                    height: stretch::style::Dimension::Points(100.0000),
11141                    ..Default::default()
11142                },
11143                children: vec![stretch::style::Node {
11144                    size: stretch::geometry::Size {
11145                        width: stretch::style::Dimension::Points(10.0000),
11146                        height: stretch::style::Dimension::Points(10.0000),
11147                        ..Default::default()
11148                    },
11149                    position: stretch::geometry::Rect {
11150                        top: stretch::style::Dimension::Points(10.0000),
11151                        ..Default::default()
11152                    },
11153                    ..Default::default()
11154                }],
11155                ..Default::default()
11156            },
11157            stretch::geometry::Size::undefined(),
11158        )
11159        .unwrap();
11160
11161        assert_eq!(layout.size.width, 100.0000);
11162        assert_eq!(layout.size.height, 100.0000);
11163        assert_eq!(layout.location.x, 0.0000);
11164        assert_eq!(layout.location.y, 0.0000);
11165
11166        assert_eq!(layout.children[0].size.width, 10.0000);
11167        assert_eq!(layout.children[0].size.height, 10.0000);
11168        assert_eq!(layout.children[0].location.x, 0.0000);
11169        assert_eq!(layout.children[0].location.y, 55.0000);
11170    }
11171
11172    #[test]
11173    fn width_smaller_then_content_with_flex_grow_large_size() {
11174        let layout = stretch::compute(
11175            &stretch::style::Node {
11176                size: stretch::geometry::Size {
11177                    width: stretch::style::Dimension::Points(100.0000),
11178                    ..Default::default()
11179                },
11180                children: vec![
11181                    stretch::style::Node {
11182                        flex_direction: stretch::style::FlexDirection::Column,
11183                        flex_grow: 1.0000,
11184                        size: stretch::geometry::Size {
11185                            width: stretch::style::Dimension::Points(0.0000),
11186                            ..Default::default()
11187                        },
11188                        children: vec![stretch::style::Node {
11189                            size: stretch::geometry::Size {
11190                                width: stretch::style::Dimension::Points(70.0000),
11191                                height: stretch::style::Dimension::Points(100.0000),
11192                                ..Default::default()
11193                            },
11194                            ..Default::default()
11195                        }],
11196                        ..Default::default()
11197                    },
11198                    stretch::style::Node {
11199                        flex_direction: stretch::style::FlexDirection::Column,
11200                        flex_grow: 1.0000,
11201                        size: stretch::geometry::Size {
11202                            width: stretch::style::Dimension::Points(0.0000),
11203                            ..Default::default()
11204                        },
11205                        children: vec![stretch::style::Node {
11206                            size: stretch::geometry::Size {
11207                                width: stretch::style::Dimension::Points(20.0000),
11208                                height: stretch::style::Dimension::Points(100.0000),
11209                                ..Default::default()
11210                            },
11211                            ..Default::default()
11212                        }],
11213                        ..Default::default()
11214                    },
11215                ],
11216                ..Default::default()
11217            },
11218            stretch::geometry::Size::undefined(),
11219        )
11220        .unwrap();
11221
11222        assert_eq!(layout.size.width, 100.0000);
11223        assert_eq!(layout.size.height, 100.0000);
11224        assert_eq!(layout.location.x, 0.0000);
11225        assert_eq!(layout.location.y, 0.0000);
11226
11227        assert_eq!(layout.children[0].size.width, 50.0000);
11228        assert_eq!(layout.children[0].size.height, 100.0000);
11229        assert_eq!(layout.children[0].location.x, 0.0000);
11230        assert_eq!(layout.children[0].location.y, 0.0000);
11231
11232        assert_eq!(layout.children[0].children[0].size.width, 70.0000);
11233        assert_eq!(layout.children[0].children[0].size.height, 100.0000);
11234        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
11235        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
11236
11237        assert_eq!(layout.children[1].size.width, 50.0000);
11238        assert_eq!(layout.children[1].size.height, 100.0000);
11239        assert_eq!(layout.children[1].location.x, 50.0000);
11240        assert_eq!(layout.children[1].location.y, 0.0000);
11241
11242        assert_eq!(layout.children[1].children[0].size.width, 20.0000);
11243        assert_eq!(layout.children[1].children[0].size.height, 100.0000);
11244        assert_eq!(layout.children[1].children[0].location.x, 0.0000);
11245        assert_eq!(layout.children[1].children[0].location.y, 0.0000);
11246    }
11247
11248    #[test]
11249    fn display_none() {
11250        let layout = stretch::compute(
11251            &stretch::style::Node {
11252                size: stretch::geometry::Size {
11253                    width: stretch::style::Dimension::Points(100.0000),
11254                    height: stretch::style::Dimension::Points(100.0000),
11255                    ..Default::default()
11256                },
11257                children: vec![
11258                    stretch::style::Node { flex_grow: 1.0000, ..Default::default() },
11259                    stretch::style::Node {
11260                        display: stretch::style::Display::None,
11261                        flex_grow: 1.0000,
11262                        ..Default::default()
11263                    },
11264                ],
11265                ..Default::default()
11266            },
11267            stretch::geometry::Size::undefined(),
11268        )
11269        .unwrap();
11270
11271        assert_eq!(layout.size.width, 100.0000);
11272        assert_eq!(layout.size.height, 100.0000);
11273        assert_eq!(layout.location.x, 0.0000);
11274        assert_eq!(layout.location.y, 0.0000);
11275
11276        assert_eq!(layout.children[0].size.width, 100.0000);
11277        assert_eq!(layout.children[0].size.height, 100.0000);
11278        assert_eq!(layout.children[0].location.x, 0.0000);
11279        assert_eq!(layout.children[0].location.y, 0.0000);
11280
11281        assert_eq!(layout.children[1].size.width, 0.0000);
11282        assert_eq!(layout.children[1].size.height, 0.0000);
11283        assert_eq!(layout.children[1].location.x, 0.0000);
11284        assert_eq!(layout.children[1].location.y, 0.0000);
11285    }
11286
11287    #[test]
11288    fn flex_basis_smaller_than_content_column() {
11289        let layout = stretch::compute(
11290            &stretch::style::Node {
11291                flex_direction: stretch::style::FlexDirection::Column,
11292                size: stretch::geometry::Size {
11293                    height: stretch::style::Dimension::Points(100.0000),
11294                    ..Default::default()
11295                },
11296                children: vec![stretch::style::Node {
11297                    flex_direction: stretch::style::FlexDirection::Column,
11298                    flex_basis: stretch::style::Dimension::Points(50.0000),
11299                    children: vec![stretch::style::Node {
11300                        size: stretch::geometry::Size {
11301                            width: stretch::style::Dimension::Points(100.0000),
11302                            height: stretch::style::Dimension::Points(100.0000),
11303                            ..Default::default()
11304                        },
11305                        ..Default::default()
11306                    }],
11307                    ..Default::default()
11308                }],
11309                ..Default::default()
11310            },
11311            stretch::geometry::Size::undefined(),
11312        )
11313        .unwrap();
11314
11315        assert_eq!(layout.size.width, 100.0000);
11316        assert_eq!(layout.size.height, 100.0000);
11317        assert_eq!(layout.location.x, 0.0000);
11318        assert_eq!(layout.location.y, 0.0000);
11319
11320        assert_eq!(layout.children[0].size.width, 100.0000);
11321        assert_eq!(layout.children[0].size.height, 50.0000);
11322        assert_eq!(layout.children[0].location.x, 0.0000);
11323        assert_eq!(layout.children[0].location.y, 0.0000);
11324
11325        assert_eq!(layout.children[0].children[0].size.width, 100.0000);
11326        assert_eq!(layout.children[0].children[0].size.height, 50.0000);
11327        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
11328        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
11329    }
11330
11331    #[test]
11332    fn percentage_width_height_undefined_parent_size() {
11333        let layout = stretch::compute(
11334            &stretch::style::Node {
11335                flex_direction: stretch::style::FlexDirection::Column,
11336                children: vec![stretch::style::Node {
11337                    size: stretch::geometry::Size {
11338                        width: stretch::style::Dimension::Percent(0.5000),
11339                        height: stretch::style::Dimension::Percent(0.5000),
11340                        ..Default::default()
11341                    },
11342                    ..Default::default()
11343                }],
11344                ..Default::default()
11345            },
11346            stretch::geometry::Size::undefined(),
11347        )
11348        .unwrap();
11349
11350        assert_eq!(layout.size.width, 0.0000);
11351        assert_eq!(layout.size.height, 0.0000);
11352        assert_eq!(layout.location.x, 0.0000);
11353        assert_eq!(layout.location.y, 0.0000);
11354
11355        assert_eq!(layout.children[0].size.width, 0.0000);
11356        assert_eq!(layout.children[0].size.height, 0.0000);
11357        assert_eq!(layout.children[0].location.x, 0.0000);
11358        assert_eq!(layout.children[0].location.y, 0.0000);
11359    }
11360
11361    #[test]
11362    fn flex_grow_within_max_width() {
11363        let layout = stretch::compute(
11364            &stretch::style::Node {
11365                flex_direction: stretch::style::FlexDirection::Column,
11366                size: stretch::geometry::Size {
11367                    width: stretch::style::Dimension::Points(200.0000),
11368                    height: stretch::style::Dimension::Points(100.0000),
11369                    ..Default::default()
11370                },
11371                children: vec![stretch::style::Node {
11372                    max_size: stretch::geometry::Size {
11373                        width: stretch::style::Dimension::Points(100.0000),
11374                        ..Default::default()
11375                    },
11376                    children: vec![stretch::style::Node {
11377                        flex_grow: 1.0000,
11378                        size: stretch::geometry::Size {
11379                            height: stretch::style::Dimension::Points(20.0000),
11380                            ..Default::default()
11381                        },
11382                        ..Default::default()
11383                    }],
11384                    ..Default::default()
11385                }],
11386                ..Default::default()
11387            },
11388            stretch::geometry::Size::undefined(),
11389        )
11390        .unwrap();
11391
11392        assert_eq!(layout.size.width, 200.0000);
11393        assert_eq!(layout.size.height, 100.0000);
11394        assert_eq!(layout.location.x, 0.0000);
11395        assert_eq!(layout.location.y, 0.0000);
11396
11397        assert_eq!(layout.children[0].size.width, 100.0000);
11398        assert_eq!(layout.children[0].size.height, 20.0000);
11399        assert_eq!(layout.children[0].location.x, 0.0000);
11400        assert_eq!(layout.children[0].location.y, 0.0000);
11401
11402        assert_eq!(layout.children[0].children[0].size.width, 100.0000);
11403        assert_eq!(layout.children[0].children[0].size.height, 20.0000);
11404        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
11405        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
11406    }
11407
11408    #[test]
11409    fn flex_grow_height_maximized() {
11410        let layout = stretch::compute(
11411            &stretch::style::Node {
11412                flex_direction: stretch::style::FlexDirection::Column,
11413                size: stretch::geometry::Size {
11414                    width: stretch::style::Dimension::Points(100.0000),
11415                    height: stretch::style::Dimension::Points(500.0000),
11416                    ..Default::default()
11417                },
11418                children: vec![stretch::style::Node {
11419                    flex_direction: stretch::style::FlexDirection::Column,
11420                    flex_grow: 1.0000,
11421                    min_size: stretch::geometry::Size {
11422                        height: stretch::style::Dimension::Points(100.0000),
11423                        ..Default::default()
11424                    },
11425                    max_size: stretch::geometry::Size {
11426                        height: stretch::style::Dimension::Points(500.0000),
11427                        ..Default::default()
11428                    },
11429                    children: vec![
11430                        stretch::style::Node {
11431                            flex_grow: 1.0000,
11432                            flex_basis: stretch::style::Dimension::Points(200.0000),
11433                            ..Default::default()
11434                        },
11435                        stretch::style::Node {
11436                            size: stretch::geometry::Size {
11437                                height: stretch::style::Dimension::Points(100.0000),
11438                                ..Default::default()
11439                            },
11440                            ..Default::default()
11441                        },
11442                    ],
11443                    ..Default::default()
11444                }],
11445                ..Default::default()
11446            },
11447            stretch::geometry::Size::undefined(),
11448        )
11449        .unwrap();
11450
11451        assert_eq!(layout.size.width, 100.0000);
11452        assert_eq!(layout.size.height, 500.0000);
11453        assert_eq!(layout.location.x, 0.0000);
11454        assert_eq!(layout.location.y, 0.0000);
11455
11456        assert_eq!(layout.children[0].size.width, 100.0000);
11457        assert_eq!(layout.children[0].size.height, 500.0000);
11458        assert_eq!(layout.children[0].location.x, 0.0000);
11459        assert_eq!(layout.children[0].location.y, 0.0000);
11460
11461        assert_eq!(layout.children[0].children[0].size.width, 100.0000);
11462        assert_eq!(layout.children[0].children[0].size.height, 400.0000);
11463        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
11464        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
11465
11466        assert_eq!(layout.children[0].children[1].size.width, 100.0000);
11467        assert_eq!(layout.children[0].children[1].size.height, 100.0000);
11468        assert_eq!(layout.children[0].children[1].location.x, 0.0000);
11469        assert_eq!(layout.children[0].children[1].location.y, 400.0000);
11470    }
11471
11472    #[test]
11473    fn max_height_overrides_height() {
11474        let layout = stretch::compute(
11475            &stretch::style::Node {
11476                children: vec![stretch::style::Node {
11477                    size: stretch::geometry::Size {
11478                        height: stretch::style::Dimension::Points(200.0000),
11479                        ..Default::default()
11480                    },
11481                    max_size: stretch::geometry::Size {
11482                        height: stretch::style::Dimension::Points(100.0000),
11483                        ..Default::default()
11484                    },
11485                    ..Default::default()
11486                }],
11487                ..Default::default()
11488            },
11489            stretch::geometry::Size::undefined(),
11490        )
11491        .unwrap();
11492
11493        assert_eq!(layout.size.width, 0.0000);
11494        assert_eq!(layout.size.height, 100.0000);
11495        assert_eq!(layout.location.x, 0.0000);
11496        assert_eq!(layout.location.y, 0.0000);
11497
11498        assert_eq!(layout.children[0].size.width, 0.0000);
11499        assert_eq!(layout.children[0].size.height, 100.0000);
11500        assert_eq!(layout.children[0].location.x, 0.0000);
11501        assert_eq!(layout.children[0].location.y, 0.0000);
11502    }
11503
11504    #[test]
11505    fn relative_position_should_not_nudge_siblings() {
11506        let layout = stretch::compute(
11507            &stretch::style::Node {
11508                flex_direction: stretch::style::FlexDirection::Column,
11509                size: stretch::geometry::Size {
11510                    width: stretch::style::Dimension::Points(100.0000),
11511                    height: stretch::style::Dimension::Points(100.0000),
11512                    ..Default::default()
11513                },
11514                children: vec![
11515                    stretch::style::Node {
11516                        size: stretch::geometry::Size {
11517                            height: stretch::style::Dimension::Points(10.0000),
11518                            ..Default::default()
11519                        },
11520                        position: stretch::geometry::Rect {
11521                            top: stretch::style::Dimension::Points(15.0000),
11522                            ..Default::default()
11523                        },
11524                        ..Default::default()
11525                    },
11526                    stretch::style::Node {
11527                        size: stretch::geometry::Size {
11528                            height: stretch::style::Dimension::Points(10.0000),
11529                            ..Default::default()
11530                        },
11531                        position: stretch::geometry::Rect {
11532                            top: stretch::style::Dimension::Points(15.0000),
11533                            ..Default::default()
11534                        },
11535                        ..Default::default()
11536                    },
11537                ],
11538                ..Default::default()
11539            },
11540            stretch::geometry::Size::undefined(),
11541        )
11542        .unwrap();
11543
11544        assert_eq!(layout.size.width, 100.0000);
11545        assert_eq!(layout.size.height, 100.0000);
11546        assert_eq!(layout.location.x, 0.0000);
11547        assert_eq!(layout.location.y, 0.0000);
11548
11549        assert_eq!(layout.children[0].size.width, 100.0000);
11550        assert_eq!(layout.children[0].size.height, 10.0000);
11551        assert_eq!(layout.children[0].location.x, 0.0000);
11552        assert_eq!(layout.children[0].location.y, 15.0000);
11553
11554        assert_eq!(layout.children[1].size.width, 100.0000);
11555        assert_eq!(layout.children[1].size.height, 10.0000);
11556        assert_eq!(layout.children[1].location.x, 0.0000);
11557        assert_eq!(layout.children[1].location.y, 25.0000);
11558    }
11559
11560    #[test]
11561    fn justify_content_min_width_with_padding_child_width_greater_than_parent() {
11562        let layout = stretch::compute(
11563            &stretch::style::Node {
11564                flex_direction: stretch::style::FlexDirection::Column,
11565                size: stretch::geometry::Size {
11566                    width: stretch::style::Dimension::Points(1000.0000),
11567                    height: stretch::style::Dimension::Points(1584.0000),
11568                    ..Default::default()
11569                },
11570                children: vec![stretch::style::Node {
11571                    children: vec![stretch::style::Node {
11572                        justify_content: stretch::style::JustifyContent::Center,
11573                        min_size: stretch::geometry::Size {
11574                            width: stretch::style::Dimension::Points(400.0000),
11575                            ..Default::default()
11576                        },
11577                        padding: stretch::geometry::Rect {
11578                            start: stretch::style::Dimension::Points(100.0000),
11579                            end: stretch::style::Dimension::Points(100.0000),
11580                            ..Default::default()
11581                        },
11582                        children: vec![stretch::style::Node {
11583                            size: stretch::geometry::Size {
11584                                width: stretch::style::Dimension::Points(300.0000),
11585                                height: stretch::style::Dimension::Points(100.0000),
11586                                ..Default::default()
11587                            },
11588                            ..Default::default()
11589                        }],
11590                        ..Default::default()
11591                    }],
11592                    ..Default::default()
11593                }],
11594                ..Default::default()
11595            },
11596            stretch::geometry::Size::undefined(),
11597        )
11598        .unwrap();
11599
11600        assert_eq!(layout.size.width, 1000.0000);
11601        assert_eq!(layout.size.height, 1584.0000);
11602        assert_eq!(layout.location.x, 0.0000);
11603        assert_eq!(layout.location.y, 0.0000);
11604
11605        assert_eq!(layout.children[0].size.width, 1000.0000);
11606        assert_eq!(layout.children[0].size.height, 100.0000);
11607        assert_eq!(layout.children[0].location.x, 0.0000);
11608        assert_eq!(layout.children[0].location.y, 0.0000);
11609
11610        assert_eq!(layout.children[0].children[0].size.width, 500.0000);
11611        assert_eq!(layout.children[0].children[0].size.height, 100.0000);
11612        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
11613        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
11614
11615        assert_eq!(layout.children[0].children[0].children[0].size.width, 300.0000);
11616        assert_eq!(layout.children[0].children[0].children[0].size.height, 100.0000);
11617        assert_eq!(layout.children[0].children[0].children[0].location.x, 100.0000);
11618        assert_eq!(layout.children[0].children[0].children[0].location.y, 0.0000);
11619    }
11620
11621    #[test]
11622    fn flex_grow_flex_basis_percent_min_max() {
11623        let layout = stretch::compute(
11624            &stretch::style::Node {
11625                size: stretch::geometry::Size {
11626                    width: stretch::style::Dimension::Points(120.0000),
11627                    ..Default::default()
11628                },
11629                children: vec![
11630                    stretch::style::Node {
11631                        flex_grow: 1.0000,
11632                        flex_shrink: 0.0000,
11633                        flex_basis: stretch::style::Dimension::Points(0.0000),
11634                        size: stretch::geometry::Size {
11635                            height: stretch::style::Dimension::Points(20.0000),
11636                            ..Default::default()
11637                        },
11638                        min_size: stretch::geometry::Size {
11639                            width: stretch::style::Dimension::Points(60.0000),
11640                            ..Default::default()
11641                        },
11642                        ..Default::default()
11643                    },
11644                    stretch::style::Node {
11645                        flex_grow: 1.0000,
11646                        flex_shrink: 0.0000,
11647                        flex_basis: stretch::style::Dimension::Percent(0.5000),
11648                        size: stretch::geometry::Size {
11649                            width: stretch::style::Dimension::Points(20.0000),
11650                            height: stretch::style::Dimension::Points(20.0000),
11651                            ..Default::default()
11652                        },
11653                        max_size: stretch::geometry::Size {
11654                            width: stretch::style::Dimension::Points(20.0000),
11655                            ..Default::default()
11656                        },
11657                        ..Default::default()
11658                    },
11659                ],
11660                ..Default::default()
11661            },
11662            stretch::geometry::Size::undefined(),
11663        )
11664        .unwrap();
11665
11666        assert_eq!(layout.size.width, 120.0000);
11667        assert_eq!(layout.size.height, 20.0000);
11668        assert_eq!(layout.location.x, 0.0000);
11669        assert_eq!(layout.location.y, 0.0000);
11670
11671        assert_eq!(layout.children[0].size.width, 100.0000);
11672        assert_eq!(layout.children[0].size.height, 20.0000);
11673        assert_eq!(layout.children[0].location.x, 0.0000);
11674        assert_eq!(layout.children[0].location.y, 0.0000);
11675
11676        assert_eq!(layout.children[1].size.width, 20.0000);
11677        assert_eq!(layout.children[1].size.height, 20.0000);
11678        assert_eq!(layout.children[1].location.x, 100.0000);
11679        assert_eq!(layout.children[1].location.y, 0.0000);
11680    }
11681
11682    #[test]
11683    fn percent_absolute_position() {
11684        let layout = stretch::compute(
11685            &stretch::style::Node {
11686                flex_direction: stretch::style::FlexDirection::Column,
11687                size: stretch::geometry::Size {
11688                    width: stretch::style::Dimension::Points(60.0000),
11689                    height: stretch::style::Dimension::Points(50.0000),
11690                    ..Default::default()
11691                },
11692                children: vec![stretch::style::Node {
11693                    position_type: stretch::style::PositionType::Absolute,
11694                    size: stretch::geometry::Size {
11695                        width: stretch::style::Dimension::Percent(1.0000),
11696                        height: stretch::style::Dimension::Points(50.0000),
11697                        ..Default::default()
11698                    },
11699                    position: stretch::geometry::Rect {
11700                        start: stretch::style::Dimension::Percent(0.5000),
11701                        ..Default::default()
11702                    },
11703                    children: vec![
11704                        stretch::style::Node {
11705                            size: stretch::geometry::Size {
11706                                width: stretch::style::Dimension::Percent(1.0000),
11707                                ..Default::default()
11708                            },
11709                            ..Default::default()
11710                        },
11711                        stretch::style::Node {
11712                            size: stretch::geometry::Size {
11713                                width: stretch::style::Dimension::Percent(1.0000),
11714                                ..Default::default()
11715                            },
11716                            ..Default::default()
11717                        },
11718                    ],
11719                    ..Default::default()
11720                }],
11721                ..Default::default()
11722            },
11723            stretch::geometry::Size::undefined(),
11724        )
11725        .unwrap();
11726
11727        assert_eq!(layout.size.width, 60.0000);
11728        assert_eq!(layout.size.height, 50.0000);
11729        assert_eq!(layout.location.x, 0.0000);
11730        assert_eq!(layout.location.y, 0.0000);
11731
11732        assert_eq!(layout.children[0].size.width, 60.0000);
11733        assert_eq!(layout.children[0].size.height, 50.0000);
11734        assert_eq!(layout.children[0].location.x, 30.0000);
11735        assert_eq!(layout.children[0].location.y, 0.0000);
11736
11737        assert_eq!(layout.children[0].children[0].size.width, 30.0000);
11738        assert_eq!(layout.children[0].children[0].size.height, 50.0000);
11739        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
11740        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
11741
11742        assert_eq!(layout.children[0].children[1].size.width, 30.0000);
11743        assert_eq!(layout.children[0].children[1].size.height, 50.0000);
11744        assert_eq!(layout.children[0].children[1].location.x, 30.0000);
11745        assert_eq!(layout.children[0].children[1].location.y, 0.0000);
11746    }
11747
11748    #[test]
11749    fn flex_root_ignored() {
11750        let layout = stretch::compute(
11751            &stretch::style::Node {
11752                flex_direction: stretch::style::FlexDirection::Column,
11753                size: stretch::geometry::Size {
11754                    width: stretch::style::Dimension::Points(100.0000),
11755                    ..Default::default()
11756                },
11757                min_size: stretch::geometry::Size {
11758                    height: stretch::style::Dimension::Points(100.0000),
11759                    ..Default::default()
11760                },
11761                max_size: stretch::geometry::Size {
11762                    height: stretch::style::Dimension::Points(500.0000),
11763                    ..Default::default()
11764                },
11765                children: vec![
11766                    stretch::style::Node {
11767                        flex_grow: 1.0000,
11768                        flex_basis: stretch::style::Dimension::Points(200.0000),
11769                        ..Default::default()
11770                    },
11771                    stretch::style::Node {
11772                        size: stretch::geometry::Size {
11773                            height: stretch::style::Dimension::Points(100.0000),
11774                            ..Default::default()
11775                        },
11776                        ..Default::default()
11777                    },
11778                ],
11779                ..Default::default()
11780            },
11781            stretch::geometry::Size::undefined(),
11782        )
11783        .unwrap();
11784
11785        assert_eq!(layout.size.width, 100.0000);
11786        assert_eq!(layout.size.height, 300.0000);
11787        assert_eq!(layout.location.x, 0.0000);
11788        assert_eq!(layout.location.y, 0.0000);
11789
11790        assert_eq!(layout.children[0].size.width, 100.0000);
11791        assert_eq!(layout.children[0].size.height, 200.0000);
11792        assert_eq!(layout.children[0].location.x, 0.0000);
11793        assert_eq!(layout.children[0].location.y, 0.0000);
11794
11795        assert_eq!(layout.children[1].size.width, 100.0000);
11796        assert_eq!(layout.children[1].size.height, 100.0000);
11797        assert_eq!(layout.children[1].location.x, 0.0000);
11798        assert_eq!(layout.children[1].location.y, 200.0000);
11799    }
11800
11801    #[test]
11802    fn justify_content_column_space_between() {
11803        let layout = stretch::compute(
11804            &stretch::style::Node {
11805                flex_direction: stretch::style::FlexDirection::Column,
11806                justify_content: stretch::style::JustifyContent::SpaceBetween,
11807                size: stretch::geometry::Size {
11808                    width: stretch::style::Dimension::Points(100.0000),
11809                    height: stretch::style::Dimension::Points(100.0000),
11810                    ..Default::default()
11811                },
11812                children: vec![
11813                    stretch::style::Node {
11814                        size: stretch::geometry::Size {
11815                            height: stretch::style::Dimension::Points(10.0000),
11816                            ..Default::default()
11817                        },
11818                        ..Default::default()
11819                    },
11820                    stretch::style::Node {
11821                        size: stretch::geometry::Size {
11822                            height: stretch::style::Dimension::Points(10.0000),
11823                            ..Default::default()
11824                        },
11825                        ..Default::default()
11826                    },
11827                    stretch::style::Node {
11828                        size: stretch::geometry::Size {
11829                            height: stretch::style::Dimension::Points(10.0000),
11830                            ..Default::default()
11831                        },
11832                        ..Default::default()
11833                    },
11834                ],
11835                ..Default::default()
11836            },
11837            stretch::geometry::Size::undefined(),
11838        )
11839        .unwrap();
11840
11841        assert_eq!(layout.size.width, 100.0000);
11842        assert_eq!(layout.size.height, 100.0000);
11843        assert_eq!(layout.location.x, 0.0000);
11844        assert_eq!(layout.location.y, 0.0000);
11845
11846        assert_eq!(layout.children[0].size.width, 100.0000);
11847        assert_eq!(layout.children[0].size.height, 10.0000);
11848        assert_eq!(layout.children[0].location.x, 0.0000);
11849        assert_eq!(layout.children[0].location.y, 0.0000);
11850
11851        assert_eq!(layout.children[1].size.width, 100.0000);
11852        assert_eq!(layout.children[1].size.height, 10.0000);
11853        assert_eq!(layout.children[1].location.x, 0.0000);
11854        assert_eq!(layout.children[1].location.y, 45.0000);
11855
11856        assert_eq!(layout.children[2].size.width, 100.0000);
11857        assert_eq!(layout.children[2].size.height, 10.0000);
11858        assert_eq!(layout.children[2].location.x, 0.0000);
11859        assert_eq!(layout.children[2].location.y, 90.0000);
11860    }
11861
11862    #[test]
11863    fn flex_grow_within_constrained_max_width() {
11864        let layout = stretch::compute(
11865            &stretch::style::Node {
11866                flex_direction: stretch::style::FlexDirection::Column,
11867                size: stretch::geometry::Size {
11868                    width: stretch::style::Dimension::Points(200.0000),
11869                    height: stretch::style::Dimension::Points(100.0000),
11870                    ..Default::default()
11871                },
11872                children: vec![stretch::style::Node {
11873                    max_size: stretch::geometry::Size {
11874                        width: stretch::style::Dimension::Points(300.0000),
11875                        ..Default::default()
11876                    },
11877                    children: vec![stretch::style::Node {
11878                        flex_grow: 1.0000,
11879                        size: stretch::geometry::Size {
11880                            height: stretch::style::Dimension::Points(20.0000),
11881                            ..Default::default()
11882                        },
11883                        ..Default::default()
11884                    }],
11885                    ..Default::default()
11886                }],
11887                ..Default::default()
11888            },
11889            stretch::geometry::Size::undefined(),
11890        )
11891        .unwrap();
11892
11893        assert_eq!(layout.size.width, 200.0000);
11894        assert_eq!(layout.size.height, 100.0000);
11895        assert_eq!(layout.location.x, 0.0000);
11896        assert_eq!(layout.location.y, 0.0000);
11897
11898        assert_eq!(layout.children[0].size.width, 200.0000);
11899        assert_eq!(layout.children[0].size.height, 20.0000);
11900        assert_eq!(layout.children[0].location.x, 0.0000);
11901        assert_eq!(layout.children[0].location.y, 0.0000);
11902
11903        assert_eq!(layout.children[0].children[0].size.width, 200.0000);
11904        assert_eq!(layout.children[0].children[0].size.height, 20.0000);
11905        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
11906        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
11907    }
11908
11909    #[test]
11910    fn flex_basis_smaller_than_content_row() {
11911        let layout = stretch::compute(
11912            &stretch::style::Node {
11913                size: stretch::geometry::Size {
11914                    width: stretch::style::Dimension::Points(100.0000),
11915                    ..Default::default()
11916                },
11917                children: vec![stretch::style::Node {
11918                    flex_direction: stretch::style::FlexDirection::Column,
11919                    flex_basis: stretch::style::Dimension::Points(50.0000),
11920                    children: vec![stretch::style::Node {
11921                        size: stretch::geometry::Size {
11922                            width: stretch::style::Dimension::Points(100.0000),
11923                            height: stretch::style::Dimension::Points(100.0000),
11924                            ..Default::default()
11925                        },
11926                        ..Default::default()
11927                    }],
11928                    ..Default::default()
11929                }],
11930                ..Default::default()
11931            },
11932            stretch::geometry::Size::undefined(),
11933        )
11934        .unwrap();
11935
11936        assert_eq!(layout.size.width, 100.0000);
11937        assert_eq!(layout.size.height, 100.0000);
11938        assert_eq!(layout.location.x, 0.0000);
11939        assert_eq!(layout.location.y, 0.0000);
11940
11941        assert_eq!(layout.children[0].size.width, 100.0000);
11942        assert_eq!(layout.children[0].size.height, 100.0000);
11943        assert_eq!(layout.children[0].location.x, 0.0000);
11944        assert_eq!(layout.children[0].location.y, 0.0000);
11945
11946        assert_eq!(layout.children[0].children[0].size.width, 100.0000);
11947        assert_eq!(layout.children[0].children[0].size.height, 100.0000);
11948        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
11949        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
11950    }
11951
11952    #[test]
11953    fn max_width_overrides_width() {
11954        let layout = stretch::compute(
11955            &stretch::style::Node {
11956                children: vec![stretch::style::Node {
11957                    size: stretch::geometry::Size {
11958                        width: stretch::style::Dimension::Points(200.0000),
11959                        ..Default::default()
11960                    },
11961                    max_size: stretch::geometry::Size {
11962                        width: stretch::style::Dimension::Points(100.0000),
11963                        ..Default::default()
11964                    },
11965                    ..Default::default()
11966                }],
11967                ..Default::default()
11968            },
11969            stretch::geometry::Size::undefined(),
11970        )
11971        .unwrap();
11972
11973        assert_eq!(layout.size.width, 100.0000);
11974        assert_eq!(layout.size.height, 0.0000);
11975        assert_eq!(layout.location.x, 0.0000);
11976        assert_eq!(layout.location.y, 0.0000);
11977
11978        assert_eq!(layout.children[0].size.width, 100.0000);
11979        assert_eq!(layout.children[0].size.height, 0.0000);
11980        assert_eq!(layout.children[0].location.x, 0.0000);
11981        assert_eq!(layout.children[0].location.y, 0.0000);
11982    }
11983
11984    #[test]
11985    fn percentage_position_bottom_right() {
11986        let layout = stretch::compute(
11987            &stretch::style::Node {
11988                size: stretch::geometry::Size {
11989                    width: stretch::style::Dimension::Points(500.0000),
11990                    height: stretch::style::Dimension::Points(500.0000),
11991                    ..Default::default()
11992                },
11993                children: vec![stretch::style::Node {
11994                    size: stretch::geometry::Size {
11995                        width: stretch::style::Dimension::Percent(0.5500),
11996                        height: stretch::style::Dimension::Percent(0.1500),
11997                        ..Default::default()
11998                    },
11999                    position: stretch::geometry::Rect {
12000                        end: stretch::style::Dimension::Percent(0.2000),
12001                        bottom: stretch::style::Dimension::Percent(0.1000),
12002                        ..Default::default()
12003                    },
12004                    ..Default::default()
12005                }],
12006                ..Default::default()
12007            },
12008            stretch::geometry::Size::undefined(),
12009        )
12010        .unwrap();
12011
12012        assert_eq!(layout.size.width, 500.0000);
12013        assert_eq!(layout.size.height, 500.0000);
12014        assert_eq!(layout.location.x, 0.0000);
12015        assert_eq!(layout.location.y, 0.0000);
12016
12017        assert_eq!(layout.children[0].size.width, 275.0000);
12018        assert_eq!(layout.children[0].size.height, 75.0000);
12019        assert_eq!(layout.children[0].location.x, -100.0000);
12020        assert_eq!(layout.children[0].location.y, -50.0000);
12021    }
12022
12023    #[test]
12024    fn margin_auto_top_stretching_child() {
12025        let layout = stretch::compute(
12026            &stretch::style::Node {
12027                align_items: stretch::style::AlignItems::Center,
12028                size: stretch::geometry::Size {
12029                    width: stretch::style::Dimension::Points(200.0000),
12030                    height: stretch::style::Dimension::Points(200.0000),
12031                    ..Default::default()
12032                },
12033                children: vec![
12034                    stretch::style::Node {
12035                        flex_grow: 1.0000,
12036                        flex_shrink: 1.0000,
12037                        flex_basis: stretch::style::Dimension::Percent(0.0000),
12038                        margin: stretch::geometry::Rect { top: stretch::style::Dimension::Auto, ..Default::default() },
12039                        ..Default::default()
12040                    },
12041                    stretch::style::Node {
12042                        size: stretch::geometry::Size {
12043                            width: stretch::style::Dimension::Points(50.0000),
12044                            height: stretch::style::Dimension::Points(50.0000),
12045                            ..Default::default()
12046                        },
12047                        ..Default::default()
12048                    },
12049                ],
12050                ..Default::default()
12051            },
12052            stretch::geometry::Size::undefined(),
12053        )
12054        .unwrap();
12055
12056        assert_eq!(layout.size.width, 200.0000);
12057        assert_eq!(layout.size.height, 200.0000);
12058        assert_eq!(layout.location.x, 0.0000);
12059        assert_eq!(layout.location.y, 0.0000);
12060
12061        assert_eq!(layout.children[0].size.width, 150.0000);
12062        assert_eq!(layout.children[0].size.height, 0.0000);
12063        assert_eq!(layout.children[0].location.x, 0.0000);
12064        assert_eq!(layout.children[0].location.y, 200.0000);
12065
12066        assert_eq!(layout.children[1].size.width, 50.0000);
12067        assert_eq!(layout.children[1].size.height, 50.0000);
12068        assert_eq!(layout.children[1].location.x, 150.0000);
12069        assert_eq!(layout.children[1].location.y, 75.0000);
12070    }
12071
12072    #[test]
12073    fn align_flex_start_with_shrinking_children() {
12074        let layout = stretch::compute(
12075            &stretch::style::Node {
12076                size: stretch::geometry::Size {
12077                    width: stretch::style::Dimension::Points(500.0000),
12078                    height: stretch::style::Dimension::Points(500.0000),
12079                    ..Default::default()
12080                },
12081                children: vec![stretch::style::Node {
12082                    align_items: stretch::style::AlignItems::FlexStart,
12083                    children: vec![stretch::style::Node {
12084                        flex_grow: 1.0000,
12085                        flex_shrink: 1.0000,
12086                        children: vec![stretch::style::Node {
12087                            flex_grow: 1.0000,
12088                            flex_shrink: 1.0000,
12089                            ..Default::default()
12090                        }],
12091                        ..Default::default()
12092                    }],
12093                    ..Default::default()
12094                }],
12095                ..Default::default()
12096            },
12097            stretch::geometry::Size::undefined(),
12098        )
12099        .unwrap();
12100
12101        assert_eq!(layout.size.width, 500.0000);
12102        assert_eq!(layout.size.height, 500.0000);
12103        assert_eq!(layout.location.x, 0.0000);
12104        assert_eq!(layout.location.y, 0.0000);
12105
12106        assert_eq!(layout.children[0].size.width, 0.0000);
12107        assert_eq!(layout.children[0].size.height, 500.0000);
12108        assert_eq!(layout.children[0].location.x, 0.0000);
12109        assert_eq!(layout.children[0].location.y, 0.0000);
12110
12111        assert_eq!(layout.children[0].children[0].size.width, 0.0000);
12112        assert_eq!(layout.children[0].children[0].size.height, 0.0000);
12113        assert_eq!(layout.children[0].children[0].location.x, 0.0000);
12114        assert_eq!(layout.children[0].children[0].location.y, 0.0000);
12115
12116        assert_eq!(layout.children[0].children[0].children[0].size.width, 0.0000);
12117        assert_eq!(layout.children[0].children[0].children[0].size.height, 0.0000);
12118        assert_eq!(layout.children[0].children[0].children[0].location.x, 0.0000);
12119        assert_eq!(layout.children[0].children[0].children[0].location.y, 0.0000);
12120    }
12121
12122    #[test]
12123    fn justify_content_column_min_height_and_margin_bottom() {
12124        let layout = stretch::compute(
12125            &stretch::style::Node {
12126                flex_direction: stretch::style::FlexDirection::Column,
12127                justify_content: stretch::style::JustifyContent::Center,
12128                min_size: stretch::geometry::Size {
12129                    height: stretch::style::Dimension::Points(50.0000),
12130                    ..Default::default()
12131                },
12132                children: vec![stretch::style::Node {
12133                    size: stretch::geometry::Size {
12134                        width: stretch::style::Dimension::Points(20.0000),
12135                        height: stretch::style::Dimension::Points(20.0000),
12136                        ..Default::default()
12137                    },
12138                    margin: stretch::geometry::Rect {
12139                        bottom: stretch::style::Dimension::Points(10.0000),
12140                        ..Default::default()
12141                    },
12142                    ..Default::default()
12143                }],
12144                ..Default::default()
12145            },
12146            stretch::geometry::Size::undefined(),
12147        )
12148        .unwrap();
12149
12150        assert_eq!(layout.size.width, 20.0000);
12151        assert_eq!(layout.size.height, 50.0000);
12152        assert_eq!(layout.location.x, 0.0000);
12153        assert_eq!(layout.location.y, 0.0000);
12154
12155        assert_eq!(layout.children[0].size.width, 20.0000);
12156        assert_eq!(layout.children[0].size.height, 20.0000);
12157        assert_eq!(layout.children[0].location.x, 0.0000);
12158        assert_eq!(layout.children[0].location.y, 10.0000);
12159    }
12160
12161}