⎇ float-layout
tests/generated/grid/grid_fit_content_points_min_content_hidden.rs
Historia
Quién tocó qué
crudo
Add `taffy_test_helpers` crate (#755)
1#[test]
2#[allow(non_snake_case)]
3fn grid_fit_content_points_min_content_hidden__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_with_context(
9 taffy::style::Style {
10 overflow: taffy::geometry::Point {
11 x: taffy::style::Overflow::Hidden,
12 y: taffy::style::Overflow::Hidden,
13 },
14 scrollbar_width: 15f32,
15 ..Default::default()
16 },
17 crate::TestNodeContext::ahem_text("HHHH\u{200b}HH", crate::WritingMode::Horizontal),
18 )
19 .unwrap();
20 let node = taffy
21 .new_with_children(
22 taffy::style::Style {
23 display: taffy::style::Display::Grid,
24 grid_template_rows: vec![length(40f32)],
25 grid_template_columns: vec![fit_content(length(30f32))],
26 ..Default::default()
27 },
28 &[node0],
29 )
30 .unwrap();
31 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
32 println!("\nComputed tree:");
33 taffy.print_tree(node);
34 println!();
35 let layout = taffy.layout(node).unwrap();
36 let Layout { size, location, .. } = layout;
37 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node, 30f32, size.width);
38 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node, 40f32, size.height);
39 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
40 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
41 let layout = taffy.layout(node0).unwrap();
42 let Layout { size, location, .. } = layout;
43 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node0, 30f32, size.width);
44 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
45 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
46 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
47 #[cfg(feature = "content_size")]
48 assert_eq!(
49 layout.scroll_width(),
50 10f32,
51 "scroll_width of node {:?}. Expected {}. Actual {}",
52 node0,
53 10f32,
54 layout.scroll_width()
55 );
56 #[cfg(feature = "content_size")]
57 assert_eq!(
58 layout.scroll_height(),
59 0f32,
60 "scroll_height of node {:?}. Expected {}. Actual {}",
61 node0,
62 0f32,
63 layout.scroll_height()
64 );
65}
66
67#[test]
68#[allow(non_snake_case)]
69fn grid_fit_content_points_min_content_hidden__content_box() {
70 #[allow(unused_imports)]
71 use taffy::{prelude::*, Layout};
72 let mut taffy = crate::new_test_tree();
73 let node0 = taffy
74 .new_leaf_with_context(
75 taffy::style::Style {
76 box_sizing: taffy::style::BoxSizing::ContentBox,
77 overflow: taffy::geometry::Point {
78 x: taffy::style::Overflow::Hidden,
79 y: taffy::style::Overflow::Hidden,
80 },
81 scrollbar_width: 15f32,
82 ..Default::default()
83 },
84 crate::TestNodeContext::ahem_text("HHHH\u{200b}HH", crate::WritingMode::Horizontal),
85 )
86 .unwrap();
87 let node = taffy
88 .new_with_children(
89 taffy::style::Style {
90 display: taffy::style::Display::Grid,
91 box_sizing: taffy::style::BoxSizing::ContentBox,
92 grid_template_rows: vec![length(40f32)],
93 grid_template_columns: vec![fit_content(length(30f32))],
94 ..Default::default()
95 },
96 &[node0],
97 )
98 .unwrap();
99 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
100 println!("\nComputed tree:");
101 taffy.print_tree(node);
102 println!();
103 let layout = taffy.layout(node).unwrap();
104 let Layout { size, location, .. } = layout;
105 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node, 30f32, size.width);
106 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node, 40f32, size.height);
107 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
108 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
109 let layout = taffy.layout(node0).unwrap();
110 let Layout { size, location, .. } = layout;
111 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node0, 30f32, size.width);
112 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
113 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
114 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
115 #[cfg(feature = "content_size")]
116 assert_eq!(
117 layout.scroll_width(),
118 10f32,
119 "scroll_width of node {:?}. Expected {}. Actual {}",
120 node0,
121 10f32,
122 layout.scroll_width()
123 );
124 #[cfg(feature = "content_size")]
125 assert_eq!(
126 layout.scroll_height(),
127 0f32,
128 "scroll_height of node {:?}. Expected {}. Actual {}",
129 node0,
130 0f32,
131 layout.scroll_height()
132 );
133}