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