From a7ebfdedeee84bd01615ad62ac448adae12787db Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Fri, 22 Nov 2024 19:14:47 +0100 Subject: Add box + option tests --- asl/box.hpp | 1 + asl/tests/box_tests.cpp | 24 ++++++++++++++++++++++++ asl/tests/option_tests.cpp | 4 ++++ 3 files changed, 29 insertions(+) (limited to 'asl') diff --git a/asl/box.hpp b/asl/box.hpp index 7556d76..eeb2b9c 100644 --- a/asl/box.hpp +++ b/asl/box.hpp @@ -5,6 +5,7 @@ #include "asl/annotations.hpp" #include "asl/memory.hpp" #include "asl/utility.hpp" +#include "asl/box.hpp" namespace asl { 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) == sizeof(int*)); static_assert(!asl::copyable>); static_assert(asl::moveable>); static_assert(asl::has_niche>); +static_assert(sizeof(asl::option>) == sizeof(int*)); ASL_TEST(destructor) { @@ -50,3 +52,25 @@ ASL_TEST(arrow) auto b = asl::make_box(45); ASL_TEST_EXPECT(b->a == 45); } + +ASL_TEST(niche) +{ + asl::option> opt; + ASL_TEST_EXPECT(!opt.has_value()); + + opt = asl::make_box(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> opt2 = asl::make_box(&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); } -- cgit