Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn container_with_unsized_child__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, Layout};
6 let mut taffy = crate::new_test_tree();
7 let node0 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
8 let node = taffy
9 .new_with_children(
10 taffy::style::Style {
11 size: taffy::geometry::Size {
12 width: taffy::style::Dimension::from_length(100f32),
13 height: taffy::style::Dimension::from_length(100f32),
14 },
15 ..Default::default()
16 },
17 &[node0],
18 )
19 .unwrap();
20 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
21 println!("\nComputed tree:");
22 taffy.print_tree(node);
23 println!();
24 let layout = taffy.layout(node).unwrap();
25 let Layout { size, location, .. } = layout;
26 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
27 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
28 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
29 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
30 let layout = taffy.layout(node0).unwrap();
31 let Layout { size, location, .. } = layout;
32 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node0, 0f32, size.width);
33 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
34 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
35 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
36}
37
38#[test]
39#[allow(non_snake_case)]
40fn container_with_unsized_child__content_box() {
41 #[allow(unused_imports)]
42 use taffy::{prelude::*, Layout};
43 let mut taffy = crate::new_test_tree();
44 let node0 = taffy
45 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
46 .unwrap();
47 let node = taffy
48 .new_with_children(
49 taffy::style::Style {
50 box_sizing: taffy::style::BoxSizing::ContentBox,
51 size: taffy::geometry::Size {
52 width: taffy::style::Dimension::from_length(100f32),
53 height: taffy::style::Dimension::from_length(100f32),
54 },
55 ..Default::default()
56 },
57 &[node0],
58 )
59 .unwrap();
60 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
61 println!("\nComputed tree:");
62 taffy.print_tree(node);
63 println!();
64 let layout = taffy.layout(node).unwrap();
65 let Layout { size, location, .. } = layout;
66 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
67 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
68 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
69 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
70 let layout = taffy.layout(node0).unwrap();
71 let Layout { size, location, .. } = layout;
72 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node0, 0f32, size.width);
73 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
74 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
75 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
76}