tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1061HTML 997Markdown 12TOML 83120 Definiciones

Add fully reduced test case for #387 (#391)

fb0bb3a8c183a90ff68d35d15e8c6e0e77491456 · por Nico Burns · (hace 3 años) · padre 87acbeba0 · ver el árbol en este commit

Delta semántico · 2

tests/generated/mod.rs

tests/generated/percentage_sizes_should_not_prevent_flex_shrinking.rs

3 archivos · +59 −0

diff --git a/test_fixtures/percentage_sizes_should_not_prevent_flex_shrinking.html b/test_fixtures/percentage_sizes_should_not_prevent_flex_shrinking.html
new file mode 100644
index 000000000..d1bcfe8f4
--- /dev/null
+++ b/test_fixtures/percentage_sizes_should_not_prevent_flex_shrinking.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>
+    Bevy #8017
+</title>
+</head>
+<body>
+
+<div id="test-root" style="width: 200px;height:200px">
+  <div style="width: 120%;">
+      <div></div>
+  </div>
+</div>
+
+</body>
+</html>
\ No newline at end of file
diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs
index c0670224a..47cb45127 100644
--- a/tests/generated/mod.rs
+++ b/tests/generated/mod.rs
@@ -874,6 +874,7 @@ mod percentage_position_bottom_right;
 mod percentage_position_left_top;
 mod percentage_size_based_on_parent_inner_size;
 mod percentage_size_of_flex_basis;
+mod percentage_sizes_should_not_prevent_flex_shrinking;
 mod percentage_width_height;
 mod percentage_width_height_undefined_parent_size;
 mod position_root_with_rtl_should_position_withoutdirection;
diff --git a/tests/generated/percentage_sizes_should_not_prevent_flex_shrinking.rs b/tests/generated/percentage_sizes_should_not_prevent_flex_shrinking.rs
new file mode 100644
index 000000000..fa40fec88
--- /dev/null
+++ b/tests/generated/percentage_sizes_should_not_prevent_flex_shrinking.rs
@@ -0,0 +1,39 @@
+#[test]
+fn percentage_sizes_should_not_prevent_flex_shrinking() {
+    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::Percent(1.2f32), height: auto() },
+            ..Default::default()
+        })
+        .unwrap();
+    let node = taffy
+        .new_with_children(
+            taffy::style::Style {
+                size: taffy::geometry::Size {
+                    width: taffy::style::Dimension::Points(200f32),
+                    height: taffy::style::Dimension::Points(200f32),
+                },
+                ..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, 200f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 200f32, size.width);
+    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 200f32, 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, 200f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 200f32, size.width);
+    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 200f32, size.height);
+    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
+    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
+}