diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-22 15:10:49 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-22 15:10:49 +0100 |
commit | d038f192c7dcb453c9fc19082cd1b642c8f70fc8 (patch) | |
tree | bcb539657cd8b35ed742f19e5673c777ab39610c /src/test/OptionalRefTest.cpp | |
parent | c3c3476f1d82aa83d8f8dc706488475dc2cf1e55 (diff) | |
parent | 4117d1d287f1d87efd0577d56819520e981a7f1c (diff) |
merge with `master`loek/audio
Diffstat (limited to 'src/test/OptionalRefTest.cpp')
-rw-r--r-- | src/test/OptionalRefTest.cpp | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/src/test/OptionalRefTest.cpp b/src/test/OptionalRefTest.cpp index 219ccca..83f7b23 100644 --- a/src/test/OptionalRefTest.cpp +++ b/src/test/OptionalRefTest.cpp @@ -6,33 +6,37 @@ using namespace std; using namespace crepe; using namespace testing; -TEST(OptionalRefTest, Explicit) { +TEST(OptionalRefTest, Normal) { string value = "foo"; - OptionalRef<string> ref; - EXPECT_FALSE(ref); - ASSERT_THROW(ref.get(), runtime_error); + OptionalRef<string> ref = value; - ref.set(value); EXPECT_TRUE(ref); - ASSERT_NO_THROW(ref.get()); + ASSERT_NO_THROW({ + string & value_ref = ref; + EXPECT_EQ(value_ref, value); + }); ref.clear(); EXPECT_FALSE(ref); - ASSERT_THROW(ref.get(), runtime_error); + ASSERT_THROW({ string & value_ref = ref; }, runtime_error); } -TEST(OptionalRefTest, Implicit) { +TEST(OptionalRefTest, Empty) { string value = "foo"; - OptionalRef<string> ref = value; - EXPECT_TRUE(ref); - ASSERT_NO_THROW(ref.get()); + OptionalRef<string> ref; - ref.clear(); EXPECT_FALSE(ref); - ASSERT_THROW(ref.get(), runtime_error); - - ref = value; - EXPECT_TRUE(ref); - ASSERT_NO_THROW(ref.get()); + 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); +} |