⎇ 48e4800f14c6af5cd26275fb570d11b93e279654
tests/generated/flex/measure_child_with_flex_grow.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Make test measure function non-generated (move to tests/fixtures.rs) (#529)
1#[test]
2fn measure_child_with_flex_grow() {
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 size: taffy::geometry::Size {
9 width: taffy::style::Dimension::Length(50f32),
10 height: taffy::style::Dimension::Length(50f32),
11 },
12 ..Default::default()
13 })
14 .unwrap();
15 let node1 = taffy
16 .new_leaf_with_measure(
17 taffy::style::Style { ..Default::default() },
18 taffy::tree::MeasureFunc::Raw(|known_dimensions, available_space| {
19 const TEXT: &str = "H\u{200b}H\u{200b}H\u{200b}H\u{200b}H";
20 crate::measure_standard_text(
21 known_dimensions,
22 available_space,
23 TEXT,
24 crate::WritingMode::Horizontal,
25 None,
26 )
27 }),
28 )
29 .unwrap();
30 let node = taffy
31 .new_with_children(
32 taffy::style::Style {
33 size: taffy::geometry::Size {
34 width: taffy::style::Dimension::Length(100f32),
35 height: taffy::style::Dimension::Auto,
36 },
37 ..Default::default()
38 },
39 &[node0, node1],
40 )
41 .unwrap();
42 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
43 println!("\nComputed tree:");
44 taffy::util::print_tree(&taffy, node);
45 println!();
46 let Layout { size, location, .. } = taffy.layout(node).unwrap();
47 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
48 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node, 50f32, size.height);
49 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
50 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
51 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
52 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
53 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
54 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
55 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
56 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
57 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
58 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
59 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
60 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
61}