diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-24 22:12:31 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-24 22:12:31 +0100 |
commit | 24e3f0ea7c5ce90af1276dca49644b5e1ac799f6 (patch) | |
tree | 465dd020c1700511a1697267268b3d975caefd48 /src/test/OptionalRefTest.cpp | |
parent | 6287d4e9068d8bd27a9e62643f54adb69e84befd (diff) | |
parent | be5ccbe24086d5d4fb407f268c649dcbc36eda6b (diff) |
merge
Diffstat (limited to 'src/test/OptionalRefTest.cpp')
-rw-r--r-- | src/test/OptionalRefTest.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/test/OptionalRefTest.cpp b/src/test/OptionalRefTest.cpp new file mode 100644 index 0000000..83f7b23 --- /dev/null +++ b/src/test/OptionalRefTest.cpp @@ -0,0 +1,42 @@ +#include <gtest/gtest.h> + +#include <crepe/util/OptionalRef.h> + +using namespace std; +using namespace crepe; +using namespace testing; + +TEST(OptionalRefTest, Normal) { + string value = "foo"; + OptionalRef<string> ref = value; + + EXPECT_TRUE(ref); + ASSERT_NO_THROW({ + string & value_ref = ref; + EXPECT_EQ(value_ref, value); + }); + + ref.clear(); + EXPECT_FALSE(ref); + ASSERT_THROW({ string & value_ref = ref; }, runtime_error); +} + +TEST(OptionalRefTest, Empty) { + string value = "foo"; + OptionalRef<string> ref; + + EXPECT_FALSE(ref); + ASSERT_THROW({ string & value_ref = ref; }, runtime_error); +} + +TEST(OptionalRefTest, Chain) { + string value = "foo"; + OptionalRef<string> ref1 = value; + OptionalRef<string> ref2 = ref1; + + EXPECT_TRUE(ref2); + string & value_ref = ref2; + EXPECT_EQ(value_ref, value); + value_ref = "bar"; + EXPECT_EQ(value_ref, value); +} |