⎇ 48e4800f14c6af5cd26275fb570d11b93e279654
tests/generated/flex/align_self_baseline.rs
Historia
Quién tocó qué
crudo
Sort test fixtures and generated tests into folders (#514)
1#[test]
2fn align_self_baseline() {
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 align_self: Some(taffy::style::AlignSelf::Baseline),
9 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::Length(50f32),
11 height: taffy::style::Dimension::Length(50f32),
12 },
13 ..Default::default()
14 })
15 .unwrap();
16 let node10 = taffy
17 .new_leaf(taffy::style::Style {
18 size: taffy::geometry::Size {
19 width: taffy::style::Dimension::Length(50f32),
20 height: taffy::style::Dimension::Length(10f32),
21 },
22 ..Default::default()
23 })
24 .unwrap();
25 let node1 = taffy
26 .new_with_children(
27 taffy::style::Style {
28 align_self: Some(taffy::style::AlignSelf::Baseline),
29 size: taffy::geometry::Size {
30 width: taffy::style::Dimension::Length(50f32),
31 height: taffy::style::Dimension::Length(20f32),
32 },
33 ..Default::default()
34 },
35 &[node10],
36 )
37 .unwrap();
38 let node = taffy
39 .new_with_children(
40 taffy::style::Style {
41 size: taffy::geometry::Size {
42 width: taffy::style::Dimension::Length(100f32),
43 height: taffy::style::Dimension::Length(100f32),
44 },
45 ..Default::default()
46 },
47 &[node0, node1],
48 )
49 .unwrap();
50 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
51 println!("\nComputed tree:");
52 taffy::util::print_tree(&taffy, node);
53 println!();
54 let Layout { size, location, .. } = taffy.layout(node).unwrap();
55 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
56 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
57 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
58 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
59 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
60 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
61 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
62 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
63 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
64 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
65 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
66 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
67 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
68 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1, 40f32, location.y);
69 let Layout { size, location, .. } = taffy.layout(node10).unwrap();
70 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10, 50f32, size.width);
71 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10, 10f32, size.height);
72 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10, 0f32, location.x);
73 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10, 0f32, location.y);
74}