Summary: Fixes https://github.com/facebook/yoga/issues/850 https://github.com/facebook/yoga/issues/850 describes a conformance issue where positioning of an absolute child using percentages is not calculated against the correct box size. This takes the fix for that in https://github.com/facebook/yoga/pull/1028, regenerates tests, and fixes tests so that the experimental feature can be enabled. Goal is to run this as an experiment internally to see if we can enable by default. Changelog: [Internal] Pull Request resolved: https://github.com/facebook/yoga/pull/1201 Reviewed By: yungsters Differential Revision: D42282358 Pulled By: NickGerleman fbshipit-source-id: 57c0dd9b0f1c47cb9335ff6e13d44b4646e5fa58
261 lines
10 KiB
C++
261 lines
10 KiB
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
// clang-format off
|
|
// @generated by gentest/gentest.rb from gentest/fixtures/YGAlignSelfTest.html
|
|
|
|
#include <gtest/gtest.h>
|
|
#include <yoga/Yoga.h>
|
|
|
|
TEST(YogaTest, align_self_center) {
|
|
const YGConfigRef config = YGConfigNew();
|
|
YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge, true);
|
|
YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureFixAbsoluteTrailingColumnMargin, true);
|
|
|
|
const YGNodeRef root = YGNodeNewWithConfig(config);
|
|
YGNodeStyleSetWidth(root, 100);
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
|
YGNodeStyleSetAlignSelf(root_child0, YGAlignCenter);
|
|
YGNodeStyleSetWidth(root_child0, 10);
|
|
YGNodeStyleSetHeight(root_child0, 10);
|
|
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(100, YGNodeLayoutGetHeight(root));
|
|
|
|
ASSERT_FLOAT_EQ(45, YGNodeLayoutGetLeft(root_child0));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
|
|
ASSERT_FLOAT_EQ(10, 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(100, YGNodeLayoutGetHeight(root));
|
|
|
|
ASSERT_FLOAT_EQ(45, YGNodeLayoutGetLeft(root_child0));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
YGConfigFree(config);
|
|
}
|
|
|
|
TEST(YogaTest, align_self_flex_end) {
|
|
const YGConfigRef config = YGConfigNew();
|
|
YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge, true);
|
|
YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureFixAbsoluteTrailingColumnMargin, true);
|
|
|
|
const YGNodeRef root = YGNodeNewWithConfig(config);
|
|
YGNodeStyleSetWidth(root, 100);
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
|
YGNodeStyleSetAlignSelf(root_child0, YGAlignFlexEnd);
|
|
YGNodeStyleSetWidth(root_child0, 10);
|
|
YGNodeStyleSetHeight(root_child0, 10);
|
|
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(100, YGNodeLayoutGetHeight(root));
|
|
|
|
ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child0));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
|
|
ASSERT_FLOAT_EQ(10, 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(100, YGNodeLayoutGetHeight(root));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
YGConfigFree(config);
|
|
}
|
|
|
|
TEST(YogaTest, align_self_flex_start) {
|
|
const YGConfigRef config = YGConfigNew();
|
|
YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge, true);
|
|
YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureFixAbsoluteTrailingColumnMargin, true);
|
|
|
|
const YGNodeRef root = YGNodeNewWithConfig(config);
|
|
YGNodeStyleSetWidth(root, 100);
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
|
YGNodeStyleSetAlignSelf(root_child0, YGAlignFlexStart);
|
|
YGNodeStyleSetWidth(root_child0, 10);
|
|
YGNodeStyleSetHeight(root_child0, 10);
|
|
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(100, YGNodeLayoutGetHeight(root));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
|
|
ASSERT_FLOAT_EQ(10, 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(100, YGNodeLayoutGetHeight(root));
|
|
|
|
ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child0));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
YGConfigFree(config);
|
|
}
|
|
|
|
TEST(YogaTest, align_self_flex_end_override_flex_start) {
|
|
const YGConfigRef config = YGConfigNew();
|
|
YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge, true);
|
|
YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureFixAbsoluteTrailingColumnMargin, true);
|
|
|
|
const YGNodeRef root = YGNodeNewWithConfig(config);
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
YGNodeStyleSetWidth(root, 100);
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
|
YGNodeStyleSetAlignSelf(root_child0, YGAlignFlexEnd);
|
|
YGNodeStyleSetWidth(root_child0, 10);
|
|
YGNodeStyleSetHeight(root_child0, 10);
|
|
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(100, YGNodeLayoutGetHeight(root));
|
|
|
|
ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child0));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
|
|
ASSERT_FLOAT_EQ(10, 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(100, YGNodeLayoutGetHeight(root));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
YGConfigFree(config);
|
|
}
|
|
|
|
TEST(YogaTest, align_self_baseline) {
|
|
const YGConfigRef config = YGConfigNew();
|
|
YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge, true);
|
|
YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureFixAbsoluteTrailingColumnMargin, true);
|
|
|
|
const YGNodeRef root = YGNodeNewWithConfig(config);
|
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
|
YGNodeStyleSetWidth(root, 100);
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
|
YGNodeStyleSetAlignSelf(root_child0, YGAlignBaseline);
|
|
YGNodeStyleSetWidth(root_child0, 50);
|
|
YGNodeStyleSetHeight(root_child0, 50);
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
|
|
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
|
|
YGNodeStyleSetAlignSelf(root_child1, YGAlignBaseline);
|
|
YGNodeStyleSetWidth(root_child1, 50);
|
|
YGNodeStyleSetHeight(root_child1, 20);
|
|
YGNodeInsertChild(root, root_child1, 1);
|
|
|
|
const YGNodeRef root_child1_child0 = YGNodeNewWithConfig(config);
|
|
YGNodeStyleSetWidth(root_child1_child0, 50);
|
|
YGNodeStyleSetHeight(root_child1_child0, 10);
|
|
YGNodeInsertChild(root_child1, root_child1_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(100, YGNodeLayoutGetHeight(root));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1));
|
|
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1));
|
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0));
|
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_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(100, YGNodeLayoutGetHeight(root));
|
|
|
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
|
|
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1));
|
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0));
|
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child0));
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
YGConfigFree(config);
|
|
}
|