⎇ 50ff9cb42edca669a335afffbf6e05808e52068a
tests/generated/grid/grid_placement_definite_primary.rs
Historia
Quién tocó qué
crudo
fix: removed wrong addition, causing items to be misplaced. (#817)
1#[test]
2#[allow(non_snake_case)]
3fn grid_placement_definite_primary__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 grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
10 ..Default::default()
11 })
12 .unwrap();
13 let node1 = taffy
14 .new_leaf(taffy::style::Style {
15 grid_column: taffy::geometry::Line { start: line(2i16), end: taffy::style::GridPlacement::Auto },
16 ..Default::default()
17 })
18 .unwrap();
19 let node2 = taffy
20 .new_leaf(taffy::style::Style {
21 grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
22 ..Default::default()
23 })
24 .unwrap();
25 let node3 = taffy
26 .new_leaf(taffy::style::Style {
27 grid_column: taffy::geometry::Line { start: line(2i16), end: taffy::style::GridPlacement::Auto },
28 ..Default::default()
29 })
30 .unwrap();
31 let node4 = taffy
32 .new_leaf(taffy::style::Style {
33 grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
34 ..Default::default()
35 })
36 .unwrap();
37 let node = taffy
38 .new_with_children(
39 taffy::style::Style {
40 display: taffy::style::Display::Grid,
41 grid_template_columns: vec![percent(0.33f32), percent(0.74f32)],
42 size: taffy::geometry::Size {
43 width: taffy::style::Dimension::from_length(200f32),
44 height: taffy::style::Dimension::from_length(200f32),
45 },
46 ..Default::default()
47 },
48 &[node0, node1, node2, node3, node4],
49 )
50 .unwrap();
51 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
52 println!("\nComputed tree:");
53 taffy.print_tree(node);
54 println!();
55 let layout = taffy.layout(node).unwrap();
56 let Layout { size, location, .. } = layout;
57 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
58 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
59 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
60 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
61 let layout = taffy.layout(node0).unwrap();
62 let Layout { size, location, .. } = layout;
63 assert_eq!(size.width, 66f32, "width of node {:?}. Expected {}. Actual {}", node0, 66f32, size.width);
64 assert_eq!(size.height, 67f32, "height of node {:?}. Expected {}. Actual {}", node0, 67f32, size.height);
65 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
66 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
67 let layout = taffy.layout(node1).unwrap();
68 let Layout { size, location, .. } = layout;
69 assert_eq!(size.width, 148f32, "width of node {:?}. Expected {}. Actual {}", node1, 148f32, size.width);
70 assert_eq!(size.height, 67f32, "height of node {:?}. Expected {}. Actual {}", node1, 67f32, size.height);
71 assert_eq!(location.x, 66f32, "x of node {:?}. Expected {}. Actual {}", node1, 66f32, location.x);
72 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
73 let layout = taffy.layout(node2).unwrap();
74 let Layout { size, location, .. } = layout;
75 assert_eq!(size.width, 66f32, "width of node {:?}. Expected {}. Actual {}", node2, 66f32, size.width);
76 assert_eq!(size.height, 66f32, "height of node {:?}. Expected {}. Actual {}", node2, 66f32, size.height);
77 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
78 assert_eq!(location.y, 67f32, "y of node {:?}. Expected {}. Actual {}", node2, 67f32, location.y);
79 let layout = taffy.layout(node3).unwrap();
80 let Layout { size, location, .. } = layout;
81 assert_eq!(size.width, 148f32, "width of node {:?}. Expected {}. Actual {}", node3, 148f32, size.width);
82 assert_eq!(size.height, 66f32, "height of node {:?}. Expected {}. Actual {}", node3, 66f32, size.height);
83 assert_eq!(location.x, 66f32, "x of node {:?}. Expected {}. Actual {}", node3, 66f32, location.x);
84 assert_eq!(location.y, 67f32, "y of node {:?}. Expected {}. Actual {}", node3, 67f32, location.y);
85 let layout = taffy.layout(node4).unwrap();
86 let Layout { size, location, .. } = layout;
87 assert_eq!(size.width, 66f32, "width of node {:?}. Expected {}. Actual {}", node4, 66f32, size.width);
88 assert_eq!(size.height, 67f32, "height of node {:?}. Expected {}. Actual {}", node4, 67f32, size.height);
89 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node4, 0f32, location.x);
90 assert_eq!(location.y, 133f32, "y of node {:?}. Expected {}. Actual {}", node4, 133f32, location.y);
91}
92
93#[test]
94#[allow(non_snake_case)]
95fn grid_placement_definite_primary__content_box() {
96 #[allow(unused_imports)]
97 use taffy::{prelude::*, Layout};
98 let mut taffy = crate::new_test_tree();
99 let node0 = taffy
100 .new_leaf(taffy::style::Style {
101 box_sizing: taffy::style::BoxSizing::ContentBox,
102 grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
103 ..Default::default()
104 })
105 .unwrap();
106 let node1 = taffy
107 .new_leaf(taffy::style::Style {
108 box_sizing: taffy::style::BoxSizing::ContentBox,
109 grid_column: taffy::geometry::Line { start: line(2i16), end: taffy::style::GridPlacement::Auto },
110 ..Default::default()
111 })
112 .unwrap();
113 let node2 = taffy
114 .new_leaf(taffy::style::Style {
115 box_sizing: taffy::style::BoxSizing::ContentBox,
116 grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
117 ..Default::default()
118 })
119 .unwrap();
120 let node3 = taffy
121 .new_leaf(taffy::style::Style {
122 box_sizing: taffy::style::BoxSizing::ContentBox,
123 grid_column: taffy::geometry::Line { start: line(2i16), end: taffy::style::GridPlacement::Auto },
124 ..Default::default()
125 })
126 .unwrap();
127 let node4 = taffy
128 .new_leaf(taffy::style::Style {
129 box_sizing: taffy::style::BoxSizing::ContentBox,
130 grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
131 ..Default::default()
132 })
133 .unwrap();
134 let node = taffy
135 .new_with_children(
136 taffy::style::Style {
137 display: taffy::style::Display::Grid,
138 box_sizing: taffy::style::BoxSizing::ContentBox,
139 grid_template_columns: vec![percent(0.33f32), percent(0.74f32)],
140 size: taffy::geometry::Size {
141 width: taffy::style::Dimension::from_length(200f32),
142 height: taffy::style::Dimension::from_length(200f32),
143 },
144 ..Default::default()
145 },
146 &[node0, node1, node2, node3, node4],
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 let layout = taffy.layout(node).unwrap();
154 let Layout { size, location, .. } = layout;
155 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
156 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, 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 let layout = taffy.layout(node0).unwrap();
160 let Layout { size, location, .. } = layout;
161 assert_eq!(size.width, 66f32, "width of node {:?}. Expected {}. Actual {}", node0, 66f32, size.width);
162 assert_eq!(size.height, 67f32, "height of node {:?}. Expected {}. Actual {}", node0, 67f32, size.height);
163 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
164 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
165 let layout = taffy.layout(node1).unwrap();
166 let Layout { size, location, .. } = layout;
167 assert_eq!(size.width, 148f32, "width of node {:?}. Expected {}. Actual {}", node1, 148f32, size.width);
168 assert_eq!(size.height, 67f32, "height of node {:?}. Expected {}. Actual {}", node1, 67f32, size.height);
169 assert_eq!(location.x, 66f32, "x of node {:?}. Expected {}. Actual {}", node1, 66f32, location.x);
170 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
171 let layout = taffy.layout(node2).unwrap();
172 let Layout { size, location, .. } = layout;
173 assert_eq!(size.width, 66f32, "width of node {:?}. Expected {}. Actual {}", node2, 66f32, size.width);
174 assert_eq!(size.height, 66f32, "height of node {:?}. Expected {}. Actual {}", node2, 66f32, size.height);
175 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
176 assert_eq!(location.y, 67f32, "y of node {:?}. Expected {}. Actual {}", node2, 67f32, location.y);
177 let layout = taffy.layout(node3).unwrap();
178 let Layout { size, location, .. } = layout;
179 assert_eq!(size.width, 148f32, "width of node {:?}. Expected {}. Actual {}", node3, 148f32, size.width);
180 assert_eq!(size.height, 66f32, "height of node {:?}. Expected {}. Actual {}", node3, 66f32, size.height);
181 assert_eq!(location.x, 66f32, "x of node {:?}. Expected {}. Actual {}", node3, 66f32, location.x);
182 assert_eq!(location.y, 67f32, "y of node {:?}. Expected {}. Actual {}", node3, 67f32, location.y);
183 let layout = taffy.layout(node4).unwrap();
184 let Layout { size, location, .. } = layout;
185 assert_eq!(size.width, 66f32, "width of node {:?}. Expected {}. Actual {}", node4, 66f32, size.width);
186 assert_eq!(size.height, 67f32, "height of node {:?}. Expected {}. Actual {}", node4, 67f32, size.height);
187 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node4, 0f32, location.x);
188 assert_eq!(location.y, 133f32, "y of node {:?}. Expected {}. Actual {}", node4, 133f32, location.y);
189}