diff --git a/tests/CompactValueTest.cpp b/tests/CompactValueTest.cpp index 7d2afc13..d0a2c669 100644 --- a/tests/CompactValueTest.cpp +++ b/tests/CompactValueTest.cpp @@ -29,6 +29,18 @@ TEST(YogaTest, compact_value_can_represent_undefined) { ASSERT_FALSE(c.isAuto()); } +TEST(YogaTest, compact_value_manages_infinity_as_undefined) { + auto c = CompactValue{ + YGValue{std::numeric_limits::infinity(), YGUnitUndefined}}; + YGValue v = c; + ASSERT_EQ(v, YGValueUndefined); + ASSERT_NE(v, YGValueAuto); + ASSERT_NE(v, (YGValue{-1.25, YGUnitPoint})); + ASSERT_NE(v, (YGValue{25, YGUnitPercent})); + ASSERT_TRUE(c.isUndefined()); + ASSERT_FALSE(c.isAuto()); +} + TEST(YogaTest, compact_value_can_represent_auto) { auto c = CompactValue{YGValue{0, YGUnitAuto}}; YGValue v = c; diff --git a/yoga/CompactValue.h b/yoga/CompactValue.h index 9c9a92e0..3cc36a48 100644 --- a/yoga/CompactValue.h +++ b/yoga/CompactValue.h @@ -70,7 +70,8 @@ public: template static CompactValue ofMaybe(float value) noexcept { - return std::isnan(value) ? ofUndefined() : of(value); + return std::isnan(value) || std::isinf(value) ? ofUndefined() + : of(value); } static constexpr CompactValue ofZero() noexcept {