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