⎇ direction-floats
tests/generated/block/block_absolute_rtl.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
add block layout & inherited fixtures, remove unused `flip` function
1#[test]
2#[allow(non_snake_case)]
3fn block_absolute_rtl__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 position: taffy::style::Position::Absolute,
10 size: taffy::geometry::Size {
11 width: taffy::style::Dimension::from_length(20f32),
12 height: taffy::style::Dimension::from_length(20f32),
13 },
14 inset: taffy::geometry::Rect { left: length(10f32), right: auto(), top: length(10f32), bottom: auto() },
15 ..Default::default()
16 })
17 .unwrap();
18 let node1 = taffy
19 .new_leaf(taffy::style::Style {
20 position: taffy::style::Position::Absolute,
21 size: taffy::geometry::Size {
22 width: taffy::style::Dimension::from_length(20f32),
23 height: taffy::style::Dimension::from_length(20f32),
24 },
25 inset: taffy::geometry::Rect { left: auto(), right: length(10f32), top: length(40f32), bottom: auto() },
26 ..Default::default()
27 })
28 .unwrap();
29 let node2 = taffy
30 .new_leaf(taffy::style::Style {
31 position: taffy::style::Position::Absolute,
32 size: taffy::geometry::Size {
33 width: taffy::style::Dimension::from_length(20f32),
34 height: taffy::style::Dimension::from_length(20f32),
35 },
36 inset: taffy::geometry::Rect { left: auto(), right: auto(), top: length(70f32), bottom: auto() },
37 ..Default::default()
38 })
39 .unwrap();
40 let node = taffy
41 .new_with_children(
42 taffy::style::Style {
43 display: taffy::style::Display::Block,
44 direction: taffy::style::Direction::Rtl,
45 size: taffy::geometry::Size {
46 width: taffy::style::Dimension::from_length(100f32),
47 height: taffy::style::Dimension::from_length(100f32),
48 },
49 ..Default::default()
50 },
51 &[node0, node1, node2],
52 )
53 .unwrap();
54 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
55 println!("\nComputed tree:");
56 taffy.print_tree(node);
57 println!();
58 let layout = taffy.layout(node).unwrap();
59 let Layout { size, location, .. } = layout;
60 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
61 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
62 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
63 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
64 let layout = taffy.layout(node0).unwrap();
65 let Layout { size, location, .. } = layout;
66 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
67 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
68 assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node0, 10f32, location.x);
69 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node0, 10f32, location.y);
70 let layout = taffy.layout(node1).unwrap();
71 let Layout { size, location, .. } = layout;
72 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
73 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
74 assert_eq!(location.x, 70f32, "x of node {:?}. Expected {}. Actual {}", node1, 70f32, location.x);
75 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1, 40f32, location.y);
76 let layout = taffy.layout(node2).unwrap();
77 let Layout { size, location, .. } = layout;
78 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
79 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2, 20f32, size.height);
80 assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node2, 80f32, location.x);
81 assert_eq!(location.y, 70f32, "y of node {:?}. Expected {}. Actual {}", node2, 70f32, location.y);
82}
83
84#[test]
85#[allow(non_snake_case)]
86fn block_absolute_rtl__content_box() {
87 #[allow(unused_imports)]
88 use taffy::{prelude::*, Layout};
89 let mut taffy = crate::new_test_tree();
90 let node0 = taffy
91 .new_leaf(taffy::style::Style {
92 box_sizing: taffy::style::BoxSizing::ContentBox,
93 position: taffy::style::Position::Absolute,
94 size: taffy::geometry::Size {
95 width: taffy::style::Dimension::from_length(20f32),
96 height: taffy::style::Dimension::from_length(20f32),
97 },
98 inset: taffy::geometry::Rect { left: length(10f32), right: auto(), top: length(10f32), bottom: auto() },
99 ..Default::default()
100 })
101 .unwrap();
102 let node1 = taffy
103 .new_leaf(taffy::style::Style {
104 box_sizing: taffy::style::BoxSizing::ContentBox,
105 position: taffy::style::Position::Absolute,
106 size: taffy::geometry::Size {
107 width: taffy::style::Dimension::from_length(20f32),
108 height: taffy::style::Dimension::from_length(20f32),
109 },
110 inset: taffy::geometry::Rect { left: auto(), right: length(10f32), top: length(40f32), bottom: auto() },
111 ..Default::default()
112 })
113 .unwrap();
114 let node2 = taffy
115 .new_leaf(taffy::style::Style {
116 box_sizing: taffy::style::BoxSizing::ContentBox,
117 position: taffy::style::Position::Absolute,
118 size: taffy::geometry::Size {
119 width: taffy::style::Dimension::from_length(20f32),
120 height: taffy::style::Dimension::from_length(20f32),
121 },
122 inset: taffy::geometry::Rect { left: auto(), right: auto(), top: length(70f32), bottom: auto() },
123 ..Default::default()
124 })
125 .unwrap();
126 let node = taffy
127 .new_with_children(
128 taffy::style::Style {
129 display: taffy::style::Display::Block,
130 box_sizing: taffy::style::BoxSizing::ContentBox,
131 direction: taffy::style::Direction::Rtl,
132 size: taffy::geometry::Size {
133 width: taffy::style::Dimension::from_length(100f32),
134 height: taffy::style::Dimension::from_length(100f32),
135 },
136 ..Default::default()
137 },
138 &[node0, node1, node2],
139 )
140 .unwrap();
141 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
142 println!("\nComputed tree:");
143 taffy.print_tree(node);
144 println!();
145 let layout = taffy.layout(node).unwrap();
146 let Layout { size, location, .. } = layout;
147 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
148 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
149 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
150 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
151 let layout = taffy.layout(node0).unwrap();
152 let Layout { size, location, .. } = layout;
153 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
154 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
155 assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node0, 10f32, location.x);
156 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node0, 10f32, location.y);
157 let layout = taffy.layout(node1).unwrap();
158 let Layout { size, location, .. } = layout;
159 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
160 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
161 assert_eq!(location.x, 70f32, "x of node {:?}. Expected {}. Actual {}", node1, 70f32, location.x);
162 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1, 40f32, location.y);
163 let layout = taffy.layout(node2).unwrap();
164 let Layout { size, location, .. } = layout;
165 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
166 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2, 20f32, size.height);
167 assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node2, 80f32, location.x);
168 assert_eq!(location.y, 70f32, "y of node {:?}. Expected {}. Actual {}", node2, 70f32, location.y);
169}