Add `taffy_test_helpers` crate (#755)
1#[test]
2#[allow(non_snake_case)]
3fn grid_align_items_baseline__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(taffy::style::Style {
9 display: taffy::style::Display::Grid,
10 size: taffy::geometry::Size {
11 width: taffy::style::Dimension::Length(50f32),
12 height: taffy::style::Dimension::Length(50f32),
13 },
14 ..Default::default()
15 })
16 .unwrap();
17 let node1 = taffy
18 .new_leaf(taffy::style::Style {
19 display: taffy::style::Display::Grid,
20 size: taffy::geometry::Size {
21 width: taffy::style::Dimension::Length(50f32),
22 height: taffy::style::Dimension::Length(20f32),
23 },
24 ..Default::default()
25 })
26 .unwrap();
27 let node = taffy
28 .new_with_children(
29 taffy::style::Style {
30 display: taffy::style::Display::Grid,
31 align_items: Some(taffy::style::AlignItems::Baseline),
32 size: taffy::geometry::Size {
33 width: taffy::style::Dimension::Length(100f32),
34 height: taffy::style::Dimension::Length(100f32),
35 },
36 ..Default::default()
37 },
38 &[node0, node1],
39 )
40 .unwrap();
41 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
42 println!("\nComputed tree:");
43 taffy.print_tree(node);
44 println!();
45 let layout = taffy.layout(node).unwrap();
46 let Layout { size, location, .. } = layout;
47 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
48 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
49 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
50 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
51 let layout = taffy.layout(node0).unwrap();
52 let Layout { size, location, .. } = layout;
53 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
54 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
55 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
56 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
57 let layout = taffy.layout(node1).unwrap();
58 let Layout { size, location, .. } = layout;
59 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
60 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
61 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
62 assert_eq!(location.y, 65f32, "y of node {:?}. Expected {}. Actual {}", node1, 65f32, location.y);
63}
64
65#[test]
66#[allow(non_snake_case)]
67fn grid_align_items_baseline__content_box() {
68 #[allow(unused_imports)]
69 use taffy::{prelude::*, Layout};
70 let mut taffy = crate::new_test_tree();
71 let node0 = taffy
72 .new_leaf(taffy::style::Style {
73 display: taffy::style::Display::Grid,
74 box_sizing: taffy::style::BoxSizing::ContentBox,
75 size: taffy::geometry::Size {
76 width: taffy::style::Dimension::Length(50f32),
77 height: taffy::style::Dimension::Length(50f32),
78 },
79 ..Default::default()
80 })
81 .unwrap();
82 let node1 = taffy
83 .new_leaf(taffy::style::Style {
84 display: taffy::style::Display::Grid,
85 box_sizing: taffy::style::BoxSizing::ContentBox,
86 size: taffy::geometry::Size {
87 width: taffy::style::Dimension::Length(50f32),
88 height: taffy::style::Dimension::Length(20f32),
89 },
90 ..Default::default()
91 })
92 .unwrap();
93 let node = taffy
94 .new_with_children(
95 taffy::style::Style {
96 display: taffy::style::Display::Grid,
97 box_sizing: taffy::style::BoxSizing::ContentBox,
98 align_items: Some(taffy::style::AlignItems::Baseline),
99 size: taffy::geometry::Size {
100 width: taffy::style::Dimension::Length(100f32),
101 height: taffy::style::Dimension::Length(100f32),
102 },
103 ..Default::default()
104 },
105 &[node0, node1],
106 )
107 .unwrap();
108 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
109 println!("\nComputed tree:");
110 taffy.print_tree(node);
111 println!();
112 let layout = taffy.layout(node).unwrap();
113 let Layout { size, location, .. } = layout;
114 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
115 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
116 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
117 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
118 let layout = taffy.layout(node0).unwrap();
119 let Layout { size, location, .. } = layout;
120 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
121 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
122 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
123 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
124 let layout = taffy.layout(node1).unwrap();
125 let Layout { size, location, .. } = layout;
126 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
127 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
128 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
129 assert_eq!(location.y, 65f32, "y of node {:?}. Expected {}. Actual {}", node1, 65f32, location.y);
130}