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