diff options
author | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-12-02 18:55:13 +0100 |
---|---|---|
committer | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-12-02 18:55:13 +0100 |
commit | 47e6d987ced269ec16ea455706513025cb9c50c5 (patch) | |
tree | 5cb48ad8565f7c5bd8b03624bc716375b8d2321b /src/test/OptionalRefTest.cpp | |
parent | f23eaa64df8b0ef27f58b1632c5e659fe3737153 (diff) | |
parent | 647eb8e318f1ed1e3ec18505ea4df57025e6ffd5 (diff) |
Merge branch 'master' into niels/rendering_color
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); +} |