⎇ e6255f79aa9a3f8065504fddb315ff4a6dfe6d0f
tests/generated/flex/margin_with_sibling_row.rs
Historia
Quién tocó qué
crudo
Implement `box-sizing: content-box` (#675)
1#[test]
2#[allow(non_snake_case)]
3fn margin_with_sibling_row__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 margin: taffy::geometry::Rect {
11 left: zero(),
12 right: taffy::style::LengthPercentageAuto::Length(10f32),
13 top: zero(),
14 bottom: zero(),
15 },
16 ..Default::default()
17 })
18 .unwrap();
19 let node1 = taffy.new_leaf(taffy::style::Style { flex_grow: 1f32, ..Default::default() }).unwrap();
20 let node = taffy
21 .new_with_children(
22 taffy::style::Style {
23 size: taffy::geometry::Size {
24 width: taffy::style::Dimension::Length(100f32),
25 height: taffy::style::Dimension::Length(100f32),
26 },
27 ..Default::default()
28 },
29 &[node0, node1],
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 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
37 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
38 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
39 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, 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 #[cfg(feature = "content_size")]
43 assert_eq!(
44 layout.scroll_width(),
45 0f32,
46 "scroll_width of node {:?}. Expected {}. Actual {}",
47 node,
48 0f32,
49 layout.scroll_width()
50 );
51 #[cfg(feature = "content_size")]
52 assert_eq!(
53 layout.scroll_height(),
54 0f32,
55 "scroll_height of node {:?}. Expected {}. Actual {}",
56 node,
57 0f32,
58 layout.scroll_height()
59 );
60 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
61 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
62 assert_eq!(size.width, 45f32, "width of node {:?}. Expected {}. Actual {}", node0, 45f32, size.width);
63 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
64 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
65 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
66 #[cfg(feature = "content_size")]
67 assert_eq!(
68 layout.scroll_width(),
69 0f32,
70 "scroll_width of node {:?}. Expected {}. Actual {}",
71 node0,
72 0f32,
73 layout.scroll_width()
74 );
75 #[cfg(feature = "content_size")]
76 assert_eq!(
77 layout.scroll_height(),
78 0f32,
79 "scroll_height of node {:?}. Expected {}. Actual {}",
80 node0,
81 0f32,
82 layout.scroll_height()
83 );
84 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
85 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
86 assert_eq!(size.width, 45f32, "width of node {:?}. Expected {}. Actual {}", node1, 45f32, size.width);
87 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node1, 100f32, size.height);
88 assert_eq!(location.x, 55f32, "x of node {:?}. Expected {}. Actual {}", node1, 55f32, location.x);
89 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
90 #[cfg(feature = "content_size")]
91 assert_eq!(
92 layout.scroll_width(),
93 0f32,
94 "scroll_width of node {:?}. Expected {}. Actual {}",
95 node1,
96 0f32,
97 layout.scroll_width()
98 );
99 #[cfg(feature = "content_size")]
100 assert_eq!(
101 layout.scroll_height(),
102 0f32,
103 "scroll_height of node {:?}. Expected {}. Actual {}",
104 node1,
105 0f32,
106 layout.scroll_height()
107 );
108}
109
110#[test]
111#[allow(non_snake_case)]
112fn margin_with_sibling_row__content_box() {
113 #[allow(unused_imports)]
114 use taffy::{prelude::*, tree::Layout, TaffyTree};
115 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
116 let node0 = taffy
117 .new_leaf(taffy::style::Style {
118 box_sizing: taffy::style::BoxSizing::ContentBox,
119 flex_grow: 1f32,
120 margin: taffy::geometry::Rect {
121 left: zero(),
122 right: taffy::style::LengthPercentageAuto::Length(10f32),
123 top: zero(),
124 bottom: zero(),
125 },
126 ..Default::default()
127 })
128 .unwrap();
129 let node1 = taffy
130 .new_leaf(taffy::style::Style {
131 box_sizing: taffy::style::BoxSizing::ContentBox,
132 flex_grow: 1f32,
133 ..Default::default()
134 })
135 .unwrap();
136 let node = taffy
137 .new_with_children(
138 taffy::style::Style {
139 box_sizing: taffy::style::BoxSizing::ContentBox,
140 size: taffy::geometry::Size {
141 width: taffy::style::Dimension::Length(100f32),
142 height: taffy::style::Dimension::Length(100f32),
143 },
144 ..Default::default()
145 },
146 &[node0, node1],
147 )
148 .unwrap();
149 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
150 println!("\nComputed tree:");
151 taffy.print_tree(node);
152 println!();
153 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
154 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
155 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
156 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
157 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
158 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
159 #[cfg(feature = "content_size")]
160 assert_eq!(
161 layout.scroll_width(),
162 0f32,
163 "scroll_width of node {:?}. Expected {}. Actual {}",
164 node,
165 0f32,
166 layout.scroll_width()
167 );
168 #[cfg(feature = "content_size")]
169 assert_eq!(
170 layout.scroll_height(),
171 0f32,
172 "scroll_height of node {:?}. Expected {}. Actual {}",
173 node,
174 0f32,
175 layout.scroll_height()
176 );
177 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
178 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
179 assert_eq!(size.width, 45f32, "width of node {:?}. Expected {}. Actual {}", node0, 45f32, size.width);
180 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
181 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
182 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
183 #[cfg(feature = "content_size")]
184 assert_eq!(
185 layout.scroll_width(),
186 0f32,
187 "scroll_width of node {:?}. Expected {}. Actual {}",
188 node0,
189 0f32,
190 layout.scroll_width()
191 );
192 #[cfg(feature = "content_size")]
193 assert_eq!(
194 layout.scroll_height(),
195 0f32,
196 "scroll_height of node {:?}. Expected {}. Actual {}",
197 node0,
198 0f32,
199 layout.scroll_height()
200 );
201 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
202 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
203 assert_eq!(size.width, 45f32, "width of node {:?}. Expected {}. Actual {}", node1, 45f32, size.width);
204 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node1, 100f32, size.height);
205 assert_eq!(location.x, 55f32, "x of node {:?}. Expected {}. Actual {}", node1, 55f32, location.x);
206 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
207 #[cfg(feature = "content_size")]
208 assert_eq!(
209 layout.scroll_width(),
210 0f32,
211 "scroll_width of node {:?}. Expected {}. Actual {}",
212 node1,
213 0f32,
214 layout.scroll_width()
215 );
216 #[cfg(feature = "content_size")]
217 assert_eq!(
218 layout.scroll_height(),
219 0f32,
220 "scroll_height of node {:?}. Expected {}. Actual {}",
221 node1,
222 0f32,
223 layout.scroll_height()
224 );
225}