gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 492HTML 245JavaScript 8CSS 61137 Sutichaykuna

⎇ 9d61fe79d76567add93e52dd90ebcf35bd08c5d0 tests/generated/grid/grid_percent_tracks_indefinite_only.rs Rust · 154 siq'ikuna · 10.1 KB Ñawpa willay Pi imata llamkarqan ch'uya

Add `taffy_test_helpers` crate (#755) 2a3e8476b · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn grid_percent_tracks_indefinite_only__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node0 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
8    let node1 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
9    let node2 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
10    let node3 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
11    let node4 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
12    let node5 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
13    let node = taffy
14        .new_with_children(
15            taffy::style::Style {
16                display: taffy::style::Display::Grid,
17                grid_template_rows: vec![percent(0.3f32), percent(0.6f32)],
18                grid_template_columns: vec![percent(0.1f32), percent(0.2f32), percent(0.3f32)],
19                ..Default::default()
20            },
21            &[node0, node1, node2, node3, node4, node5],
22        )
23        .unwrap();
24    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
25    println!("\nComputed tree:");
26    taffy.print_tree(node);
27    println!();
28    let layout = taffy.layout(node).unwrap();
29    let Layout { size, location, .. } = layout;
30    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node, 0f32, size.width);
31    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node, 0f32, size.height);
32    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
33    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
34    let layout = taffy.layout(node0).unwrap();
35    let Layout { size, location, .. } = layout;
36    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node0, 0f32, size.width);
37    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node0, 0f32, size.height);
38    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
39    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
40    let layout = taffy.layout(node1).unwrap();
41    let Layout { size, location, .. } = layout;
42    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node1, 0f32, size.width);
43    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node1, 0f32, size.height);
44    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
45    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
46    let layout = taffy.layout(node2).unwrap();
47    let Layout { size, location, .. } = layout;
48    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node2, 0f32, size.width);
49    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node2, 0f32, size.height);
50    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
51    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
52    let layout = taffy.layout(node3).unwrap();
53    let Layout { size, location, .. } = layout;
54    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node3, 0f32, size.width);
55    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node3, 0f32, size.height);
56    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
57    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node3, 0f32, location.y);
58    let layout = taffy.layout(node4).unwrap();
59    let Layout { size, location, .. } = layout;
60    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node4, 0f32, size.width);
61    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node4, 0f32, size.height);
62    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node4, 0f32, location.x);
63    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node4, 0f32, location.y);
64    let layout = taffy.layout(node5).unwrap();
65    let Layout { size, location, .. } = layout;
66    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node5, 0f32, size.width);
67    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node5, 0f32, size.height);
68    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node5, 0f32, location.x);
69    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node5, 0f32, location.y);
70}
71
72#[test]
73#[allow(non_snake_case)]
74fn grid_percent_tracks_indefinite_only__content_box() {
75    #[allow(unused_imports)]
76    use taffy::{prelude::*, Layout};
77    let mut taffy = crate::new_test_tree();
78    let node0 = taffy
79        .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
80        .unwrap();
81    let node1 = taffy
82        .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
83        .unwrap();
84    let node2 = taffy
85        .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
86        .unwrap();
87    let node3 = taffy
88        .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
89        .unwrap();
90    let node4 = taffy
91        .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
92        .unwrap();
93    let node5 = taffy
94        .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
95        .unwrap();
96    let node = taffy
97        .new_with_children(
98            taffy::style::Style {
99                display: taffy::style::Display::Grid,
100                box_sizing: taffy::style::BoxSizing::ContentBox,
101                grid_template_rows: vec![percent(0.3f32), percent(0.6f32)],
102                grid_template_columns: vec![percent(0.1f32), percent(0.2f32), percent(0.3f32)],
103                ..Default::default()
104            },
105            &[node0, node1, node2, node3, node4, node5],
106        )
107        .unwrap();
108    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
109    println!("\nComputed tree:");
110    taffy.print_tree(node);
111    println!();
112    let layout = taffy.layout(node).unwrap();
113    let Layout { size, location, .. } = layout;
114    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node, 0f32, size.width);
115    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node, 0f32, size.height);
116    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
117    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
118    let layout = taffy.layout(node0).unwrap();
119    let Layout { size, location, .. } = layout;
120    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node0, 0f32, size.width);
121    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node0, 0f32, size.height);
122    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
123    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
124    let layout = taffy.layout(node1).unwrap();
125    let Layout { size, location, .. } = layout;
126    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node1, 0f32, size.width);
127    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node1, 0f32, size.height);
128    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
129    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
130    let layout = taffy.layout(node2).unwrap();
131    let Layout { size, location, .. } = layout;
132    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node2, 0f32, size.width);
133    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node2, 0f32, size.height);
134    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
135    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
136    let layout = taffy.layout(node3).unwrap();
137    let Layout { size, location, .. } = layout;
138    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node3, 0f32, size.width);
139    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node3, 0f32, size.height);
140    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
141    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node3, 0f32, location.y);
142    let layout = taffy.layout(node4).unwrap();
143    let Layout { size, location, .. } = layout;
144    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node4, 0f32, size.width);
145    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node4, 0f32, size.height);
146    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node4, 0f32, location.x);
147    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node4, 0f32, location.y);
148    let layout = taffy.layout(node5).unwrap();
149    let Layout { size, location, .. } = layout;
150    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node5, 0f32, size.width);
151    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node5, 0f32, size.height);
152    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node5, 0f32, location.x);
153    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node5, 0f32, location.y);
154}