⎇ 3bc35ec3b541eea8ea62344722f155ce9b22e227
tests/generated/flex/rounding_fractial_input_4.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Implement `box-sizing: content-box` (#675)
1#[test]
2#[allow(non_snake_case)]
3fn rounding_fractial_input_4__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, tree::Layout, TaffyTree};
6 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
7 let node0 = taffy
8 .new_leaf(taffy::style::Style {
9 flex_grow: 1f32,
10 flex_basis: taffy::style::Dimension::Length(50f32),
11 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(20f32) },
12 ..Default::default()
13 })
14 .unwrap();
15 let node1 = taffy
16 .new_leaf(taffy::style::Style {
17 flex_grow: 1f32,
18 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
19 ..Default::default()
20 })
21 .unwrap();
22 let node2 = taffy
23 .new_leaf(taffy::style::Style {
24 flex_grow: 1f32,
25 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
26 ..Default::default()
27 })
28 .unwrap();
29 let node = taffy
30 .new_with_children(
31 taffy::style::Style {
32 flex_direction: taffy::style::FlexDirection::Column,
33 size: taffy::geometry::Size {
34 width: taffy::style::Dimension::Length(100f32),
35 height: taffy::style::Dimension::Length(113.4f32),
36 },
37 ..Default::default()
38 },
39 &[node0, node1, node2],
40 )
41 .unwrap();
42 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
43 println!("\nComputed tree:");
44 taffy.print_tree(node);
45 println!();
46 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
47 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
48 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
49 assert_eq!(size.height, 113f32, "height of node {:?}. Expected {}. Actual {}", node, 113f32, size.height);
50 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
51 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
52 #[cfg(feature = "content_size")]
53 assert_eq!(
54 layout.scroll_width(),
55 0f32,
56 "scroll_width of node {:?}. Expected {}. Actual {}",
57 node,
58 0f32,
59 layout.scroll_width()
60 );
61 #[cfg(feature = "content_size")]
62 assert_eq!(
63 layout.scroll_height(),
64 0f32,
65 "scroll_height of node {:?}. Expected {}. Actual {}",
66 node,
67 0f32,
68 layout.scroll_height()
69 );
70 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
71 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
72 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
73 assert_eq!(size.height, 64f32, "height of node {:?}. Expected {}. Actual {}", node0, 64f32, size.height);
74 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
75 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
76 #[cfg(feature = "content_size")]
77 assert_eq!(
78 layout.scroll_width(),
79 0f32,
80 "scroll_width of node {:?}. Expected {}. Actual {}",
81 node0,
82 0f32,
83 layout.scroll_width()
84 );
85 #[cfg(feature = "content_size")]
86 assert_eq!(
87 layout.scroll_height(),
88 0f32,
89 "scroll_height of node {:?}. Expected {}. Actual {}",
90 node0,
91 0f32,
92 layout.scroll_height()
93 );
94 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
95 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
96 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width);
97 assert_eq!(size.height, 25f32, "height of node {:?}. Expected {}. Actual {}", node1, 25f32, size.height);
98 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
99 assert_eq!(location.y, 64f32, "y of node {:?}. Expected {}. Actual {}", node1, 64f32, location.y);
100 #[cfg(feature = "content_size")]
101 assert_eq!(
102 layout.scroll_width(),
103 0f32,
104 "scroll_width of node {:?}. Expected {}. Actual {}",
105 node1,
106 0f32,
107 layout.scroll_width()
108 );
109 #[cfg(feature = "content_size")]
110 assert_eq!(
111 layout.scroll_height(),
112 0f32,
113 "scroll_height of node {:?}. Expected {}. Actual {}",
114 node1,
115 0f32,
116 layout.scroll_height()
117 );
118 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
119 let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
120 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node2, 100f32, size.width);
121 assert_eq!(size.height, 24f32, "height of node {:?}. Expected {}. Actual {}", node2, 24f32, size.height);
122 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
123 assert_eq!(location.y, 89f32, "y of node {:?}. Expected {}. Actual {}", node2, 89f32, location.y);
124 #[cfg(feature = "content_size")]
125 assert_eq!(
126 layout.scroll_width(),
127 0f32,
128 "scroll_width of node {:?}. Expected {}. Actual {}",
129 node2,
130 0f32,
131 layout.scroll_width()
132 );
133 #[cfg(feature = "content_size")]
134 assert_eq!(
135 layout.scroll_height(),
136 0f32,
137 "scroll_height of node {:?}. Expected {}. Actual {}",
138 node2,
139 0f32,
140 layout.scroll_height()
141 );
142}
143
144#[test]
145#[allow(non_snake_case)]
146fn rounding_fractial_input_4__content_box() {
147 #[allow(unused_imports)]
148 use taffy::{prelude::*, tree::Layout, TaffyTree};
149 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
150 let node0 = taffy
151 .new_leaf(taffy::style::Style {
152 box_sizing: taffy::style::BoxSizing::ContentBox,
153 flex_grow: 1f32,
154 flex_basis: taffy::style::Dimension::Length(50f32),
155 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(20f32) },
156 ..Default::default()
157 })
158 .unwrap();
159 let node1 = taffy
160 .new_leaf(taffy::style::Style {
161 box_sizing: taffy::style::BoxSizing::ContentBox,
162 flex_grow: 1f32,
163 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
164 ..Default::default()
165 })
166 .unwrap();
167 let node2 = taffy
168 .new_leaf(taffy::style::Style {
169 box_sizing: taffy::style::BoxSizing::ContentBox,
170 flex_grow: 1f32,
171 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
172 ..Default::default()
173 })
174 .unwrap();
175 let node = taffy
176 .new_with_children(
177 taffy::style::Style {
178 box_sizing: taffy::style::BoxSizing::ContentBox,
179 flex_direction: taffy::style::FlexDirection::Column,
180 size: taffy::geometry::Size {
181 width: taffy::style::Dimension::Length(100f32),
182 height: taffy::style::Dimension::Length(113.4f32),
183 },
184 ..Default::default()
185 },
186 &[node0, node1, node2],
187 )
188 .unwrap();
189 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
190 println!("\nComputed tree:");
191 taffy.print_tree(node);
192 println!();
193 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
194 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
195 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
196 assert_eq!(size.height, 113f32, "height of node {:?}. Expected {}. Actual {}", node, 113f32, size.height);
197 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
198 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
199 #[cfg(feature = "content_size")]
200 assert_eq!(
201 layout.scroll_width(),
202 0f32,
203 "scroll_width of node {:?}. Expected {}. Actual {}",
204 node,
205 0f32,
206 layout.scroll_width()
207 );
208 #[cfg(feature = "content_size")]
209 assert_eq!(
210 layout.scroll_height(),
211 0f32,
212 "scroll_height of node {:?}. Expected {}. Actual {}",
213 node,
214 0f32,
215 layout.scroll_height()
216 );
217 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
218 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
219 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
220 assert_eq!(size.height, 64f32, "height of node {:?}. Expected {}. Actual {}", node0, 64f32, size.height);
221 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
222 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
223 #[cfg(feature = "content_size")]
224 assert_eq!(
225 layout.scroll_width(),
226 0f32,
227 "scroll_width of node {:?}. Expected {}. Actual {}",
228 node0,
229 0f32,
230 layout.scroll_width()
231 );
232 #[cfg(feature = "content_size")]
233 assert_eq!(
234 layout.scroll_height(),
235 0f32,
236 "scroll_height of node {:?}. Expected {}. Actual {}",
237 node0,
238 0f32,
239 layout.scroll_height()
240 );
241 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
242 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
243 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width);
244 assert_eq!(size.height, 25f32, "height of node {:?}. Expected {}. Actual {}", node1, 25f32, size.height);
245 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
246 assert_eq!(location.y, 64f32, "y of node {:?}. Expected {}. Actual {}", node1, 64f32, location.y);
247 #[cfg(feature = "content_size")]
248 assert_eq!(
249 layout.scroll_width(),
250 0f32,
251 "scroll_width of node {:?}. Expected {}. Actual {}",
252 node1,
253 0f32,
254 layout.scroll_width()
255 );
256 #[cfg(feature = "content_size")]
257 assert_eq!(
258 layout.scroll_height(),
259 0f32,
260 "scroll_height of node {:?}. Expected {}. Actual {}",
261 node1,
262 0f32,
263 layout.scroll_height()
264 );
265 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
266 let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
267 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node2, 100f32, size.width);
268 assert_eq!(size.height, 24f32, "height of node {:?}. Expected {}. Actual {}", node2, 24f32, size.height);
269 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
270 assert_eq!(location.y, 89f32, "y of node {:?}. Expected {}. Actual {}", node2, 89f32, location.y);
271 #[cfg(feature = "content_size")]
272 assert_eq!(
273 layout.scroll_width(),
274 0f32,
275 "scroll_width of node {:?}. Expected {}. Actual {}",
276 node2,
277 0f32,
278 layout.scroll_width()
279 );
280 #[cfg(feature = "content_size")]
281 assert_eq!(
282 layout.scroll_height(),
283 0f32,
284 "scroll_height of node {:?}. Expected {}. Actual {}",
285 node2,
286 0f32,
287 layout.scroll_height()
288 );
289}