⎇ 837d03fde9d8a4efa0f4eaf1e8be2fd34a719a50
tests/generated/only_shrinkable_item_with_flex_basis_zero.rs
Historia
Quién tocó qué
crudo
1#[test]
2fn only_shrinkable_item_with_flex_basis_zero() {
3 use slotmap::Key;
4 #[allow(unused_imports)]
5 use taffy::{layout::Layout, prelude::*};
6 let mut taffy = taffy::Taffy::new();
7 let node0 = taffy
8 .new_leaf(taffy::style::Style {
9 flex_shrink: 1f32,
10 flex_basis: taffy::style::Dimension::Points(0f32),
11 ..Default::default()
12 })
13 .unwrap();
14 let node1 = taffy
15 .new_leaf(taffy::style::Style {
16 flex_shrink: 0f32,
17 flex_basis: taffy::style::Dimension::Points(93f32),
18 margin: taffy::geometry::Rect {
19 left: zero(),
20 right: zero(),
21 top: zero(),
22 bottom: taffy::style::LengthPercentageAuto::Points(6f32),
23 },
24 ..Default::default()
25 })
26 .unwrap();
27 let node2 = taffy
28 .new_leaf(taffy::style::Style {
29 flex_shrink: 0f32,
30 flex_basis: taffy::style::Dimension::Points(764f32),
31 ..Default::default()
32 })
33 .unwrap();
34 let node = taffy
35 .new_with_children(
36 taffy::style::Style {
37 flex_direction: taffy::style::FlexDirection::Column,
38 size: taffy::geometry::Size { width: taffy::style::Dimension::Points(480f32), height: auto() },
39 max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(764f32) },
40 ..Default::default()
41 },
42 &[node0, node1, node2],
43 )
44 .unwrap();
45 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
46 println!("\nComputed tree:");
47 taffy::debug::print_tree(&taffy, node);
48 println!();
49 let Layout { size, location, .. } = taffy.layout(node).unwrap();
50 assert_eq!(size.width, 480f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 480f32, size.width);
51 assert_eq!(size.height, 764f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 764f32, size.height);
52 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
53 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
54 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
55 assert_eq!(size.width, 480f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 480f32, size.width);
56 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, size.height);
57 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
58 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
59 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
60 assert_eq!(size.width, 480f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 480f32, size.width);
61 assert_eq!(size.height, 93f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 93f32, size.height);
62 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.x);
63 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.y);
64 let Layout { size, location, .. } = taffy.layout(node2).unwrap();
65 assert_eq!(size.width, 480f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 480f32, size.width);
66 assert_eq!(size.height, 764f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 764f32, size.height);
67 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 0f32, location.x);
68 assert_eq!(location.y, 99f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 99f32, location.y);
69}