From fad89190354656cc12bdfc2dc20d9a13ab1ba338 Mon Sep 17 00:00:00 2001
From: Nico Burns
Date: Sun, 8 Jan 2023 14:40:28 +0000
Subject: [PATCH] Add absolute positioning margin test
---
.../generated/absolute_margin_bottom_left.rs | 36 +++++++++++++
benches/generated/mod.rs | 2 +
.../absolute_margin_bottom_left.html | 17 +++++++
.../generated/absolute_margin_bottom_left.rs | 51 +++++++++++++++++++
tests/generated/mod.rs | 1 +
5 files changed, 107 insertions(+)
create mode 100644 benches/generated/absolute_margin_bottom_left.rs
create mode 100644 test_fixtures/absolute_margin_bottom_left.html
create mode 100644 tests/generated/absolute_margin_bottom_left.rs
diff --git a/benches/generated/absolute_margin_bottom_left.rs b/benches/generated/absolute_margin_bottom_left.rs
new file mode 100644
index 000000000..9848f6ca6
--- /dev/null
+++ b/benches/generated/absolute_margin_bottom_left.rs
@@ -0,0 +1,36 @@
+pub fn compute() {
+ #[allow(unused_imports)]
+ use taffy::prelude::*;
+ let mut taffy = taffy::Taffy::new();
+ let node0 = taffy
+ .new_leaf(taffy::style::Style {
+ position: taffy::style::Position::Absolute,
+ size: taffy::geometry::Size {
+ width: taffy::style::Dimension::Points(10f32),
+ height: taffy::style::Dimension::Points(10f32),
+ },
+ margin: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentageAuto::Points(10f32),
+ right: zero(),
+ top: zero(),
+ bottom: taffy::style::LengthPercentageAuto::Points(10f32),
+ },
+ ..Default::default()
+ })
+ .unwrap();
+ let node = taffy
+ .new_with_children(
+ taffy::style::Style {
+ flex_direction: taffy::style::FlexDirection::Column,
+ justify_content: Some(taffy::style::JustifyContent::End),
+ size: taffy::geometry::Size {
+ width: taffy::style::Dimension::Points(100f32),
+ height: taffy::style::Dimension::Points(100f32),
+ },
+ ..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 94b0201ba..544122fba 100644
--- a/benches/generated/mod.rs
+++ b/benches/generated/mod.rs
@@ -82,6 +82,7 @@ mod absolute_layout_width_height_end_bottom;
mod absolute_layout_width_height_start_top;
mod absolute_layout_width_height_start_top_end_bottom;
mod absolute_layout_within_border;
+mod absolute_margin_bottom_left;
mod align_baseline;
mod align_baseline_child_multiline;
mod align_baseline_nested_child;
@@ -669,6 +670,7 @@ fn benchmark(c: &mut Criterion) {
absolute_layout_width_height_start_top::compute();
absolute_layout_width_height_start_top_end_bottom::compute();
absolute_layout_within_border::compute();
+ absolute_margin_bottom_left::compute();
align_baseline::compute();
align_baseline_child_multiline::compute();
align_baseline_nested_child::compute();
diff --git a/test_fixtures/absolute_margin_bottom_left.html b/test_fixtures/absolute_margin_bottom_left.html
new file mode 100644
index 000000000..7a4480e6f
--- /dev/null
+++ b/test_fixtures/absolute_margin_bottom_left.html
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+ Test description
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/generated/absolute_margin_bottom_left.rs b/tests/generated/absolute_margin_bottom_left.rs
new file mode 100644
index 000000000..7061fbcc4
--- /dev/null
+++ b/tests/generated/absolute_margin_bottom_left.rs
@@ -0,0 +1,51 @@
+#[test]
+fn absolute_margin_bottom_left() {
+ 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 {
+ position: taffy::style::Position::Absolute,
+ size: taffy::geometry::Size {
+ width: taffy::style::Dimension::Points(10f32),
+ height: taffy::style::Dimension::Points(10f32),
+ },
+ margin: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentageAuto::Points(10f32),
+ right: zero(),
+ top: zero(),
+ bottom: taffy::style::LengthPercentageAuto::Points(10f32),
+ },
+ ..Default::default()
+ })
+ .unwrap();
+ let node = taffy
+ .new_with_children(
+ taffy::style::Style {
+ flex_direction: taffy::style::FlexDirection::Column,
+ justify_content: Some(taffy::style::JustifyContent::End),
+ size: taffy::geometry::Size {
+ width: taffy::style::Dimension::Points(100f32),
+ height: taffy::style::Dimension::Points(100f32),
+ },
+ ..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, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width);
+ assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, 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, 10f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 10f32, size.width);
+ assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 10f32, size.height);
+ assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 10f32, location.x);
+ assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 80f32, location.y);
+}
diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs
index a6ba11482..02e609fe6 100644
--- a/tests/generated/mod.rs
+++ b/tests/generated/mod.rs
@@ -81,6 +81,7 @@ mod absolute_layout_width_height_end_bottom;
mod absolute_layout_width_height_start_top;
mod absolute_layout_width_height_start_top_end_bottom;
mod absolute_layout_within_border;
+mod absolute_margin_bottom_left;
mod align_baseline;
mod align_baseline_child_multiline;
mod align_baseline_nested_child;