⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2
tests/generated/flex/measure_stretch_overrides_measure.rs
Historia
Quién tocó qué
crudo
Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn measure_stretch_overrides_measure__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 flex_grow: 1f32,
10 flex_basis: taffy::style::Dimension::from_length(5f32),
11 ..Default::default()
12 })
13 .unwrap();
14 let node1 = taffy
15 .new_leaf_with_context(
16 taffy::style::Style {
17 flex_grow: 1f32,
18 flex_basis: taffy::style::Dimension::from_length(5f32),
19 ..Default::default()
20 },
21 crate::TestNodeContext::ahem_text("H", crate::WritingMode::Horizontal),
22 )
23 .unwrap();
24 let node = taffy
25 .new_with_children(
26 taffy::style::Style {
27 size: taffy::geometry::Size {
28 width: taffy::style::Dimension::from_length(20f32),
29 height: taffy::style::Dimension::from_length(10f32),
30 },
31 ..Default::default()
32 },
33 &[node0, node1],
34 )
35 .unwrap();
36 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
37 println!("\nComputed tree:");
38 taffy.print_tree(node);
39 println!();
40 let layout = taffy.layout(node).unwrap();
41 let Layout { size, location, .. } = layout;
42 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node, 20f32, size.width);
43 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node, 10f32, size.height);
44 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
45 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
46 let layout = taffy.layout(node0).unwrap();
47 let Layout { size, location, .. } = layout;
48 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node0, 10f32, size.width);
49 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
50 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
51 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
52 let layout = taffy.layout(node1).unwrap();
53 let Layout { size, location, .. } = layout;
54 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node1, 10f32, size.width);
55 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
56 assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node1, 10f32, location.x);
57 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
58}
59
60#[test]
61#[allow(non_snake_case)]
62fn measure_stretch_overrides_measure__content_box() {
63 #[allow(unused_imports)]
64 use taffy::{prelude::*, Layout};
65 let mut taffy = crate::new_test_tree();
66 let node0 = taffy
67 .new_leaf(taffy::style::Style {
68 box_sizing: taffy::style::BoxSizing::ContentBox,
69 flex_grow: 1f32,
70 flex_basis: taffy::style::Dimension::from_length(5f32),
71 ..Default::default()
72 })
73 .unwrap();
74 let node1 = taffy
75 .new_leaf_with_context(
76 taffy::style::Style {
77 box_sizing: taffy::style::BoxSizing::ContentBox,
78 flex_grow: 1f32,
79 flex_basis: taffy::style::Dimension::from_length(5f32),
80 ..Default::default()
81 },
82 crate::TestNodeContext::ahem_text("H", crate::WritingMode::Horizontal),
83 )
84 .unwrap();
85 let node = taffy
86 .new_with_children(
87 taffy::style::Style {
88 box_sizing: taffy::style::BoxSizing::ContentBox,
89 size: taffy::geometry::Size {
90 width: taffy::style::Dimension::from_length(20f32),
91 height: taffy::style::Dimension::from_length(10f32),
92 },
93 ..Default::default()
94 },
95 &[node0, node1],
96 )
97 .unwrap();
98 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
99 println!("\nComputed tree:");
100 taffy.print_tree(node);
101 println!();
102 let layout = taffy.layout(node).unwrap();
103 let Layout { size, location, .. } = layout;
104 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node, 20f32, size.width);
105 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node, 10f32, size.height);
106 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
107 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
108 let layout = taffy.layout(node0).unwrap();
109 let Layout { size, location, .. } = layout;
110 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node0, 10f32, size.width);
111 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
112 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
113 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
114 let layout = taffy.layout(node1).unwrap();
115 let Layout { size, location, .. } = layout;
116 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node1, 10f32, size.width);
117 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
118 assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node1, 10f32, location.x);
119 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
120}