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