Eliminate YGFloatOptional::getValue()

Summary:
@public

Replace `YGFloatOptional::getValue()` with `YGFloatOptional::unwrap()`.

`YGFloatOptional::getValue()` has the unfortunate property of calling `std::exit` if the wrapped value is undefined.

Here, we eliminate the method, and just call `.unwrap()` everywhere.

Reviewed By: shergin

Differential Revision: D13439608

fbshipit-source-id: 5ae82b170537d0a10c301412567a7a66fd50bab4
This commit is contained in:
David Aurelio
2018-12-13 07:09:30 -08:00
committed by Facebook Github Bot
parent aaa018bbea
commit 4b5ae211da
9 changed files with 55 additions and 67 deletions

View File

@@ -17,10 +17,11 @@ constexpr auto positive = YGFloatOptional{1234.5f};
constexpr auto negative = YGFloatOptional{-9876.5f};
TEST(YGFloatOptional, value) {
ASSERT_EQ(zero.getValue(), 0.0f);
ASSERT_EQ(one.getValue(), 1.0f);
ASSERT_EQ(positive.getValue(), 1234.5f);
ASSERT_EQ(negative.getValue(), -9876.5f);
ASSERT_TRUE(YGFloatIsUndefined(empty.unwrap()));
ASSERT_EQ(zero.unwrap(), 0.0f);
ASSERT_EQ(one.unwrap(), 1.0f);
ASSERT_EQ(positive.unwrap(), 1234.5f);
ASSERT_EQ(negative.unwrap(), -9876.5f);
ASSERT_TRUE(empty.isUndefined());
ASSERT_FALSE(zero.isUndefined());
@@ -46,11 +47,11 @@ TEST(YGFloatOptional, equality) {
ASSERT_FALSE(one == positive);
ASSERT_TRUE(positive == positive);
ASSERT_TRUE(positive == positive.getValue());
ASSERT_TRUE(positive == positive.unwrap());
ASSERT_FALSE(positive == one);
ASSERT_TRUE(negative == negative);
ASSERT_TRUE(negative == negative.getValue());
ASSERT_TRUE(negative == negative.unwrap());
ASSERT_FALSE(negative == zero);
}
@@ -71,11 +72,11 @@ TEST(YGFloatOptional, inequality) {
ASSERT_TRUE(one != positive);
ASSERT_FALSE(positive != positive);
ASSERT_FALSE(positive != positive.getValue());
ASSERT_FALSE(positive != positive.unwrap());
ASSERT_TRUE(positive != one);
ASSERT_FALSE(negative != negative);
ASSERT_FALSE(negative != negative.getValue());
ASSERT_FALSE(negative != negative.unwrap());
ASSERT_TRUE(negative != zero);
}
@@ -180,8 +181,8 @@ TEST(YGFloatOptional, less_than_equals) {
}
TEST(YGFloatOptional, addition) {
auto n = negative.getValue();
auto p = positive.getValue();
auto n = negative.unwrap();
auto p = positive.unwrap();
ASSERT_EQ(zero + one, one);
ASSERT_EQ(negative + positive, YGFloatOptional{n + p});