⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2
tests/generated/flex/simple_child.rs
Historia
Quién tocó qué
crudo
Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn simple_child__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, Layout};
6 let mut taffy = crate::new_test_tree();
7 let node000 = taffy
8 .new_leaf(taffy::style::Style {
9 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::from_length(10f32),
11 height: taffy::style::Dimension::from_length(10f32),
12 },
13 ..Default::default()
14 })
15 .unwrap();
16 let node00 = taffy
17 .new_with_children(
18 taffy::style::Style {
19 size: taffy::geometry::Size {
20 width: taffy::style::Dimension::from_length(10f32),
21 height: taffy::style::Dimension::from_length(10f32),
22 },
23 ..Default::default()
24 },
25 &[node000],
26 )
27 .unwrap();
28 let node010 = taffy
29 .new_leaf(taffy::style::Style {
30 align_self: Some(taffy::style::AlignSelf::Center),
31 size: taffy::geometry::Size {
32 width: taffy::style::Dimension::from_length(10f32),
33 height: taffy::style::Dimension::from_length(10f32),
34 },
35 ..Default::default()
36 })
37 .unwrap();
38 let node011 = taffy
39 .new_leaf(taffy::style::Style {
40 align_self: Some(taffy::style::AlignSelf::Center),
41 size: taffy::geometry::Size {
42 width: taffy::style::Dimension::from_length(10f32),
43 height: taffy::style::Dimension::from_length(10f32),
44 },
45 ..Default::default()
46 })
47 .unwrap();
48 let node01 = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node010, node011]).unwrap();
49 let node0 = taffy
50 .new_with_children(
51 taffy::style::Style {
52 size: taffy::geometry::Size {
53 width: taffy::style::Dimension::from_percent(1f32),
54 height: taffy::style::Dimension::from_percent(1f32),
55 },
56 ..Default::default()
57 },
58 &[node00, node01],
59 )
60 .unwrap();
61 let node = taffy
62 .new_with_children(
63 taffy::style::Style {
64 size: taffy::geometry::Size {
65 width: taffy::style::Dimension::from_length(100f32),
66 height: taffy::style::Dimension::from_length(100f32),
67 },
68 ..Default::default()
69 },
70 &[node0],
71 )
72 .unwrap();
73 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
74 println!("\nComputed tree:");
75 taffy.print_tree(node);
76 println!();
77 let layout = taffy.layout(node).unwrap();
78 let Layout { size, location, .. } = layout;
79 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
80 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
81 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
82 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
83 let layout = taffy.layout(node0).unwrap();
84 let Layout { size, location, .. } = layout;
85 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
86 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
87 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
88 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
89 let layout = taffy.layout(node00).unwrap();
90 let Layout { size, location, .. } = layout;
91 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node00, 10f32, size.width);
92 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node00, 10f32, size.height);
93 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
94 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
95 let layout = taffy.layout(node000).unwrap();
96 let Layout { size, location, .. } = layout;
97 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node000, 10f32, size.width);
98 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node000, 10f32, size.height);
99 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node000, 0f32, location.x);
100 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node000, 0f32, location.y);
101 let layout = taffy.layout(node01).unwrap();
102 let Layout { size, location, .. } = layout;
103 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node01, 20f32, size.width);
104 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node01, 100f32, size.height);
105 assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node01, 10f32, location.x);
106 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01, 0f32, location.y);
107 let layout = taffy.layout(node010).unwrap();
108 let Layout { size, location, .. } = layout;
109 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node010, 10f32, size.width);
110 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node010, 10f32, size.height);
111 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node010, 0f32, location.x);
112 assert_eq!(location.y, 45f32, "y of node {:?}. Expected {}. Actual {}", node010, 45f32, location.y);
113 let layout = taffy.layout(node011).unwrap();
114 let Layout { size, location, .. } = layout;
115 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node011, 10f32, size.width);
116 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node011, 10f32, size.height);
117 assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node011, 10f32, location.x);
118 assert_eq!(location.y, 45f32, "y of node {:?}. Expected {}. Actual {}", node011, 45f32, location.y);
119}
120
121#[test]
122#[allow(non_snake_case)]
123fn simple_child__content_box() {
124 #[allow(unused_imports)]
125 use taffy::{prelude::*, Layout};
126 let mut taffy = crate::new_test_tree();
127 let node000 = taffy
128 .new_leaf(taffy::style::Style {
129 box_sizing: taffy::style::BoxSizing::ContentBox,
130 size: taffy::geometry::Size {
131 width: taffy::style::Dimension::from_length(10f32),
132 height: taffy::style::Dimension::from_length(10f32),
133 },
134 ..Default::default()
135 })
136 .unwrap();
137 let node00 = taffy
138 .new_with_children(
139 taffy::style::Style {
140 box_sizing: taffy::style::BoxSizing::ContentBox,
141 size: taffy::geometry::Size {
142 width: taffy::style::Dimension::from_length(10f32),
143 height: taffy::style::Dimension::from_length(10f32),
144 },
145 ..Default::default()
146 },
147 &[node000],
148 )
149 .unwrap();
150 let node010 = taffy
151 .new_leaf(taffy::style::Style {
152 box_sizing: taffy::style::BoxSizing::ContentBox,
153 align_self: Some(taffy::style::AlignSelf::Center),
154 size: taffy::geometry::Size {
155 width: taffy::style::Dimension::from_length(10f32),
156 height: taffy::style::Dimension::from_length(10f32),
157 },
158 ..Default::default()
159 })
160 .unwrap();
161 let node011 = taffy
162 .new_leaf(taffy::style::Style {
163 box_sizing: taffy::style::BoxSizing::ContentBox,
164 align_self: Some(taffy::style::AlignSelf::Center),
165 size: taffy::geometry::Size {
166 width: taffy::style::Dimension::from_length(10f32),
167 height: taffy::style::Dimension::from_length(10f32),
168 },
169 ..Default::default()
170 })
171 .unwrap();
172 let node01 = taffy
173 .new_with_children(
174 taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
175 &[node010, node011],
176 )
177 .unwrap();
178 let node0 = taffy
179 .new_with_children(
180 taffy::style::Style {
181 box_sizing: taffy::style::BoxSizing::ContentBox,
182 size: taffy::geometry::Size {
183 width: taffy::style::Dimension::from_percent(1f32),
184 height: taffy::style::Dimension::from_percent(1f32),
185 },
186 ..Default::default()
187 },
188 &[node00, node01],
189 )
190 .unwrap();
191 let node = taffy
192 .new_with_children(
193 taffy::style::Style {
194 box_sizing: taffy::style::BoxSizing::ContentBox,
195 size: taffy::geometry::Size {
196 width: taffy::style::Dimension::from_length(100f32),
197 height: taffy::style::Dimension::from_length(100f32),
198 },
199 ..Default::default()
200 },
201 &[node0],
202 )
203 .unwrap();
204 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
205 println!("\nComputed tree:");
206 taffy.print_tree(node);
207 println!();
208 let layout = taffy.layout(node).unwrap();
209 let Layout { size, location, .. } = layout;
210 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
211 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
212 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
213 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
214 let layout = taffy.layout(node0).unwrap();
215 let Layout { size, location, .. } = layout;
216 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
217 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
218 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
219 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
220 let layout = taffy.layout(node00).unwrap();
221 let Layout { size, location, .. } = layout;
222 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node00, 10f32, size.width);
223 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node00, 10f32, size.height);
224 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
225 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
226 let layout = taffy.layout(node000).unwrap();
227 let Layout { size, location, .. } = layout;
228 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node000, 10f32, size.width);
229 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node000, 10f32, size.height);
230 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node000, 0f32, location.x);
231 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node000, 0f32, location.y);
232 let layout = taffy.layout(node01).unwrap();
233 let Layout { size, location, .. } = layout;
234 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node01, 20f32, size.width);
235 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node01, 100f32, size.height);
236 assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node01, 10f32, location.x);
237 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01, 0f32, location.y);
238 let layout = taffy.layout(node010).unwrap();
239 let Layout { size, location, .. } = layout;
240 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node010, 10f32, size.width);
241 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node010, 10f32, size.height);
242 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node010, 0f32, location.x);
243 assert_eq!(location.y, 45f32, "y of node {:?}. Expected {}. Actual {}", node010, 45f32, location.y);
244 let layout = taffy.layout(node011).unwrap();
245 let Layout { size, location, .. } = layout;
246 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node011, 10f32, size.width);
247 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node011, 10f32, size.height);
248 assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node011, 10f32, location.x);
249 assert_eq!(location.y, 45f32, "y of node {:?}. Expected {}. Actual {}", node011, 45f32, location.y);
250}