⎇ 477ff4aff498cbae4cdfbf0cda1ee5b04c784f08
tests/generated/block/block_padding_intrinsic_size.rs
History
Who touched what
raw
Rename Taffy struct to TaffyTree (#580)
1#[test]
2fn block_padding_intrinsic_size() {
3 #[allow(unused_imports)]
4 use taffy::{prelude::*, tree::Layout, TaffyTree};
5 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6 let node0 = taffy
7 .new_leaf(taffy::style::Style {
8 size: taffy::geometry::Size {
9 width: taffy::style::Dimension::Length(50f32),
10 height: taffy::style::Dimension::Length(10f32),
11 },
12 ..Default::default()
13 })
14 .unwrap();
15 let node1 = taffy
16 .new_leaf(taffy::style::Style {
17 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
18 ..Default::default()
19 })
20 .unwrap();
21 let node = taffy
22 .new_with_children(
23 taffy::style::Style {
24 display: taffy::style::Display::Block,
25 padding: taffy::geometry::Rect {
26 left: taffy::style::LengthPercentage::Length(8f32),
27 right: taffy::style::LengthPercentage::Length(4f32),
28 top: taffy::style::LengthPercentage::Length(2f32),
29 bottom: taffy::style::LengthPercentage::Length(6f32),
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 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
41 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
42 assert_eq!(size.width, 62f32, "width of node {:?}. Expected {}. Actual {}", node, 62f32, size.width);
43 assert_eq!(size.height, 28f32, "height of node {:?}. Expected {}. Actual {}", node, 28f32, 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 #[cfg(feature = "content_size")]
47 assert_eq!(
48 layout.scroll_width(),
49 0f32,
50 "scroll_width of node {:?}. Expected {}. Actual {}",
51 node,
52 0f32,
53 layout.scroll_width()
54 );
55 #[cfg(feature = "content_size")]
56 assert_eq!(
57 layout.scroll_height(),
58 0f32,
59 "scroll_height of node {:?}. Expected {}. Actual {}",
60 node,
61 0f32,
62 layout.scroll_height()
63 );
64 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
65 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
66 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
67 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
68 assert_eq!(location.x, 8f32, "x of node {:?}. Expected {}. Actual {}", node0, 8f32, location.x);
69 assert_eq!(location.y, 2f32, "y of node {:?}. Expected {}. Actual {}", node0, 2f32, location.y);
70 #[cfg(feature = "content_size")]
71 assert_eq!(
72 layout.scroll_width(),
73 0f32,
74 "scroll_width of node {:?}. Expected {}. Actual {}",
75 node0,
76 0f32,
77 layout.scroll_width()
78 );
79 #[cfg(feature = "content_size")]
80 assert_eq!(
81 layout.scroll_height(),
82 0f32,
83 "scroll_height of node {:?}. Expected {}. Actual {}",
84 node0,
85 0f32,
86 layout.scroll_height()
87 );
88 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
89 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
90 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
91 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
92 assert_eq!(location.x, 8f32, "x of node {:?}. Expected {}. Actual {}", node1, 8f32, location.x);
93 assert_eq!(location.y, 12f32, "y of node {:?}. Expected {}. Actual {}", node1, 12f32, location.y);
94 #[cfg(feature = "content_size")]
95 assert_eq!(
96 layout.scroll_width(),
97 0f32,
98 "scroll_width of node {:?}. Expected {}. Actual {}",
99 node1,
100 0f32,
101 layout.scroll_width()
102 );
103 #[cfg(feature = "content_size")]
104 assert_eq!(
105 layout.scroll_height(),
106 0f32,
107 "scroll_height of node {:?}. Expected {}. Actual {}",
108 node1,
109 0f32,
110 layout.scroll_height()
111 );
112}