From 1ea575684d6c614a5c4569b34d7e0b2f0f087576 Mon Sep 17 00:00:00 2001 From: Joe Vilches Date: Thu, 7 Dec 2023 21:25:45 -0800 Subject: [PATCH] Enable previously broken absolute positioning tests (#1488) Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1488 These were disabled when they were written because they were broken. The recent changes made them pass now so lets enable them. I also added another test that is already passing Reviewed By: NickGerleman Differential Revision: D51404875 fbshipit-source-id: ed10004968b871c1d033640d75138f00afc15968 --- gentest/fixtures/YGAbsolutePositionTest.html | 6 +- gentest/fixtures/YGStaticPositionTest.html | 9 ++- .../facebook/yoga/YGAbsolutePositionTest.java | 3 - .../facebook/yoga/YGStaticPositionTest.java | 59 ++++++++++++++++- .../generated/YGAbsolutePositionTest.test.ts | 6 +- .../generated/YGStaticPositionTest.test.ts | 66 ++++++++++++++++++- tests/generated/YGAbsolutePositionTest.cpp | 6 -- tests/generated/YGStaticPositionTest.cpp | 61 ++++++++++++++++- 8 files changed, 196 insertions(+), 20 deletions(-) diff --git a/gentest/fixtures/YGAbsolutePositionTest.html b/gentest/fixtures/YGAbsolutePositionTest.html index 71aa3a15b6..557ce47dd1 100644 --- a/gentest/fixtures/YGAbsolutePositionTest.html +++ b/gentest/fixtures/YGAbsolutePositionTest.html @@ -101,15 +101,15 @@
-
+
-
+
-
+
diff --git a/gentest/fixtures/YGStaticPositionTest.html b/gentest/fixtures/YGStaticPositionTest.html index 8ebbb14d29..16579b51cf 100644 --- a/gentest/fixtures/YGStaticPositionTest.html +++ b/gentest/fixtures/YGStaticPositionTest.html @@ -304,7 +304,7 @@
-
+
@@ -633,3 +633,10 @@
+ +
+
+
+
diff --git a/java/tests/com/facebook/yoga/YGAbsolutePositionTest.java b/java/tests/com/facebook/yoga/YGAbsolutePositionTest.java index db06c1c092..5e9f2d4e12 100644 --- a/java/tests/com/facebook/yoga/YGAbsolutePositionTest.java +++ b/java/tests/com/facebook/yoga/YGAbsolutePositionTest.java @@ -1214,7 +1214,6 @@ public void test_absolute_layout_percentage_height_based_on_padded_parent_and_al } @Test - @Ignore public void test_absolute_layout_padding_left() { YogaConfig config = YogaConfigFactory.create(); config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ABSOLUTE_PERCENTAGE_AGAINST_PADDING_EDGE, true); @@ -1258,7 +1257,6 @@ public void test_absolute_layout_padding_left() { } @Test - @Ignore public void test_absolute_layout_padding_right() { YogaConfig config = YogaConfigFactory.create(); config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ABSOLUTE_PERCENTAGE_AGAINST_PADDING_EDGE, true); @@ -1302,7 +1300,6 @@ public void test_absolute_layout_padding_right() { } @Test - @Ignore public void test_absolute_layout_padding_top() { YogaConfig config = YogaConfigFactory.create(); config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ABSOLUTE_PERCENTAGE_AGAINST_PADDING_EDGE, true); diff --git a/java/tests/com/facebook/yoga/YGStaticPositionTest.java b/java/tests/com/facebook/yoga/YGStaticPositionTest.java index 24667d8757..0080d73a68 100644 --- a/java/tests/com/facebook/yoga/YGStaticPositionTest.java +++ b/java/tests/com/facebook/yoga/YGStaticPositionTest.java @@ -2477,7 +2477,6 @@ public void test_static_position_static_child_containing_block_padding_box() { } @Test - @Ignore public void test_static_position_absolute_child_containing_block_content_box() { YogaConfig config = YogaConfigFactory.create(); config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ABSOLUTE_PERCENTAGE_AGAINST_PADDING_EDGE, true); @@ -5442,6 +5441,64 @@ public void test_static_position_align_flex_end_amalgamation() { assertEquals(50f, root_child0_child0_child2_child0.getLayoutHeight(), 0.0f); } + @Test + public void test_static_position_static_root() { + YogaConfig config = YogaConfigFactory.create(); + config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ABSOLUTE_PERCENTAGE_AGAINST_PADDING_EDGE, true); + + final YogaNode root = createNode(config); + root.setPositionType(YogaPositionType.STATIC); + root.setPadding(YogaEdge.LEFT, 6); + root.setPadding(YogaEdge.TOP, 1); + root.setPadding(YogaEdge.RIGHT, 11); + root.setPadding(YogaEdge.BOTTOM, 4); + root.setWidth(100f); + root.setHeight(200f); + + final YogaNode root_child0 = createNode(config); + root_child0.setPositionType(YogaPositionType.ABSOLUTE); + root_child0.setMargin(YogaEdge.LEFT, 12f); + root_child0.setMargin(YogaEdge.TOP, 11f); + root_child0.setMargin(YogaEdge.RIGHT, 15f); + root_child0.setMargin(YogaEdge.BOTTOM, 1f); + root_child0.setPadding(YogaEdge.LEFT, 3); + root_child0.setPadding(YogaEdge.TOP, 7); + root_child0.setPadding(YogaEdge.RIGHT, 5); + root_child0.setPadding(YogaEdge.BOTTOM, 4); + root_child0.setBorder(YogaEdge.LEFT, 4f); + root_child0.setBorder(YogaEdge.TOP, 3f); + root_child0.setBorder(YogaEdge.RIGHT, 2f); + root_child0.setBorder(YogaEdge.BOTTOM, 1f); + root_child0.setWidthPercent(50f); + root_child0.setHeightPercent(50f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(200f, root.getLayoutHeight(), 0.0f); + + assertEquals(18f, root_child0.getLayoutX(), 0.0f); + assertEquals(12f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(200f, root.getLayoutHeight(), 0.0f); + + assertEquals(24f, root_child0.getLayoutX(), 0.0f); + assertEquals(12f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + } + private YogaNode createNode(YogaConfig config) { return mNodeFactory.create(config); } diff --git a/javascript/tests/generated/YGAbsolutePositionTest.test.ts b/javascript/tests/generated/YGAbsolutePositionTest.test.ts index 2197819bc5..e9810a8b5d 100644 --- a/javascript/tests/generated/YGAbsolutePositionTest.test.ts +++ b/javascript/tests/generated/YGAbsolutePositionTest.test.ts @@ -1356,7 +1356,7 @@ test('absolute_layout_percentage_height_based_on_padded_parent_and_align_items_c config.free(); } }); -test.skip('absolute_layout_padding_left', () => { +test('absolute_layout_padding_left', () => { const config = Yoga.Config.create(); let root; @@ -1405,7 +1405,7 @@ test.skip('absolute_layout_padding_left', () => { config.free(); } }); -test.skip('absolute_layout_padding_right', () => { +test('absolute_layout_padding_right', () => { const config = Yoga.Config.create(); let root; @@ -1454,7 +1454,7 @@ test.skip('absolute_layout_padding_right', () => { config.free(); } }); -test.skip('absolute_layout_padding_top', () => { +test('absolute_layout_padding_top', () => { const config = Yoga.Config.create(); let root; diff --git a/javascript/tests/generated/YGStaticPositionTest.test.ts b/javascript/tests/generated/YGStaticPositionTest.test.ts index 52b517bb39..2370e7b65d 100644 --- a/javascript/tests/generated/YGStaticPositionTest.test.ts +++ b/javascript/tests/generated/YGStaticPositionTest.test.ts @@ -2680,7 +2680,7 @@ test('static_position_static_child_containing_block_padding_box', () => { config.free(); } }); -test.skip('static_position_absolute_child_containing_block_content_box', () => { +test('static_position_absolute_child_containing_block_content_box', () => { const config = Yoga.Config.create(); let root; @@ -5765,3 +5765,67 @@ test('static_position_align_flex_end_amalgamation', () => { config.free(); } }); +test('static_position_static_root', () => { + const config = Yoga.Config.create(); + let root; + + config.setExperimentalFeatureEnabled(ExperimentalFeature.AbsolutePercentageAgainstPaddingEdge, true); + + try { + root = Yoga.Node.create(config); + root.setPositionType(PositionType.Static); + root.setPadding(Edge.Left, 6); + root.setPadding(Edge.Top, 1); + root.setPadding(Edge.Right, 11); + root.setPadding(Edge.Bottom, 4); + root.setWidth(100); + root.setHeight(200); + + const root_child0 = Yoga.Node.create(config); + root_child0.setPositionType(PositionType.Absolute); + root_child0.setMargin(Edge.Left, 12); + root_child0.setMargin(Edge.Top, 11); + root_child0.setMargin(Edge.Right, 15); + root_child0.setMargin(Edge.Bottom, 1); + root_child0.setPadding(Edge.Left, 3); + root_child0.setPadding(Edge.Top, 7); + root_child0.setPadding(Edge.Right, 5); + root_child0.setPadding(Edge.Bottom, 4); + root_child0.setBorder(Edge.Left, 4); + root_child0.setBorder(Edge.Top, 3); + root_child0.setBorder(Edge.Right, 2); + root_child0.setBorder(Edge.Bottom, 1); + root_child0.setWidth("50%"); + root_child0.setHeight("50%"); + root.insertChild(root_child0, 0); + root.calculateLayout(undefined, undefined, Direction.LTR); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(200); + + expect(root_child0.getComputedLeft()).toBe(18); + expect(root_child0.getComputedTop()).toBe(12); + expect(root_child0.getComputedWidth()).toBe(50); + expect(root_child0.getComputedHeight()).toBe(100); + + root.calculateLayout(undefined, undefined, Direction.RTL); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(200); + + expect(root_child0.getComputedLeft()).toBe(24); + expect(root_child0.getComputedTop()).toBe(12); + expect(root_child0.getComputedWidth()).toBe(50); + expect(root_child0.getComputedHeight()).toBe(100); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); diff --git a/tests/generated/YGAbsolutePositionTest.cpp b/tests/generated/YGAbsolutePositionTest.cpp index f2fcdbcf6a..0e6e497cf0 100644 --- a/tests/generated/YGAbsolutePositionTest.cpp +++ b/tests/generated/YGAbsolutePositionTest.cpp @@ -1225,8 +1225,6 @@ TEST(YogaTest, absolute_layout_percentage_height_based_on_padded_parent_and_alig } TEST(YogaTest, absolute_layout_padding_left) { - GTEST_SKIP(); - const YGConfigRef config = YGConfigNew(); YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge, true); @@ -1271,8 +1269,6 @@ TEST(YogaTest, absolute_layout_padding_left) { } TEST(YogaTest, absolute_layout_padding_right) { - GTEST_SKIP(); - const YGConfigRef config = YGConfigNew(); YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge, true); @@ -1317,8 +1313,6 @@ TEST(YogaTest, absolute_layout_padding_right) { } TEST(YogaTest, absolute_layout_padding_top) { - GTEST_SKIP(); - const YGConfigRef config = YGConfigNew(); YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge, true); diff --git a/tests/generated/YGStaticPositionTest.cpp b/tests/generated/YGStaticPositionTest.cpp index 51fd1a8e3e..22c2c56e21 100644 --- a/tests/generated/YGStaticPositionTest.cpp +++ b/tests/generated/YGStaticPositionTest.cpp @@ -2497,8 +2497,6 @@ TEST(YogaTest, static_position_static_child_containing_block_padding_box) { } TEST(YogaTest, static_position_absolute_child_containing_block_content_box) { - GTEST_SKIP(); - const YGConfigRef config = YGConfigNew(); YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge, true); @@ -5482,3 +5480,62 @@ TEST(YogaTest, static_position_align_flex_end_amalgamation) { YGConfigFree(config); } + +TEST(YogaTest, static_position_static_root) { + const YGConfigRef config = YGConfigNew(); + YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge, true); + + const YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root, YGPositionTypeStatic); + YGNodeStyleSetPadding(root, YGEdgeLeft, 6); + YGNodeStyleSetPadding(root, YGEdgeTop, 1); + YGNodeStyleSetPadding(root, YGEdgeRight, 11); + YGNodeStyleSetPadding(root, YGEdgeBottom, 4); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 200); + + const YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); + YGNodeStyleSetMargin(root_child0, YGEdgeLeft, 12); + YGNodeStyleSetMargin(root_child0, YGEdgeTop, 11); + YGNodeStyleSetMargin(root_child0, YGEdgeRight, 15); + YGNodeStyleSetMargin(root_child0, YGEdgeBottom, 1); + YGNodeStyleSetPadding(root_child0, YGEdgeLeft, 3); + YGNodeStyleSetPadding(root_child0, YGEdgeTop, 7); + YGNodeStyleSetPadding(root_child0, YGEdgeRight, 5); + YGNodeStyleSetPadding(root_child0, YGEdgeBottom, 4); + YGNodeStyleSetBorder(root_child0, YGEdgeLeft, 4); + YGNodeStyleSetBorder(root_child0, YGEdgeTop, 3); + YGNodeStyleSetBorder(root_child0, YGEdgeRight, 2); + YGNodeStyleSetBorder(root_child0, YGEdgeBottom, 1); + YGNodeStyleSetWidthPercent(root_child0, 50); + YGNodeStyleSetHeightPercent(root_child0, 50); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(18, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(12, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(24, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(12, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +}