⎇ 368b7da13d700e20ed1ef0fa2399fade0ca5ea3f
tests/generated/flex/content_size.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn content_size__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, Layout};
6 let mut taffy = crate::new_test_tree();
7 let node00 = taffy
8 .new_leaf_with_context(
9 taffy::style::Style {
10 position: taffy::style::Position::Absolute,
11 flex_shrink: 0f32,
12 size: taffy::geometry::Size {
13 width: taffy::style::Dimension::from_percent(1f32),
14 height: taffy::style::Dimension::from_length(20f32),
15 },
16 inset: taffy::geometry::Rect { left: auto(), right: auto(), top: length(-10f32), bottom: auto() },
17 ..Default::default()
18 },
19 crate::TestNodeContext::ahem_text("HHHH\u{200b}HHHH", crate::WritingMode::Horizontal),
20 )
21 .unwrap();
22 let node0 = taffy
23 .new_with_children(
24 taffy::style::Style {
25 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(30f32) },
26 ..Default::default()
27 },
28 &[node00],
29 )
30 .unwrap();
31 let node = taffy
32 .new_with_children(
33 taffy::style::Style {
34 display: taffy::style::Display::Flex,
35 flex_direction: taffy::style::FlexDirection::Column,
36 overflow: taffy::geometry::Point {
37 x: taffy::style::Overflow::Visible,
38 y: taffy::style::Overflow::Scroll,
39 },
40 scrollbar_width: 15f32,
41 size: taffy::geometry::Size {
42 width: taffy::style::Dimension::from_length(100f32),
43 height: taffy::style::Dimension::from_length(100f32),
44 },
45 ..Default::default()
46 },
47 &[node0],
48 )
49 .unwrap();
50 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
51 println!("\nComputed tree:");
52 taffy.print_tree(node);
53 println!();
54 let layout = taffy.layout(node).unwrap();
55 let Layout { size, location, .. } = layout;
56 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
57 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
58 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
59 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 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 node,
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 node,
75 0f32,
76 layout.scroll_height()
77 );
78 let layout = taffy.layout(node0).unwrap();
79 let Layout { size, location, .. } = layout;
80 assert_eq!(size.width, 85f32, "width of node {:?}. Expected {}. Actual {}", node0, 85f32, size.width);
81 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node0, 30f32, size.height);
82 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
83 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
84 let layout = taffy.layout(node00).unwrap();
85 let Layout { size, location, .. } = layout;
86 assert_eq!(size.width, 85f32, "width of node {:?}. Expected {}. Actual {}", node00, 85f32, size.width);
87 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00, 20f32, size.height);
88 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
89 assert_eq!(location.y, -10f32, "y of node {:?}. Expected {}. Actual {}", node00, -10f32, location.y);
90}
91
92#[test]
93#[allow(non_snake_case)]
94fn content_size__content_box() {
95 #[allow(unused_imports)]
96 use taffy::{prelude::*, Layout};
97 let mut taffy = crate::new_test_tree();
98 let node00 = taffy
99 .new_leaf_with_context(
100 taffy::style::Style {
101 box_sizing: taffy::style::BoxSizing::ContentBox,
102 position: taffy::style::Position::Absolute,
103 flex_shrink: 0f32,
104 size: taffy::geometry::Size {
105 width: taffy::style::Dimension::from_percent(1f32),
106 height: taffy::style::Dimension::from_length(20f32),
107 },
108 inset: taffy::geometry::Rect { left: auto(), right: auto(), top: length(-10f32), bottom: auto() },
109 ..Default::default()
110 },
111 crate::TestNodeContext::ahem_text("HHHH\u{200b}HHHH", crate::WritingMode::Horizontal),
112 )
113 .unwrap();
114 let node0 = taffy
115 .new_with_children(
116 taffy::style::Style {
117 box_sizing: taffy::style::BoxSizing::ContentBox,
118 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(30f32) },
119 ..Default::default()
120 },
121 &[node00],
122 )
123 .unwrap();
124 let node = taffy
125 .new_with_children(
126 taffy::style::Style {
127 display: taffy::style::Display::Flex,
128 box_sizing: taffy::style::BoxSizing::ContentBox,
129 flex_direction: taffy::style::FlexDirection::Column,
130 overflow: taffy::geometry::Point {
131 x: taffy::style::Overflow::Visible,
132 y: taffy::style::Overflow::Scroll,
133 },
134 scrollbar_width: 15f32,
135 size: taffy::geometry::Size {
136 width: taffy::style::Dimension::from_length(100f32),
137 height: taffy::style::Dimension::from_length(100f32),
138 },
139 ..Default::default()
140 },
141 &[node0],
142 )
143 .unwrap();
144 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
145 println!("\nComputed tree:");
146 taffy.print_tree(node);
147 println!();
148 let layout = taffy.layout(node).unwrap();
149 let Layout { size, location, .. } = layout;
150 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
151 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
152 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
153 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
154 #[cfg(feature = "content_size")]
155 assert_eq!(
156 layout.scroll_width(),
157 0f32,
158 "scroll_width of node {:?}. Expected {}. Actual {}",
159 node,
160 0f32,
161 layout.scroll_width()
162 );
163 #[cfg(feature = "content_size")]
164 assert_eq!(
165 layout.scroll_height(),
166 0f32,
167 "scroll_height of node {:?}. Expected {}. Actual {}",
168 node,
169 0f32,
170 layout.scroll_height()
171 );
172 let layout = taffy.layout(node0).unwrap();
173 let Layout { size, location, .. } = layout;
174 assert_eq!(size.width, 85f32, "width of node {:?}. Expected {}. Actual {}", node0, 85f32, size.width);
175 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node0, 30f32, size.height);
176 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
177 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
178 let layout = taffy.layout(node00).unwrap();
179 let Layout { size, location, .. } = layout;
180 assert_eq!(size.width, 85f32, "width of node {:?}. Expected {}. Actual {}", node00, 85f32, size.width);
181 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00, 20f32, size.height);
182 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
183 assert_eq!(location.y, -10f32, "y of node {:?}. Expected {}. Actual {}", node00, -10f32, location.y);
184}