summaryrefslogtreecommitdiff
path: root/asl/tests
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2024-11-02 18:32:17 +0100
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2024-12-20 15:35:58 +0100
commitbe34f768e093cb6752ab81fde3ab529861a8a6a8 (patch)
tree284a6ca5a79fb2a647586e2bfdb11b3923e01f91 /asl/tests
parentafd8e711ab35e8d21bc9c8397f31dcf7ecdec2e3 (diff)
Add emplace to option
Diffstat (limited to 'asl/tests')
-rw-r--r--asl/tests/option_tests.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/asl/tests/option_tests.cpp b/asl/tests/option_tests.cpp
index ec6e957..73998f8 100644
--- a/asl/tests/option_tests.cpp
+++ b/asl/tests/option_tests.cpp
@@ -198,3 +198,29 @@ ASL_TEST(value_or)
ASL_TEST_EXPECT(a.value_or(5) == 5);
ASL_TEST_EXPECT(b.value_or(5) == 2);
}
+
+ASL_TEST(emplace)
+{
+ asl::option<int> a = asl::nullopt;
+
+ a.emplace(42);
+ ASL_TEST_EXPECT(a.has_value());
+ ASL_TEST_EXPECT(a.value() == 42);
+}
+
+ASL_TEST(emplace_destroys_previous)
+{
+ bool b1 = false;
+ bool b2 = false;
+
+ {
+ asl::option<DestructorObserver> a{&b1};
+ ASL_TEST_EXPECT(!b1);
+
+ a.emplace(&b2);
+ ASL_TEST_EXPECT(b1);
+ ASL_TEST_EXPECT(!b2);
+ }
+
+ ASL_TEST_EXPECT(b2);
+}