diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-10-28 23:52:48 +0100 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-12-20 15:35:58 +0100 |
commit | 2a10eaae094e48a157d55ec886aaa07b0d0be6c9 (patch) | |
tree | e334ce5d2de1604eb168a3269be887bbc078df70 /asl/tests/option_tests.cpp | |
parent | 46cc6bfc5f62bb45427ef7778ba5fc04d7a546da (diff) |
Some work on test framework & option
Diffstat (limited to 'asl/tests/option_tests.cpp')
-rw-r--r-- | asl/tests/option_tests.cpp | 87 |
1 files changed, 71 insertions, 16 deletions
diff --git a/asl/tests/option_tests.cpp b/asl/tests/option_tests.cpp index e423cc9..e7fff8b 100644 --- a/asl/tests/option_tests.cpp +++ b/asl/tests/option_tests.cpp @@ -24,35 +24,90 @@ static_assert(asl::move_assignable<asl::option<int>>); static_assert(asl::move_assignable<asl::option<CopyAssignable>>);
static_assert(!asl::move_assignable<asl::option<NonMoveAssignable>>);
-ASL_TEST(Option_cheese)
+ASL_TEST(make_null)
{
asl::option<int> a;
- asl::option<int> b;
+ asl::option<int> b = asl::nullopt;
- a = ASL_MOVE(b);
+ ASL_TEST_EXPECT(!a.has_value());
+ ASL_TEST_EXPECT(!b.has_value());
}
-ASL_TEST(Option_cheese2)
+ASL_TEST(make_value)
{
- asl::option<int> a;
- asl::option<int> b;
+ asl::option<int> a = 48;
- a = ASL_MOVE(b);
+ ASL_TEST_EXPECT(a.has_value());
}
-ASL_TEST(Option_cheese3)
+ASL_TEST(reset)
{
- asl::option<int> a;
- asl::option<int> b;
+ asl::option<int> b = 48;
+ ASL_TEST_EXPECT(b.has_value());
+
+ b.reset();
+ ASL_TEST_EXPECT(!b.has_value());
+}
+
+ASL_TEST(call_destructor)
+{
+ bool destroyed = false;
+
+ {
+ DestructorObserver obs(&destroyed);
+
+ asl::option<DestructorObserver> opt(ASL_MOVE(obs));
+ ASL_TEST_EXPECT(!destroyed);
+
+ asl::option<DestructorObserver> opt2 = ASL_MOVE(opt);
+ ASL_TEST_EXPECT(!destroyed);
+ }
- a = ASL_MOVE(b);
- asl::testing::report_failure("OH NO", __FILE__, __LINE__);
+ ASL_TEST_EXPECT(destroyed);
}
-ASL_TEST(Option_cheese4)
+ASL_TEST(call_destructor_on_reset)
{
- asl::option<int> a;
- asl::option<int> b;
+ bool destroyed = false;
+
+ asl::option<DestructorObserver> opt(&destroyed);
+ ASL_TEST_EXPECT(!destroyed);
+
+ opt.reset();
+ ASL_TEST_EXPECT(destroyed);
+}
+
+ASL_TEST(value)
+{
+ asl::option<int> a = 1;
+ asl::option<int> b = 2;
+ asl::option<int> c = a;
+
+ ASL_TEST_EXPECT(a.value() == 1);
+ ASL_TEST_EXPECT(b.value() == 2);
+ ASL_TEST_EXPECT(c.value() == 1);
- a = ASL_MOVE(b);
+ c = b;
+ ASL_TEST_EXPECT(c.value() == 2);
+}
+
+ASL_TEST(value_move)
+{
+ bool destroyed = false;
+
+ asl::option<DestructorObserver> opt(&destroyed);
+ ASL_TEST_EXPECT(!destroyed);
+
+ {
+ auto x = ASL_MOVE(opt).value();
+ ASL_TEST_EXPECT(!destroyed);
+ }
+
+ ASL_TEST_EXPECT(destroyed);
+}
+
+ASL_TEST(deduction_guide)
+{
+ asl::option opt(45);
+ ASL_TEST_EXPECT(opt.value() == 45);
}
|