#include "asl/option.hpp" #include "asl/tests/test_types.hpp" #include "asl/testing/testing.hpp" static_assert(asl::trivially_destructible>); static_assert(!asl::trivially_destructible>); static_assert(asl::copy_constructible>); static_assert(asl::copy_constructible>); static_assert(!asl::copy_constructible>); static_assert(!asl::copy_constructible>); static_assert(asl::move_constructible>); static_assert(asl::move_constructible>); static_assert(asl::move_constructible>); static_assert(!asl::move_constructible>); static_assert(asl::copy_assignable>); static_assert(asl::copy_assignable>); static_assert(!asl::copy_assignable>); static_assert(!asl::copy_assignable>); static_assert(asl::move_assignable>); static_assert(asl::move_assignable>); static_assert(!asl::move_assignable>); ASL_TEST(make_null) { asl::option a; asl::option b = asl::nullopt; ASL_TEST_EXPECT(!a.has_value()); ASL_TEST_EXPECT(!b.has_value()); } ASL_TEST(make_value) { asl::option a = 48; ASL_TEST_EXPECT(a.has_value()); } ASL_TEST(reset) { asl::option 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 opt(ASL_MOVE(obs)); ASL_TEST_EXPECT(!destroyed); asl::option opt2 = ASL_MOVE(opt); ASL_TEST_EXPECT(!destroyed); } ASL_TEST_EXPECT(destroyed); } ASL_TEST(call_destructor_on_reset) { bool destroyed = false; asl::option opt(&destroyed); ASL_TEST_EXPECT(!destroyed); opt.reset(); ASL_TEST_EXPECT(destroyed); } ASL_TEST(value) { asl::option a = 1; asl::option b = 2; asl::option c = a; ASL_TEST_EXPECT(a.value() == 1); ASL_TEST_EXPECT(b.value() == 2); ASL_TEST_EXPECT(c.value() == 1); c = b; ASL_TEST_EXPECT(c.value() == 2); } ASL_TEST(value_move) { bool destroyed = false; asl::option 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); }