summaryrefslogtreecommitdiff
path: root/asl/tests
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2024-11-22 19:14:47 +0100
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2024-12-20 15:35:58 +0100
commita7ebfdedeee84bd01615ad62ac448adae12787db (patch)
tree223f0b4a6ae7b4b2495f751f7b7d02a5452231cf /asl/tests
parent53b9ec80a3b7bb7e403a8c7330c0741484b9ba4d (diff)
Add box + option tests
Diffstat (limited to 'asl/tests')
-rw-r--r--asl/tests/box_tests.cpp24
-rw-r--r--asl/tests/option_tests.cpp4
2 files changed, 28 insertions, 0 deletions
diff --git a/asl/tests/box_tests.cpp b/asl/tests/box_tests.cpp
index 3813639..53b6dda 100644
--- a/asl/tests/box_tests.cpp
+++ b/asl/tests/box_tests.cpp
@@ -1,4 +1,5 @@
#include "asl/box.hpp"
+#include "asl/option.hpp"
#include "asl/testing/testing.hpp"
#include "asl/tests/test_types.hpp"
@@ -7,6 +8,7 @@ static_assert(sizeof(asl::box<int>) == sizeof(int*));
static_assert(!asl::copyable<asl::box<int>>);
static_assert(asl::moveable<asl::box<int>>);
static_assert(asl::has_niche<asl::box<int>>);
+static_assert(sizeof(asl::option<asl::box<int>>) == sizeof(int*));
ASL_TEST(destructor)
{
@@ -50,3 +52,25 @@ ASL_TEST(arrow)
auto b = asl::make_box<Struct>(45);
ASL_TEST_EXPECT(b->a == 45);
}
+
+ASL_TEST(niche)
+{
+ asl::option<asl::box<int>> opt;
+ ASL_TEST_EXPECT(!opt.has_value());
+
+ opt = asl::make_box<int>(66);
+ ASL_TEST_EXPECT(opt.has_value());
+ ASL_TEST_EXPECT(*opt.value() == 66);
+
+ opt = asl::nullopt;
+ ASL_TEST_EXPECT(!opt.has_value());
+
+ bool destroyed = false;
+ asl::option<asl::box<DestructorObserver>> opt2 = asl::make_box<DestructorObserver>(&destroyed);
+ ASL_TEST_EXPECT(opt2.has_value());
+ ASL_TEST_EXPECT(!destroyed);
+
+ opt2.reset();
+ ASL_TEST_EXPECT(!opt2.has_value());
+ ASL_TEST_EXPECT(destroyed);
+}
diff --git a/asl/tests/option_tests.cpp b/asl/tests/option_tests.cpp
index 15367f1..8261583 100644
--- a/asl/tests/option_tests.cpp
+++ b/asl/tests/option_tests.cpp
@@ -311,4 +311,8 @@ ASL_TEST(niche)
opt.reset();
ASL_TEST_EXPECT(!opt.has_value());
+
+ opt = NonZero(87);
+ ASL_TEST_EXPECT(opt.has_value());
+ ASL_TEST_EXPECT(opt.value().value == 87);
}