⎇ 40dd6120fc73aa866f30e52a51d1abaf39adce6f
tests/generated/flex/wrap_row.rs
History
Who touched what
raw
Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn wrap_row__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, Layout};
6 let mut taffy = crate::new_test_tree();
7 let node0 = taffy
8 .new_leaf(taffy::style::Style {
9 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::from_length(31f32),
11 height: taffy::style::Dimension::from_length(30f32),
12 },
13 ..Default::default()
14 })
15 .unwrap();
16 let node1 = taffy
17 .new_leaf(taffy::style::Style {
18 size: taffy::geometry::Size {
19 width: taffy::style::Dimension::from_length(32f32),
20 height: taffy::style::Dimension::from_length(30f32),
21 },
22 ..Default::default()
23 })
24 .unwrap();
25 let node2 = taffy
26 .new_leaf(taffy::style::Style {
27 size: taffy::geometry::Size {
28 width: taffy::style::Dimension::from_length(33f32),
29 height: taffy::style::Dimension::from_length(30f32),
30 },
31 ..Default::default()
32 })
33 .unwrap();
34 let node3 = taffy
35 .new_leaf(taffy::style::Style {
36 size: taffy::geometry::Size {
37 width: taffy::style::Dimension::from_length(34f32),
38 height: taffy::style::Dimension::from_length(30f32),
39 },
40 ..Default::default()
41 })
42 .unwrap();
43 let node = taffy
44 .new_with_children(
45 taffy::style::Style {
46 flex_wrap: taffy::style::FlexWrap::Wrap,
47 size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(100f32), height: auto() },
48 ..Default::default()
49 },
50 &[node0, node1, node2, node3],
51 )
52 .unwrap();
53 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
54 println!("\nComputed tree:");
55 taffy.print_tree(node);
56 println!();
57 let layout = taffy.layout(node).unwrap();
58 let Layout { size, location, .. } = layout;
59 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
60 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node, 60f32, size.height);
61 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
62 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
63 let layout = taffy.layout(node0).unwrap();
64 let Layout { size, location, .. } = layout;
65 assert_eq!(size.width, 31f32, "width of node {:?}. Expected {}. Actual {}", node0, 31f32, size.width);
66 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node0, 30f32, size.height);
67 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
68 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
69 let layout = taffy.layout(node1).unwrap();
70 let Layout { size, location, .. } = layout;
71 assert_eq!(size.width, 32f32, "width of node {:?}. Expected {}. Actual {}", node1, 32f32, size.width);
72 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node1, 30f32, size.height);
73 assert_eq!(location.x, 31f32, "x of node {:?}. Expected {}. Actual {}", node1, 31f32, location.x);
74 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
75 let layout = taffy.layout(node2).unwrap();
76 let Layout { size, location, .. } = layout;
77 assert_eq!(size.width, 33f32, "width of node {:?}. Expected {}. Actual {}", node2, 33f32, size.width);
78 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node2, 30f32, size.height);
79 assert_eq!(location.x, 63f32, "x of node {:?}. Expected {}. Actual {}", node2, 63f32, location.x);
80 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
81 let layout = taffy.layout(node3).unwrap();
82 let Layout { size, location, .. } = layout;
83 assert_eq!(size.width, 34f32, "width of node {:?}. Expected {}. Actual {}", node3, 34f32, size.width);
84 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node3, 30f32, size.height);
85 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
86 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node3, 30f32, location.y);
87}
88
89#[test]
90#[allow(non_snake_case)]
91fn wrap_row__content_box() {
92 #[allow(unused_imports)]
93 use taffy::{prelude::*, Layout};
94 let mut taffy = crate::new_test_tree();
95 let node0 = taffy
96 .new_leaf(taffy::style::Style {
97 box_sizing: taffy::style::BoxSizing::ContentBox,
98 size: taffy::geometry::Size {
99 width: taffy::style::Dimension::from_length(31f32),
100 height: taffy::style::Dimension::from_length(30f32),
101 },
102 ..Default::default()
103 })
104 .unwrap();
105 let node1 = taffy
106 .new_leaf(taffy::style::Style {
107 box_sizing: taffy::style::BoxSizing::ContentBox,
108 size: taffy::geometry::Size {
109 width: taffy::style::Dimension::from_length(32f32),
110 height: taffy::style::Dimension::from_length(30f32),
111 },
112 ..Default::default()
113 })
114 .unwrap();
115 let node2 = taffy
116 .new_leaf(taffy::style::Style {
117 box_sizing: taffy::style::BoxSizing::ContentBox,
118 size: taffy::geometry::Size {
119 width: taffy::style::Dimension::from_length(33f32),
120 height: taffy::style::Dimension::from_length(30f32),
121 },
122 ..Default::default()
123 })
124 .unwrap();
125 let node3 = taffy
126 .new_leaf(taffy::style::Style {
127 box_sizing: taffy::style::BoxSizing::ContentBox,
128 size: taffy::geometry::Size {
129 width: taffy::style::Dimension::from_length(34f32),
130 height: taffy::style::Dimension::from_length(30f32),
131 },
132 ..Default::default()
133 })
134 .unwrap();
135 let node = taffy
136 .new_with_children(
137 taffy::style::Style {
138 box_sizing: taffy::style::BoxSizing::ContentBox,
139 flex_wrap: taffy::style::FlexWrap::Wrap,
140 size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(100f32), height: auto() },
141 ..Default::default()
142 },
143 &[node0, node1, node2, node3],
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, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
153 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node, 60f32, 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, 31f32, "width of node {:?}. Expected {}. Actual {}", node0, 31f32, size.width);
159 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node0, 30f32, 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, 32f32, "width of node {:?}. Expected {}. Actual {}", node1, 32f32, size.width);
165 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node1, 30f32, size.height);
166 assert_eq!(location.x, 31f32, "x of node {:?}. Expected {}. Actual {}", node1, 31f32, 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, 33f32, "width of node {:?}. Expected {}. Actual {}", node2, 33f32, size.width);
171 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node2, 30f32, size.height);
172 assert_eq!(location.x, 63f32, "x of node {:?}. Expected {}. Actual {}", node2, 63f32, 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, 34f32, "width of node {:?}. Expected {}. Actual {}", node3, 34f32, size.width);
177 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node3, 30f32, size.height);
178 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
179 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node3, 30f32, location.y);
180}