⎇ fd9112585b697975a342fdb76ca5b263a2b62891
tests/generated/block/block_margin_y_simple_positive.rs
History
Who touched what
raw
Rename Taffy struct to TaffyTree (#580)
1#[test]
2fn block_margin_y_simple_positive() {
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 { width: auto(), height: taffy::style::Dimension::Length(10f32) },
9 margin: taffy::geometry::Rect {
10 left: zero(),
11 right: zero(),
12 top: taffy::style::LengthPercentageAuto::Length(10f32),
13 bottom: taffy::style::LengthPercentageAuto::Length(10f32),
14 },
15 ..Default::default()
16 })
17 .unwrap();
18 let node1 = taffy
19 .new_leaf(taffy::style::Style {
20 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
21 ..Default::default()
22 })
23 .unwrap();
24 let node = taffy
25 .new_with_children(
26 taffy::style::Style {
27 display: taffy::style::Display::Block,
28 size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
29 ..Default::default()
30 },
31 &[node0, node1],
32 )
33 .unwrap();
34 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
35 println!("\nComputed tree:");
36 taffy.print_tree(node);
37 println!();
38 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
39 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
40 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
41 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node, 40f32, size.height);
42 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
43 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
44 #[cfg(feature = "content_size")]
45 assert_eq!(
46 layout.scroll_width(),
47 0f32,
48 "scroll_width of node {:?}. Expected {}. Actual {}",
49 node,
50 0f32,
51 layout.scroll_width()
52 );
53 #[cfg(feature = "content_size")]
54 assert_eq!(
55 layout.scroll_height(),
56 0f32,
57 "scroll_height of node {:?}. Expected {}. Actual {}",
58 node,
59 0f32,
60 layout.scroll_height()
61 );
62 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
63 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
64 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
65 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
66 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
67 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node0, 10f32, location.y);
68 #[cfg(feature = "content_size")]
69 assert_eq!(
70 layout.scroll_width(),
71 0f32,
72 "scroll_width of node {:?}. Expected {}. Actual {}",
73 node0,
74 0f32,
75 layout.scroll_width()
76 );
77 #[cfg(feature = "content_size")]
78 assert_eq!(
79 layout.scroll_height(),
80 0f32,
81 "scroll_height of node {:?}. Expected {}. Actual {}",
82 node0,
83 0f32,
84 layout.scroll_height()
85 );
86 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
87 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
88 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
89 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
90 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
91 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node1, 30f32, location.y);
92 #[cfg(feature = "content_size")]
93 assert_eq!(
94 layout.scroll_width(),
95 0f32,
96 "scroll_width of node {:?}. Expected {}. Actual {}",
97 node1,
98 0f32,
99 layout.scroll_width()
100 );
101 #[cfg(feature = "content_size")]
102 assert_eq!(
103 layout.scroll_height(),
104 0f32,
105 "scroll_height of node {:?}. Expected {}. Actual {}",
106 node1,
107 0f32,
108 layout.scroll_height()
109 );
110}