Fix justify content with margin tests (#329)
* Fix justify content with margin test (error due to differences in gentest setup between yoga and taffy
* Fix position_root_with_rtl_should_position_withoutdirection test
b0c7d824daea2c453850812d532c277f8ac37736 · ruwaq Nico Burns · 2023-01-16T02:27:06Z (3 wata ñawpaq) · tayta b91874d4e · kay commitpi sach'ata qhaway
Semántico sayk'uy · 13
benches/generated/justify_content_column_min_height_and_margin.rs
benches/generated/justify_content_colunn_max_height_and_margin.rs
benches/generated/position_root_with_rtl_should_position_withoutdirection.rs
tests/generated/justify_content_column_min_height_and_margin.rs
tests/generated/justify_content_colunn_max_height_and_margin.rs
tests/generated/position_root_with_rtl_should_position_withoutdirection.rs
diff --git a/benches/generated/justify_content_column_min_height_and_margin.rs b/benches/generated/justify_content_column_min_height_and_margin.rs
new file mode 100644
index 000000000..206eca83f
--- /dev/null
+++ b/benches/generated/justify_content_column_min_height_and_margin.rs
@@ -0,0 +1,33 @@
+pub fn compute() {
+ #[allow(unused_imports)]
+ use taffy::prelude::*;
+ let mut taffy = taffy::Taffy::new();
+ let node00 = taffy
+ .new_leaf(taffy::style::Style {
+ size: taffy::geometry::Size {
+ width: taffy::style::Dimension::Points(20f32),
+ height: taffy::style::Dimension::Points(20f32),
+ },
+ ..Default::default()
+ })
+ .unwrap();
+ let node0 = taffy
+ .new_with_children(
+ taffy::style::Style {
+ flex_direction: taffy::style::FlexDirection::Column,
+ justify_content: Some(taffy::style::JustifyContent::Center),
+ min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(50f32) },
+ margin: taffy::geometry::Rect {
+ left: zero(),
+ right: zero(),
+ top: taffy::style::LengthPercentageAuto::Points(100f32),
+ bottom: zero(),
+ },
+ ..Default::default()
+ },
+ &[node00],
+ )
+ .unwrap();
+ let node = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node0]).unwrap();
+ taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
+}
diff --git a/benches/generated/justify_content_colunn_max_height_and_margin.rs b/benches/generated/justify_content_colunn_max_height_and_margin.rs
new file mode 100644
index 000000000..f6533d354
--- /dev/null
+++ b/benches/generated/justify_content_colunn_max_height_and_margin.rs
@@ -0,0 +1,34 @@
+pub fn compute() {
+ #[allow(unused_imports)]
+ use taffy::prelude::*;
+ let mut taffy = taffy::Taffy::new();
+ let node00 = taffy
+ .new_leaf(taffy::style::Style {
+ size: taffy::geometry::Size {
+ width: taffy::style::Dimension::Points(20f32),
+ height: taffy::style::Dimension::Points(20f32),
+ },
+ ..Default::default()
+ })
+ .unwrap();
+ let node0 = taffy
+ .new_with_children(
+ taffy::style::Style {
+ flex_direction: taffy::style::FlexDirection::Column,
+ justify_content: Some(taffy::style::JustifyContent::Center),
+ size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(100f32) },
+ max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(80f32) },
+ margin: taffy::geometry::Rect {
+ left: zero(),
+ right: zero(),
+ top: taffy::style::LengthPercentageAuto::Points(100f32),
+ bottom: zero(),
+ },
+ ..Default::default()
+ },
+ &[node00],
+ )
+ .unwrap();
+ let node = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node0]).unwrap();
+ taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
+}
diff --git a/benches/generated/mod.rs b/benches/generated/mod.rs
index dc6e01760..f7b7f74b3 100644
--- a/benches/generated/mod.rs
+++ b/benches/generated/mod.rs
@@ -561,11 +561,13 @@ mod grid_size_child_fixed_tracks;
mod justify_content_column_center;
mod justify_content_column_flex_end;
mod justify_content_column_flex_start;
+mod justify_content_column_min_height_and_margin;
mod justify_content_column_min_height_and_margin_bottom;
mod justify_content_column_min_height_and_margin_top;
mod justify_content_column_space_around;
mod justify_content_column_space_between;
mod justify_content_column_space_evenly;
+mod justify_content_colunn_max_height_and_margin;
mod justify_content_min_max;
mod justify_content_min_width_with_padding_child_width_greater_than_parent;
mod justify_content_min_width_with_padding_child_width_lower_than_parent;
@@ -681,6 +683,7 @@ mod percentage_size_based_on_parent_inner_size;
mod percentage_size_of_flex_basis;
mod percentage_width_height;
mod percentage_width_height_undefined_parent_size;
+mod position_root_with_rtl_should_position_withoutdirection;
mod relative_position_should_not_nudge_siblings;
mod rounding_flex_basis_flex_grow_row_prime_number_width;
mod rounding_flex_basis_flex_grow_row_width_of_100;
@@ -1229,11 +1232,13 @@ fn benchmark(c: &mut Criterion) {
justify_content_column_center::compute();
justify_content_column_flex_end::compute();
justify_content_column_flex_start::compute();
+ justify_content_column_min_height_and_margin::compute();
justify_content_column_min_height_and_margin_bottom::compute();
justify_content_column_min_height_and_margin_top::compute();
justify_content_column_space_around::compute();
justify_content_column_space_between::compute();
justify_content_column_space_evenly::compute();
+ justify_content_colunn_max_height_and_margin::compute();
justify_content_min_max::compute();
justify_content_min_width_with_padding_child_width_greater_than_parent::compute();
justify_content_min_width_with_padding_child_width_lower_than_parent::compute();
@@ -1349,6 +1354,7 @@ fn benchmark(c: &mut Criterion) {
percentage_size_of_flex_basis::compute();
percentage_width_height::compute();
percentage_width_height_undefined_parent_size::compute();
+ position_root_with_rtl_should_position_withoutdirection::compute();
relative_position_should_not_nudge_siblings::compute();
rounding_flex_basis_flex_grow_row_prime_number_width::compute();
rounding_flex_basis_flex_grow_row_width_of_100::compute();
diff --git a/benches/generated/position_root_with_rtl_should_position_withoutdirection.rs b/benches/generated/position_root_with_rtl_should_position_withoutdirection.rs
new file mode 100644
index 000000000..aee006c59
--- /dev/null
+++ b/benches/generated/position_root_with_rtl_should_position_withoutdirection.rs
@@ -0,0 +1,22 @@
+pub fn compute() {
+ #[allow(unused_imports)]
+ use taffy::prelude::*;
+ let mut taffy = taffy::Taffy::new();
+ let node0 = taffy
+ .new_leaf(taffy::style::Style {
+ size: taffy::geometry::Size {
+ width: taffy::style::Dimension::Points(52f32),
+ height: taffy::style::Dimension::Points(52f32),
+ },
+ inset: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentageAuto::Points(72f32),
+ right: auto(),
+ top: auto(),
+ bottom: auto(),
+ },
+ ..Default::default()
+ })
+ .unwrap();
+ let node = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node0]).unwrap();
+ taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
+}
diff --git a/test_fixtures/justify_content_column_min_height_and_margin.html b/test_fixtures/justify_content_column_min_height_and_margin.html
new file mode 100644
index 000000000..3fb17ffc2
--- /dev/null
+++ b/test_fixtures/justify_content_column_min_height_and_margin.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <script src="../scripts/gentest/test_helper.js"></script>
+ <link rel="stylesheet" type="text/css" href="../scripts/gentest/test_base_style.css">
+ <title>
+ Test description
+ </title>
+<head/>
+<body>
+
+<!-- this test has an extra node compared to the yoga version because yoga's gentest script wraps places the test
+ snippet within an extra root node. Whereas Taffy's script make the root of the snippet the test root -->
+<div id="test-root">
+ <div style="min-height: 50px; margin-top: 100px; justify-content: center; flex-direction: column;">
+ <div style="height: 20px; width: 20px;"></div>
+ </div>
+</div>
+
+</body>
+</html>
\ No newline at end of file
diff --git a/test_fixtures/justify_content_colunn_max_height_and_margin.html b/test_fixtures/justify_content_colunn_max_height_and_margin.html
new file mode 100644
index 000000000..a159d44a4
--- /dev/null
+++ b/test_fixtures/justify_content_colunn_max_height_and_margin.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <script src="../scripts/gentest/test_helper.js"></script>
+ <link rel="stylesheet" type="text/css" href="../scripts/gentest/test_base_style.css">
+ <title>
+ Test description
+ </title>
+<head/>
+<body>
+
+<!-- this test has an extra node compared to the yoga version because yoga's gentest script wraps places the test
+ snippet within an extra root node. Whereas Taffy's script make the root of the snippet the test root -->
+<div id="test-root">
+ <div style="height: 100px; max-height: 80px; margin-top: 100px; justify-content: center; flex-direction: column;">
+ <div style="height: 20px; width: 20px;"></div>
+ </div>
+</div>
+
+</body>
+</html>
\ No newline at end of file
diff --git a/test_fixtures/position_root_with_rtl_should_position_withoutdirection.html b/test_fixtures/position_root_with_rtl_should_position_withoutdirection.html
new file mode 100644
index 000000000..dd06ff5c5
--- /dev/null
+++ b/test_fixtures/position_root_with_rtl_should_position_withoutdirection.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <script src="../scripts/gentest/test_helper.js"></script>
+ <link rel="stylesheet" type="text/css" href="../scripts/gentest/test_base_style.css">
+ <title>
+ Test description
+ </title>
+<head/>
+<body>
+
+<!-- this test has an extra node compared to the yoga version because yoga's gentest script wraps places the test
+ snippet within an extra root node. Whereas Taffy's script make the root of the snippet the test root -->
+<div id="test-root">
+ <div style="height: 52px; width: 52px; left: 72px; "></div>
+</div>
+
+</body>
+</html>
\ No newline at end of file
diff --git a/test_fixtures/xjustify_content_column_min_height_and_margin.html b/test_fixtures/xjustify_content_column_min_height_and_margin.html
deleted file mode 100644
index d1716ad1b..000000000
--- a/test_fixtures/xjustify_content_column_min_height_and_margin.html
+++ /dev/null
@@ -1,17 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
- <script src="../scripts/gentest/test_helper.js"></script>
- <link rel="stylesheet" type="text/css" href="../scripts/gentest/test_base_style.css">
- <title>
- Test description
- </title>
-<head/>
-<body>
-
-<div id="test-root" style="min-height: 50px; margin-top: 100px; justify-content: center; flex-direction: column;">
- <div style="height: 20px; width: 20px;"></div>
-</div>
-
-</body>
-</html>
\ No newline at end of file
diff --git a/test_fixtures/xjustify_content_colunn_max_height_and_margin.html b/test_fixtures/xjustify_content_colunn_max_height_and_margin.html
deleted file mode 100644
index 8d1a2d4ea..000000000
--- a/test_fixtures/xjustify_content_colunn_max_height_and_margin.html
+++ /dev/null
@@ -1,17 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
- <script src="../scripts/gentest/test_helper.js"></script>
- <link rel="stylesheet" type="text/css" href="../scripts/gentest/test_base_style.css">
- <title>
- Test description
- </title>
-<head/>
-<body>
-
-<div id="test-root" style="height: 100px; max-height: 80px; margin-top: 100px; justify-content: center; flex-direction: column;">
- <div style="height: 20px; width: 20px;"></div>
-</div>
-
-</body>
-</html>
\ No newline at end of file
diff --git a/test_fixtures/xposition_root_with_rtl_should_position_withoutdirection.html b/test_fixtures/xposition_root_with_rtl_should_position_withoutdirection.html
deleted file mode 100644
index bedbd0b21..000000000
--- a/test_fixtures/xposition_root_with_rtl_should_position_withoutdirection.html
+++ /dev/null
@@ -1,15 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
- <script src="../scripts/gentest/test_helper.js"></script>
- <link rel="stylesheet" type="text/css" href="../scripts/gentest/test_base_style.css">
- <title>
- Test description
- </title>
-<head/>
-<body>
-
-<div id="test-root" style="height: 52px; width: 52px; left: 72px; "></div>
-
-</body>
-</html>
\ No newline at end of file
diff --git a/tests/generated/justify_content_column_min_height_and_margin.rs b/tests/generated/justify_content_column_min_height_and_margin.rs
new file mode 100644
index 000000000..f98c9f98f
--- /dev/null
+++ b/tests/generated/justify_content_column_min_height_and_margin.rs
@@ -0,0 +1,53 @@
+#[test]
+fn justify_content_column_min_height_and_margin() {
+ use slotmap::Key;
+ #[allow(unused_imports)]
+ use taffy::{layout::Layout, prelude::*};
+ let mut taffy = taffy::Taffy::new();
+ let node00 = taffy
+ .new_leaf(taffy::style::Style {
+ size: taffy::geometry::Size {
+ width: taffy::style::Dimension::Points(20f32),
+ height: taffy::style::Dimension::Points(20f32),
+ },
+ ..Default::default()
+ })
+ .unwrap();
+ let node0 = taffy
+ .new_with_children(
+ taffy::style::Style {
+ flex_direction: taffy::style::FlexDirection::Column,
+ justify_content: Some(taffy::style::JustifyContent::Center),
+ min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(50f32) },
+ margin: taffy::geometry::Rect {
+ left: zero(),
+ right: zero(),
+ top: taffy::style::LengthPercentageAuto::Points(100f32),
+ bottom: zero(),
+ },
+ ..Default::default()
+ },
+ &[node00],
+ )
+ .unwrap();
+ let node = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node0]).unwrap();
+ taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
+ println!("\nComputed tree:");
+ taffy::debug::print_tree(&taffy, node);
+ println!();
+ let Layout { size, location, .. } = taffy.layout(node).unwrap();
+ assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 20f32, size.width);
+ assert_eq!(size.height, 150f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 150f32, size.height);
+ assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
+ assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
+ let Layout { size, location, .. } = taffy.layout(node0).unwrap();
+ assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.width);
+ assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height);
+ assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
+ assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, location.y);
+ let Layout { size, location, .. } = taffy.layout(node00).unwrap();
+ assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 20f32, size.width);
+ assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 20f32, size.height);
+ assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.x);
+ assert_eq!(location.y, 15f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 15f32, location.y);
+}
diff --git a/tests/generated/justify_content_colunn_max_height_and_margin.rs b/tests/generated/justify_content_colunn_max_height_and_margin.rs
new file mode 100644
index 000000000..02bd315cd
--- /dev/null
+++ b/tests/generated/justify_content_colunn_max_height_and_margin.rs
@@ -0,0 +1,54 @@
+#[test]
+fn justify_content_colunn_max_height_and_margin() {
+ use slotmap::Key;
+ #[allow(unused_imports)]
+ use taffy::{layout::Layout, prelude::*};
+ let mut taffy = taffy::Taffy::new();
+ let node00 = taffy
+ .new_leaf(taffy::style::Style {
+ size: taffy::geometry::Size {
+ width: taffy::style::Dimension::Points(20f32),
+ height: taffy::style::Dimension::Points(20f32),
+ },
+ ..Default::default()
+ })
+ .unwrap();
+ let node0 = taffy
+ .new_with_children(
+ taffy::style::Style {
+ flex_direction: taffy::style::FlexDirection::Column,
+ justify_content: Some(taffy::style::JustifyContent::Center),
+ size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(100f32) },
+ max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(80f32) },
+ margin: taffy::geometry::Rect {
+ left: zero(),
+ right: zero(),
+ top: taffy::style::LengthPercentageAuto::Points(100f32),
+ bottom: zero(),
+ },
+ ..Default::default()
+ },
+ &[node00],
+ )
+ .unwrap();
+ let node = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node0]).unwrap();
+ taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
+ println!("\nComputed tree:");
+ taffy::debug::print_tree(&taffy, node);
+ println!();
+ let Layout { size, location, .. } = taffy.layout(node).unwrap();
+ assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 20f32, size.width);
+ assert_eq!(size.height, 180f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 180f32, size.height);
+ assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
+ assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
+ let Layout { size, location, .. } = taffy.layout(node0).unwrap();
+ assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.width);
+ assert_eq!(size.height, 80f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 80f32, size.height);
+ assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
+ assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, location.y);
+ let Layout { size, location, .. } = taffy.layout(node00).unwrap();
+ assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 20f32, size.width);
+ assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 20f32, size.height);
+ assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.x);
+ assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 30f32, location.y);
+}
diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs
index 829311ccb..5822cbd09 100644
--- a/tests/generated/mod.rs
+++ b/tests/generated/mod.rs
@@ -560,11 +560,13 @@ mod grid_size_child_fixed_tracks;
mod justify_content_column_center;
mod justify_content_column_flex_end;
mod justify_content_column_flex_start;
+mod justify_content_column_min_height_and_margin;
mod justify_content_column_min_height_and_margin_bottom;
mod justify_content_column_min_height_and_margin_top;
mod justify_content_column_space_around;
mod justify_content_column_space_between;
mod justify_content_column_space_evenly;
+mod justify_content_colunn_max_height_and_margin;
mod justify_content_min_max;
mod justify_content_min_width_with_padding_child_width_greater_than_parent;
mod justify_content_min_width_with_padding_child_width_lower_than_parent;
@@ -680,6 +682,7 @@ mod percentage_size_based_on_parent_inner_size;
mod percentage_size_of_flex_basis;
mod percentage_width_height;
mod percentage_width_height_undefined_parent_size;
+mod position_root_with_rtl_should_position_withoutdirection;
mod relative_position_should_not_nudge_siblings;
mod rounding_flex_basis_flex_grow_row_prime_number_width;
mod rounding_flex_basis_flex_grow_row_width_of_100;
diff --git a/tests/generated/position_root_with_rtl_should_position_withoutdirection.rs b/tests/generated/position_root_with_rtl_should_position_withoutdirection.rs
new file mode 100644
index 000000000..95b97d9fd
--- /dev/null
+++ b/tests/generated/position_root_with_rtl_should_position_withoutdirection.rs
@@ -0,0 +1,37 @@
+#[test]
+fn position_root_with_rtl_should_position_withoutdirection() {
+ use slotmap::Key;
+ #[allow(unused_imports)]
+ use taffy::{layout::Layout, prelude::*};
+ let mut taffy = taffy::Taffy::new();
+ let node0 = taffy
+ .new_leaf(taffy::style::Style {
+ size: taffy::geometry::Size {
+ width: taffy::style::Dimension::Points(52f32),
+ height: taffy::style::Dimension::Points(52f32),
+ },
+ inset: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentageAuto::Points(72f32),
+ right: auto(),
+ top: auto(),
+ bottom: auto(),
+ },
+ ..Default::default()
+ })
+ .unwrap();
+ let node = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node0]).unwrap();
+ taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
+ println!("\nComputed tree:");
+ taffy::debug::print_tree(&taffy, node);
+ println!();
+ let Layout { size, location, .. } = taffy.layout(node).unwrap();
+ assert_eq!(size.width, 52f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 52f32, size.width);
+ assert_eq!(size.height, 52f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 52f32, size.height);
+ assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
+ assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
+ let Layout { size, location, .. } = taffy.layout(node0).unwrap();
+ assert_eq!(size.width, 52f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 52f32, size.width);
+ assert_eq!(size.height, 52f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 52f32, size.height);
+ assert_eq!(location.x, 72f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 72f32, location.x);
+ assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
+}