⎇ 568f643327ec6b4879df0087def7f4e66b6acafb
tests/generated/block_margin_y_collapse_through_positive.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Implement CSS Block layout (`Display::Block`) (#474)
1#[test]
2fn block_margin_y_collapse_through_positive() {
3 #[allow(unused_imports)]
4 use taffy::{prelude::*, tree::Layout};
5 let mut taffy = taffy::Taffy::new();
6 let node0 = taffy
7 .new_leaf(taffy::style::Style {
8 display: taffy::style::Display::Block,
9 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
10 margin: taffy::geometry::Rect {
11 left: zero(),
12 right: zero(),
13 top: zero(),
14 bottom: taffy::style::LengthPercentageAuto::Length(10f32),
15 },
16 ..Default::default()
17 })
18 .unwrap();
19 let node1 = taffy
20 .new_leaf(taffy::style::Style {
21 display: taffy::style::Display::Block,
22 margin: taffy::geometry::Rect {
23 left: zero(),
24 right: zero(),
25 top: taffy::style::LengthPercentageAuto::Length(10f32),
26 bottom: taffy::style::LengthPercentageAuto::Length(10f32),
27 },
28 ..Default::default()
29 })
30 .unwrap();
31 let node2 = taffy
32 .new_leaf(taffy::style::Style {
33 display: taffy::style::Display::Block,
34 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
35 margin: taffy::geometry::Rect {
36 left: zero(),
37 right: zero(),
38 top: taffy::style::LengthPercentageAuto::Length(10f32),
39 bottom: zero(),
40 },
41 ..Default::default()
42 })
43 .unwrap();
44 let node = taffy
45 .new_with_children(
46 taffy::style::Style {
47 display: taffy::style::Display::Block,
48 size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
49 ..Default::default()
50 },
51 &[node0, node1, node2],
52 )
53 .unwrap();
54 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
55 println!("\nComputed tree:");
56 taffy::util::print_tree(&taffy, node);
57 println!();
58 let Layout { size, location, .. } = taffy.layout(node).unwrap();
59 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
60 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node, 30f32, size.height);
61 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
62 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
63 let 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, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
68 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
69 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
70 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node1, 0f32, size.height);
71 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
72 assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node1, 20f32, location.y);
73 let Layout { size, location, .. } = taffy.layout(node2).unwrap();
74 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
75 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height);
76 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
77 assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node2, 20f32, location.y);
78}