⎇ b746ac4f346dde8a2b6f85d3a428c02a2342f099
tests/generated/flex/min_width_overrides_max_width.rs
History
Who touched what
raw
Implement `box-sizing: content-box` (#675)
1#[test]
2#[allow(non_snake_case)]
3fn min_width_overrides_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(taffy::style::Style {
9 min_size: taffy::geometry::Size { width: taffy::style::Dimension::Length(100f32), height: auto() },
10 max_size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
11 ..Default::default()
12 })
13 .unwrap();
14 let node = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node0]).unwrap();
15 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
16 println!("\nComputed tree:");
17 taffy.print_tree(node);
18 println!();
19 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
20 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
21 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
22 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node, 0f32, size.height);
23 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
24 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
25 #[cfg(feature = "content_size")]
26 assert_eq!(
27 layout.scroll_width(),
28 0f32,
29 "scroll_width of node {:?}. Expected {}. Actual {}",
30 node,
31 0f32,
32 layout.scroll_width()
33 );
34 #[cfg(feature = "content_size")]
35 assert_eq!(
36 layout.scroll_height(),
37 0f32,
38 "scroll_height of node {:?}. Expected {}. Actual {}",
39 node,
40 0f32,
41 layout.scroll_height()
42 );
43 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
44 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
45 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
46 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node0, 0f32, size.height);
47 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
48 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
49 #[cfg(feature = "content_size")]
50 assert_eq!(
51 layout.scroll_width(),
52 0f32,
53 "scroll_width of node {:?}. Expected {}. Actual {}",
54 node0,
55 0f32,
56 layout.scroll_width()
57 );
58 #[cfg(feature = "content_size")]
59 assert_eq!(
60 layout.scroll_height(),
61 0f32,
62 "scroll_height of node {:?}. Expected {}. Actual {}",
63 node0,
64 0f32,
65 layout.scroll_height()
66 );
67}
68
69#[test]
70#[allow(non_snake_case)]
71fn min_width_overrides_max_width__content_box() {
72 #[allow(unused_imports)]
73 use taffy::{prelude::*, tree::Layout, TaffyTree};
74 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
75 let node0 = taffy
76 .new_leaf(taffy::style::Style {
77 box_sizing: taffy::style::BoxSizing::ContentBox,
78 min_size: taffy::geometry::Size { width: taffy::style::Dimension::Length(100f32), height: auto() },
79 max_size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
80 ..Default::default()
81 })
82 .unwrap();
83 let node = taffy
84 .new_with_children(
85 taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
86 &[node0],
87 )
88 .unwrap();
89 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
90 println!("\nComputed tree:");
91 taffy.print_tree(node);
92 println!();
93 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
94 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
95 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
96 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node, 0f32, size.height);
97 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
98 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
99 #[cfg(feature = "content_size")]
100 assert_eq!(
101 layout.scroll_width(),
102 0f32,
103 "scroll_width of node {:?}. Expected {}. Actual {}",
104 node,
105 0f32,
106 layout.scroll_width()
107 );
108 #[cfg(feature = "content_size")]
109 assert_eq!(
110 layout.scroll_height(),
111 0f32,
112 "scroll_height of node {:?}. Expected {}. Actual {}",
113 node,
114 0f32,
115 layout.scroll_height()
116 );
117 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
118 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
119 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
120 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node0, 0f32, size.height);
121 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
122 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
123 #[cfg(feature = "content_size")]
124 assert_eq!(
125 layout.scroll_width(),
126 0f32,
127 "scroll_width of node {:?}. Expected {}. Actual {}",
128 node0,
129 0f32,
130 layout.scroll_width()
131 );
132 #[cfg(feature = "content_size")]
133 assert_eq!(
134 layout.scroll_height(),
135 0f32,
136 "scroll_height of node {:?}. Expected {}. Actual {}",
137 node0,
138 0f32,
139 layout.scroll_height()
140 );
141}