⎇ float-layout
tests/generated/grid/grid_fit_content_percent_indefinite_argument.rs
Historia
Quién tocó qué
crudo
Add `taffy_test_helpers` crate (#755)
1#[test]
2#[allow(non_snake_case)]
3fn grid_fit_content_percent_indefinite_argument__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, Layout};
6 let mut taffy = crate::new_test_tree();
7 let node0 = taffy
8 .new_leaf_with_context(
9 taffy::style::Style { ..Default::default() },
10 crate::TestNodeContext::ahem_text("HH\u{200b}HH\u{200b}HH", crate::WritingMode::Horizontal),
11 )
12 .unwrap();
13 let node = taffy
14 .new_with_children(
15 taffy::style::Style {
16 display: taffy::style::Display::Grid,
17 grid_template_rows: vec![length(40f32)],
18 grid_template_columns: vec![fit_content(percent(0.5f32))],
19 ..Default::default()
20 },
21 &[node0],
22 )
23 .unwrap();
24 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
25 println!("\nComputed tree:");
26 taffy.print_tree(node);
27 println!();
28 let layout = taffy.layout(node).unwrap();
29 let Layout { size, location, .. } = layout;
30 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node, 60f32, size.width);
31 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node, 40f32, size.height);
32 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
33 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
34 let layout = taffy.layout(node0).unwrap();
35 let Layout { size, location, .. } = layout;
36 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node0, 30f32, size.width);
37 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
38 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
39 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
40}
41
42#[test]
43#[allow(non_snake_case)]
44fn grid_fit_content_percent_indefinite_argument__content_box() {
45 #[allow(unused_imports)]
46 use taffy::{prelude::*, Layout};
47 let mut taffy = crate::new_test_tree();
48 let node0 = taffy
49 .new_leaf_with_context(
50 taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
51 crate::TestNodeContext::ahem_text("HH\u{200b}HH\u{200b}HH", crate::WritingMode::Horizontal),
52 )
53 .unwrap();
54 let node = taffy
55 .new_with_children(
56 taffy::style::Style {
57 display: taffy::style::Display::Grid,
58 box_sizing: taffy::style::BoxSizing::ContentBox,
59 grid_template_rows: vec![length(40f32)],
60 grid_template_columns: vec![fit_content(percent(0.5f32))],
61 ..Default::default()
62 },
63 &[node0],
64 )
65 .unwrap();
66 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
67 println!("\nComputed tree:");
68 taffy.print_tree(node);
69 println!();
70 let layout = taffy.layout(node).unwrap();
71 let Layout { size, location, .. } = layout;
72 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node, 60f32, size.width);
73 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node, 40f32, size.height);
74 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
75 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
76 let layout = taffy.layout(node0).unwrap();
77 let Layout { size, location, .. } = layout;
78 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node0, 30f32, size.width);
79 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
80 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
81 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
82}