Fixed a typo and added a test case

Summary: Fixed a typo of flexshrink and added a test case

Reviewed By: emilsjolander

Differential Revision: D7289221

fbshipit-source-id: 48ee9ccfac4adee51d515a366b5a11790f7236fc
This commit is contained in:
Pritesh Nandgaonkar
2018-03-15 12:29:00 -07:00
committed by Facebook Github Bot
parent 0dde40ce0b
commit ae86824636
2 changed files with 24 additions and 1 deletions

View File

@@ -57,3 +57,26 @@ TEST(YogaTest, copy_style_modified_same) {
YGNodeFree(node0); YGNodeFree(node0);
YGNodeFree(node1); YGNodeFree(node1);
} }
TEST(YogaTest, initialise_flexShrink_flexGrow) {
const YGNodeRef node0 = YGNodeNew();
YGNodeStyleSetFlexShrink(node0, 1);
ASSERT_EQ(1, YGNodeStyleGetFlexShrink(node0));
YGNodeStyleSetFlexShrink(node0, YGUndefined);
YGNodeStyleSetFlexGrow(node0, 3);
ASSERT_EQ(
0,
YGNodeStyleGetFlexShrink(
node0)); // Default value is Zero, if flex shrink is not defined
ASSERT_EQ(3, YGNodeStyleGetFlexGrow(node0));
YGNodeStyleSetFlexGrow(node0, YGUndefined);
YGNodeStyleSetFlexShrink(node0, 3);
ASSERT_EQ(
0,
YGNodeStyleGetFlexGrow(
node0)); // Default value is Zero, if flex grow is not defined
ASSERT_EQ(3, YGNodeStyleGetFlexShrink(node0));
YGNodeFree(node0);
}

View File

@@ -778,7 +778,7 @@ void YGNodeStyleSetFlexShrink(const YGNodeRef node, const float flexShrink) {
if (!YGFloatOptionalFloatEquals(node->getStyle().flexShrink, flexShrink)) { if (!YGFloatOptionalFloatEquals(node->getStyle().flexShrink, flexShrink)) {
YGStyle style = node->getStyle(); YGStyle style = node->getStyle();
if (YGFloatIsUndefined(flexShrink)) { if (YGFloatIsUndefined(flexShrink)) {
style.flexGrow = {true, 0}; style.flexShrink = {true, 0};
} else { } else {
style.flexShrink = {false, flexShrink}; style.flexShrink = {false, flexShrink};
} }