tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 684HTML 640Markdown 12TOML 62290 Sutichaykuna

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