⎇ 25571b5d07206880207e451af69dd3b49b113628
tests/generated/flex/aspect_ratio_flex_column_fill_max_width.rs
History
Who touched what
raw
Implement `box-sizing: content-box` (#675)
1#[test]
2#[allow(non_snake_case)]
3fn aspect_ratio_flex_column_fill_max_width__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_with_context(
9 taffy::style::Style {
10 max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(20f32) },
11 aspect_ratio: Some(2f32),
12 ..Default::default()
13 },
14 crate::TextMeasure {
15 text_content: "HH\u{200b}HH\u{200b}HH\u{200b}HH",
16 writing_mode: crate::WritingMode::Horizontal,
17 _aspect_ratio: Some(2f32),
18 },
19 )
20 .unwrap();
21 let node = taffy
22 .new_with_children(
23 taffy::style::Style {
24 display: taffy::style::Display::Flex,
25 flex_direction: taffy::style::FlexDirection::Column,
26 align_items: Some(taffy::style::AlignItems::Start),
27 size: taffy::geometry::Size {
28 width: taffy::style::Dimension::Length(100f32),
29 height: taffy::style::Dimension::Length(100f32),
30 },
31 ..Default::default()
32 },
33 &[node0],
34 )
35 .unwrap();
36 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
37 println!("\nComputed tree:");
38 taffy.print_tree(node);
39 println!();
40 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
41 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
42 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
43 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
44 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
45 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
46 #[cfg(feature = "content_size")]
47 assert_eq!(
48 layout.scroll_width(),
49 0f32,
50 "scroll_width of node {:?}. Expected {}. Actual {}",
51 node,
52 0f32,
53 layout.scroll_width()
54 );
55 #[cfg(feature = "content_size")]
56 assert_eq!(
57 layout.scroll_height(),
58 0f32,
59 "scroll_height of node {:?}. Expected {}. Actual {}",
60 node,
61 0f32,
62 layout.scroll_height()
63 );
64 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
65 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
66 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
67 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
68 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
69 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
70 #[cfg(feature = "content_size")]
71 assert_eq!(
72 layout.scroll_width(),
73 0f32,
74 "scroll_width of node {:?}. Expected {}. Actual {}",
75 node0,
76 0f32,
77 layout.scroll_width()
78 );
79 #[cfg(feature = "content_size")]
80 assert_eq!(
81 layout.scroll_height(),
82 0f32,
83 "scroll_height of node {:?}. Expected {}. Actual {}",
84 node0,
85 0f32,
86 layout.scroll_height()
87 );
88}
89
90#[test]
91#[allow(non_snake_case)]
92fn aspect_ratio_flex_column_fill_max_width__content_box() {
93 #[allow(unused_imports)]
94 use taffy::{prelude::*, tree::Layout, TaffyTree};
95 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
96 let node0 = taffy
97 .new_leaf_with_context(
98 taffy::style::Style {
99 box_sizing: taffy::style::BoxSizing::ContentBox,
100 max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(20f32) },
101 aspect_ratio: Some(2f32),
102 ..Default::default()
103 },
104 crate::TextMeasure {
105 text_content: "HH\u{200b}HH\u{200b}HH\u{200b}HH",
106 writing_mode: crate::WritingMode::Horizontal,
107 _aspect_ratio: Some(2f32),
108 },
109 )
110 .unwrap();
111 let node = taffy
112 .new_with_children(
113 taffy::style::Style {
114 display: taffy::style::Display::Flex,
115 box_sizing: taffy::style::BoxSizing::ContentBox,
116 flex_direction: taffy::style::FlexDirection::Column,
117 align_items: Some(taffy::style::AlignItems::Start),
118 size: taffy::geometry::Size {
119 width: taffy::style::Dimension::Length(100f32),
120 height: taffy::style::Dimension::Length(100f32),
121 },
122 ..Default::default()
123 },
124 &[node0],
125 )
126 .unwrap();
127 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
128 println!("\nComputed tree:");
129 taffy.print_tree(node);
130 println!();
131 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
132 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
133 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
134 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
135 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
136 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
137 #[cfg(feature = "content_size")]
138 assert_eq!(
139 layout.scroll_width(),
140 0f32,
141 "scroll_width of node {:?}. Expected {}. Actual {}",
142 node,
143 0f32,
144 layout.scroll_width()
145 );
146 #[cfg(feature = "content_size")]
147 assert_eq!(
148 layout.scroll_height(),
149 0f32,
150 "scroll_height of node {:?}. Expected {}. Actual {}",
151 node,
152 0f32,
153 layout.scroll_height()
154 );
155 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
156 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
157 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
158 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
159 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
160 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
161 #[cfg(feature = "content_size")]
162 assert_eq!(
163 layout.scroll_width(),
164 0f32,
165 "scroll_width of node {:?}. Expected {}. Actual {}",
166 node0,
167 0f32,
168 layout.scroll_width()
169 );
170 #[cfg(feature = "content_size")]
171 assert_eq!(
172 layout.scroll_height(),
173 0f32,
174 "scroll_height of node {:?}. Expected {}. Actual {}",
175 node0,
176 0f32,
177 layout.scroll_height()
178 );
179}