tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 684HTML 640Markdown 12TOML 62290 Sutichaykuna

⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2 tests/generated/grid/grid_min_content_flex_column.rs Rust · 163 siq'ikuna · 8.8 KB Ñawpa willay Pi imata llamkarqan ch'uya

Add `taffy_test_helpers` crate (#755) 2a3e8476b · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn grid_min_content_flex_column__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 { ..Default::default() },
10            crate::TestNodeContext::ahem_text("HH\u{200b}HH", crate::WritingMode::Horizontal),
11        )
12        .unwrap();
13    let node01 = taffy
14        .new_leaf_with_context(
15            taffy::style::Style { ..Default::default() },
16            crate::TestNodeContext::ahem_text("HH\u{200b}HH", crate::WritingMode::Horizontal),
17        )
18        .unwrap();
19    let node02 = taffy
20        .new_leaf_with_context(
21            taffy::style::Style { ..Default::default() },
22            crate::TestNodeContext::ahem_text("HH\u{200b}HH", crate::WritingMode::Horizontal),
23        )
24        .unwrap();
25    let node0 = taffy
26        .new_with_children(
27            taffy::style::Style {
28                display: taffy::style::Display::Flex,
29                flex_direction: taffy::style::FlexDirection::Column,
30                ..Default::default()
31            },
32            &[node00, node01, node02],
33        )
34        .unwrap();
35    let node = taffy
36        .new_with_children(
37            taffy::style::Style {
38                display: taffy::style::Display::Grid,
39                grid_template_rows: vec![length(40f32)],
40                grid_template_columns: vec![min_content()],
41                ..Default::default()
42            },
43            &[node0],
44        )
45        .unwrap();
46    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
47    println!("\nComputed tree:");
48    taffy.print_tree(node);
49    println!();
50    let layout = taffy.layout(node).unwrap();
51    let Layout { size, location, .. } = layout;
52    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node, 20f32, size.width);
53    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node, 40f32, size.height);
54    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
55    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
56    let layout = taffy.layout(node0).unwrap();
57    let Layout { size, location, .. } = layout;
58    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
59    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
60    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
61    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
62    let layout = taffy.layout(node00).unwrap();
63    let Layout { size, location, .. } = layout;
64    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00, 20f32, size.width);
65    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00, 20f32, size.height);
66    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
67    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
68    let layout = taffy.layout(node01).unwrap();
69    let Layout { size, location, .. } = layout;
70    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node01, 20f32, size.width);
71    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node01, 20f32, size.height);
72    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node01, 0f32, location.x);
73    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node01, 20f32, location.y);
74    let layout = taffy.layout(node02).unwrap();
75    let Layout { size, location, .. } = layout;
76    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node02, 20f32, size.width);
77    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node02, 20f32, size.height);
78    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node02, 0f32, location.x);
79    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node02, 40f32, location.y);
80}
81
82#[test]
83#[allow(non_snake_case)]
84fn grid_min_content_flex_column__content_box() {
85    #[allow(unused_imports)]
86    use taffy::{prelude::*, Layout};
87    let mut taffy = crate::new_test_tree();
88    let node00 = taffy
89        .new_leaf_with_context(
90            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
91            crate::TestNodeContext::ahem_text("HH\u{200b}HH", crate::WritingMode::Horizontal),
92        )
93        .unwrap();
94    let node01 = taffy
95        .new_leaf_with_context(
96            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
97            crate::TestNodeContext::ahem_text("HH\u{200b}HH", crate::WritingMode::Horizontal),
98        )
99        .unwrap();
100    let node02 = taffy
101        .new_leaf_with_context(
102            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
103            crate::TestNodeContext::ahem_text("HH\u{200b}HH", crate::WritingMode::Horizontal),
104        )
105        .unwrap();
106    let node0 = taffy
107        .new_with_children(
108            taffy::style::Style {
109                display: taffy::style::Display::Flex,
110                box_sizing: taffy::style::BoxSizing::ContentBox,
111                flex_direction: taffy::style::FlexDirection::Column,
112                ..Default::default()
113            },
114            &[node00, node01, node02],
115        )
116        .unwrap();
117    let node = taffy
118        .new_with_children(
119            taffy::style::Style {
120                display: taffy::style::Display::Grid,
121                box_sizing: taffy::style::BoxSizing::ContentBox,
122                grid_template_rows: vec![length(40f32)],
123                grid_template_columns: vec![min_content()],
124                ..Default::default()
125            },
126            &[node0],
127        )
128        .unwrap();
129    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
130    println!("\nComputed tree:");
131    taffy.print_tree(node);
132    println!();
133    let layout = taffy.layout(node).unwrap();
134    let Layout { size, location, .. } = layout;
135    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node, 20f32, size.width);
136    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node, 40f32, size.height);
137    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
138    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
139    let layout = taffy.layout(node0).unwrap();
140    let Layout { size, location, .. } = layout;
141    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
142    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
143    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
144    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
145    let layout = taffy.layout(node00).unwrap();
146    let Layout { size, location, .. } = layout;
147    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00, 20f32, size.width);
148    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00, 20f32, size.height);
149    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
150    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
151    let layout = taffy.layout(node01).unwrap();
152    let Layout { size, location, .. } = layout;
153    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node01, 20f32, size.width);
154    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node01, 20f32, size.height);
155    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node01, 0f32, location.x);
156    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node01, 20f32, location.y);
157    let layout = taffy.layout(node02).unwrap();
158    let Layout { size, location, .. } = layout;
159    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node02, 20f32, size.width);
160    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node02, 20f32, size.height);
161    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node02, 0f32, location.x);
162    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node02, 40f32, location.y);
163}