From a141c401f78467bc15f62882fca5d55a007cacbb Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Mon, 17 Feb 2025 00:21:48 +0100 Subject: Reorganize everything --- asl/tests/BUILD.bazel | 10 + asl/tests/box_tests.cpp | 102 ------- asl/tests/buffer_tests.cpp | 603 ------------------------------------- asl/tests/float_tests.cpp | 23 -- asl/tests/format_tests.cpp | 110 ------- asl/tests/functional_tests.cpp | 73 ----- asl/tests/hash_map_tests.cpp | 48 --- asl/tests/hash_set_tests.cpp | 185 ------------ asl/tests/hash_tests.cpp | 260 ---------------- asl/tests/integers_tests.cpp | 15 - asl/tests/maybe_uninit_tests.cpp | 22 -- asl/tests/meta_tests.cpp | 289 ------------------ asl/tests/option_tests.cpp | 330 -------------------- asl/tests/span_tests.cpp | 444 --------------------------- asl/tests/status_or_tests.cpp | 84 ------ asl/tests/status_tests.cpp | 82 ----- asl/tests/string_builder_tests.cpp | 23 -- asl/tests/string_tests.cpp | 21 -- asl/tests/string_view_tests.cpp | 117 ------- asl/tests/test_types.hpp | 92 ------ asl/tests/types.hpp | 89 ++++++ asl/tests/utility_tests.cpp | 1 - 22 files changed, 99 insertions(+), 2924 deletions(-) create mode 100644 asl/tests/BUILD.bazel delete mode 100644 asl/tests/box_tests.cpp delete mode 100644 asl/tests/buffer_tests.cpp delete mode 100644 asl/tests/float_tests.cpp delete mode 100644 asl/tests/format_tests.cpp delete mode 100644 asl/tests/functional_tests.cpp delete mode 100644 asl/tests/hash_map_tests.cpp delete mode 100644 asl/tests/hash_set_tests.cpp delete mode 100644 asl/tests/hash_tests.cpp delete mode 100644 asl/tests/integers_tests.cpp delete mode 100644 asl/tests/maybe_uninit_tests.cpp delete mode 100644 asl/tests/meta_tests.cpp delete mode 100644 asl/tests/option_tests.cpp delete mode 100644 asl/tests/span_tests.cpp delete mode 100644 asl/tests/status_or_tests.cpp delete mode 100644 asl/tests/status_tests.cpp delete mode 100644 asl/tests/string_builder_tests.cpp delete mode 100644 asl/tests/string_tests.cpp delete mode 100644 asl/tests/string_view_tests.cpp delete mode 100644 asl/tests/test_types.hpp create mode 100644 asl/tests/types.hpp delete mode 100644 asl/tests/utility_tests.cpp (limited to 'asl/tests') diff --git a/asl/tests/BUILD.bazel b/asl/tests/BUILD.bazel new file mode 100644 index 0000000..eb51ec8 --- /dev/null +++ b/asl/tests/BUILD.bazel @@ -0,0 +1,10 @@ +cc_library( + name = "utils", + hdrs = [ + "types.hpp", + ], + deps = [ + "//asl/base", + ], + visibility = ["//asl:__subpackages__"], +) diff --git a/asl/tests/box_tests.cpp b/asl/tests/box_tests.cpp deleted file mode 100644 index 3faf121..0000000 --- a/asl/tests/box_tests.cpp +++ /dev/null @@ -1,102 +0,0 @@ -#include "asl/box.hpp" -#include "asl/option.hpp" - -#include "asl/testing/testing.hpp" -#include "asl/tests/test_types.hpp" - -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) -{ - bool d = false; - - { - auto box = asl::make_box(&d); - ASL_TEST_ASSERT(!d); - - - auto box3 = ASL_MOVE(box); - ASL_TEST_ASSERT(!d); - } - - ASL_TEST_ASSERT(d); -} - -ASL_TEST(value) -{ - auto b = asl::make_box(24); - ASL_TEST_EXPECT(*b == 24); - - auto b2 = ASL_MOVE(b); - ASL_TEST_EXPECT(*b2 == 24); -} - -ASL_TEST(ptr) -{ - auto b = asl::make_box(24); - auto* ptr1 = b.get(); - - auto b2 = ASL_MOVE(b); - auto* ptr2 = b2.get(); - ASL_TEST_EXPECT(ptr1 == ptr2); -} - -struct Struct { int a; }; - -ASL_TEST(arrow) -{ - auto b = asl::make_box(45); - ASL_TEST_EXPECT(b->a == 45); -} - -ASL_TEST(niche) -{ - static_assert(sizeof(asl::box) == sizeof(asl::option>)); - - 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); -} - -class Base -{ -public: - virtual ~Base() = default; - virtual int number() { return 1; } -}; - -class Derived : public Base -{ -public: - int number() override { return 2; } -}; - -static_assert(asl::convertible_from, asl::box>); -static_assert(asl::convertible_from, asl::box>); -static_assert(!asl::convertible_from, asl::box>); -static_assert(!asl::convertible_from, asl::box>); - -ASL_TEST(derived) -{ - asl::box obj = asl::make_box(); - ASL_TEST_ASSERT(obj->number() == 2); -} diff --git a/asl/tests/buffer_tests.cpp b/asl/tests/buffer_tests.cpp deleted file mode 100644 index 174b3bc..0000000 --- a/asl/tests/buffer_tests.cpp +++ /dev/null @@ -1,603 +0,0 @@ -#include "asl/buffer.hpp" - -#include "asl/testing/testing.hpp" -#include "asl/tests/test_types.hpp" - -struct Big -{ - uint64_t data[8]; -}; - -static_assert(asl::buffer::kInlineCapacity == 5); -static_assert(asl::buffer::kInlineCapacity == 2); -static_assert(asl::buffer::kInlineCapacity == 23); -static_assert(asl::buffer::kInlineCapacity == 0); - -ASL_TEST(default_size) -{ - asl::buffer b1; - ASL_TEST_EXPECT(b1.size() == 0); - ASL_TEST_EXPECT(b1.capacity() == 5); - ASL_TEST_EXPECT(static_cast(b1.data()) == &b1); - - asl::buffer b2; - ASL_TEST_EXPECT(b2.size() == 0); - ASL_TEST_EXPECT(b2.capacity() == 0); - ASL_TEST_EXPECT(b2.data() == nullptr); -} - -struct CounterAllocator -{ - isize_t* count; - - void* alloc(const asl::layout& layout) const - { - *count += 1; - return asl::GlobalHeap::alloc(layout); - } - - void* realloc(void* ptr, const asl::layout& old, const asl::layout& new_layout) const - { - *count += 1; - return asl::GlobalHeap::realloc(ptr, old, new_layout); - } - - static void dealloc(void* ptr, const asl::layout& layout) - { - asl::GlobalHeap::dealloc(ptr, layout); - } - - constexpr bool operator==(const CounterAllocator&) const { return true; } -}; -static_assert(asl::allocator); - -struct IncompatibleAllocator -{ - static void* alloc(const asl::layout& layout) - { - return asl::GlobalHeap::alloc(layout); - } - - static void* realloc(void* ptr, const asl::layout& old, const asl::layout& new_layout) - { - return asl::GlobalHeap::realloc(ptr, old, new_layout); - } - - static void dealloc(void* ptr, const asl::layout& layout) - { - asl::GlobalHeap::dealloc(ptr, layout); - } - - constexpr bool operator==(const IncompatibleAllocator&) const { return false; } -}; -static_assert(asl::allocator); - -ASL_TEST(reserve_capacity) -{ - isize_t count = 0; - asl::buffer b(CounterAllocator{&count}); - ASL_TEST_EXPECT(b.size() == 0); - ASL_TEST_EXPECT(b.capacity() == 5); - ASL_TEST_EXPECT(count == 0); - - b.reserve_capacity(4); - ASL_TEST_EXPECT(b.size() == 0); - ASL_TEST_EXPECT(b.capacity() == 5); - ASL_TEST_EXPECT(count == 0); - - b.reserve_capacity(12); - ASL_TEST_EXPECT(b.size() == 0); - ASL_TEST_EXPECT(b.capacity() >= 12); - ASL_TEST_EXPECT(count == 1); - - b.reserve_capacity(13); - ASL_TEST_EXPECT(b.size() == 0); - ASL_TEST_EXPECT(b.capacity() >= 13); - ASL_TEST_EXPECT(count == 1); - - b.reserve_capacity(130); - ASL_TEST_EXPECT(b.size() == 0); - ASL_TEST_EXPECT(b.capacity() >= 130); - ASL_TEST_EXPECT(count == 2); -} - -ASL_TEST(push) -{ - asl::buffer b; - ASL_TEST_EXPECT(b.size() == 0); - - b.push(1); - ASL_TEST_EXPECT(b.size() == 1); - ASL_TEST_EXPECT(b[0] == 1); - - b.push(2); - b.push(3); - ASL_TEST_EXPECT(b.size() == 3); - ASL_TEST_EXPECT(b[0] == 1); - ASL_TEST_EXPECT(b[1] == 2); - ASL_TEST_EXPECT(b[2] == 3); - - b.push(4); - b.push(5); - b.push(6); - b.push(7); - ASL_TEST_EXPECT(b.size() == 7); - ASL_TEST_EXPECT(b[0] == 1); - ASL_TEST_EXPECT(b[1] == 2); - ASL_TEST_EXPECT(b[2] == 3); - ASL_TEST_EXPECT(b[3] == 4); - ASL_TEST_EXPECT(b[4] == 5); - ASL_TEST_EXPECT(b[5] == 6); - ASL_TEST_EXPECT(b[6] == 7); -} - -ASL_TEST(from_span) -{ - int data[] = {1, 2, 4, 8}; - asl::buffer b{data}; - - ASL_TEST_EXPECT(b.size() == 4); - ASL_TEST_EXPECT(b[0] == 1); - ASL_TEST_EXPECT(b[1] == 2); - ASL_TEST_EXPECT(b[2] == 4); - ASL_TEST_EXPECT(b[3] == 8); -} - -struct MoveableType -{ - int moved{}; - int value; - - explicit MoveableType(int x) : value{x} {} - MoveableType(const MoveableType&) = delete; - MoveableType(MoveableType&& other) : moved{other.moved + 1}, value{other.value} {} - MoveableType& operator=(const MoveableType&) = delete; - MoveableType& operator=(MoveableType&&) = delete; -}; -static_assert(!asl::trivially_copy_constructible); -static_assert(!asl::trivially_move_constructible); -static_assert(!asl::copyable); -static_assert(asl::move_constructible); - -ASL_TEST(push_move) -{ - asl::buffer b; - - static_assert(asl::buffer::kInlineCapacity > 0); - - b.push(0); - ASL_TEST_EXPECT(b[0].value == 0); - ASL_TEST_EXPECT(b[0].moved == 0); - - b.push(1); - ASL_TEST_EXPECT(b[0].value == 0); - ASL_TEST_EXPECT(b[0].moved == 0); - ASL_TEST_EXPECT(b[1].value == 1); - ASL_TEST_EXPECT(b[1].moved == 0); - - b.push(2); - ASL_TEST_EXPECT(b[0].value == 0); - ASL_TEST_EXPECT(b[0].moved == 1); - ASL_TEST_EXPECT(b[1].value == 1); - ASL_TEST_EXPECT(b[1].moved == 1); - ASL_TEST_EXPECT(b[2].value == 2); - ASL_TEST_EXPECT(b[2].moved == 0); - - b.push(3); - ASL_TEST_EXPECT(b[0].value == 0); - ASL_TEST_EXPECT(b[0].moved == 1); - ASL_TEST_EXPECT(b[1].value == 1); - ASL_TEST_EXPECT(b[1].moved == 1); - ASL_TEST_EXPECT(b[2].value == 2); - ASL_TEST_EXPECT(b[2].moved == 0); - ASL_TEST_EXPECT(b[3].value == 3); - ASL_TEST_EXPECT(b[3].moved == 0); - - b.push(4); - ASL_TEST_EXPECT(b[0].value == 0); - ASL_TEST_EXPECT(b[0].moved == 2); - ASL_TEST_EXPECT(b[1].value == 1); - ASL_TEST_EXPECT(b[1].moved == 2); - ASL_TEST_EXPECT(b[2].value == 2); - ASL_TEST_EXPECT(b[2].moved == 1); - ASL_TEST_EXPECT(b[3].value == 3); - ASL_TEST_EXPECT(b[3].moved == 1); - ASL_TEST_EXPECT(b[4].value == 4); - ASL_TEST_EXPECT(b[4].moved == 0); -} - -ASL_TEST(clear) -{ - asl::buffer b; - ASL_TEST_EXPECT(b.size() == 0); - - b.push(1); - b.push(2); - b.push(3); - b.push(4); - b.push(5); - b.push(6); - b.push(7); - ASL_TEST_EXPECT(b.size() == 7); - - b.clear(); - ASL_TEST_EXPECT(b.size() == 0); -} - -static_assert(asl::buffer::kInlineCapacity == 2); - -ASL_TEST(clear_destructor_small) -{ - bool d0 = false; - bool d1 = false; - - asl::buffer buf; - - buf.push(&d0); - buf.push(&d1); - - buf.clear(); - ASL_TEST_EXPECT(d0 == true); - ASL_TEST_EXPECT(d1 == true); -} - -ASL_TEST(clear_destructor_heap) -{ - bool d0 = false; - bool d1 = false; - bool d2 = false; - - asl::buffer buf; - - buf.push(&d0); - buf.push(&d1); - buf.push(&d2); - ASL_TEST_EXPECT(d0 == false); - ASL_TEST_EXPECT(d1 == false); - ASL_TEST_EXPECT(d2 == false); - - buf.clear(); - ASL_TEST_EXPECT(d0 == true); - ASL_TEST_EXPECT(d1 == true); - ASL_TEST_EXPECT(d2 == true); -} - -ASL_TEST(move_construct_from_heap) -{ - bool d[3]{}; - asl::buffer buf; - buf.push(&d[0]); - buf.push(&d[1]); - buf.push(&d[2]); - - { - asl::buffer buf2(ASL_MOVE(buf)); - ASL_TEST_EXPECT(buf2.size() == 3); - ASL_TEST_EXPECT(d[0] == false); - ASL_TEST_EXPECT(d[1] == false); - ASL_TEST_EXPECT(d[2] == false); - } - - ASL_TEST_EXPECT(buf.size() == 0); - ASL_TEST_EXPECT(d[0] == true); - ASL_TEST_EXPECT(d[1] == true); - ASL_TEST_EXPECT(d[2] == true); -} - -ASL_TEST(move_construct_inline_trivial) -{ - asl::buffer buf; - buf.push(1U); - buf.push(2U); - - asl::buffer buf2(ASL_MOVE(buf)); - ASL_TEST_EXPECT(buf2[0] == 1U); - ASL_TEST_EXPECT(buf2[1] == 2U); - - ASL_TEST_EXPECT(buf2.size() == 2); - ASL_TEST_EXPECT(buf.size() == 0); -} - -ASL_TEST(move_construct_from_inline_non_trivial) -{ - bool d[2]{}; - asl::buffer buf; - buf.push(&d[0]); - buf.push(&d[1]); - - { - asl::buffer buf2(ASL_MOVE(buf)); - ASL_TEST_EXPECT(buf2.size() == 2); - ASL_TEST_EXPECT(d[0] == false); - ASL_TEST_EXPECT(d[1] == false); - } - - ASL_TEST_EXPECT(buf.size() == 0); - ASL_TEST_EXPECT(d[0] == true); - ASL_TEST_EXPECT(d[1] == true); -} - -ASL_TEST(move_assign_from_heap) -{ - bool d[6]{}; - - { - asl::buffer buf; - asl::buffer buf2; - - buf.push(&d[0]); - buf.push(&d[1]); - buf.push(&d[2]); - - buf2.push(&d[3]); - buf2.push(&d[4]); - buf2.push(&d[5]); - - ASL_TEST_EXPECT(d[0] == false); - ASL_TEST_EXPECT(d[1] == false); - ASL_TEST_EXPECT(d[2] == false); - ASL_TEST_EXPECT(d[3] == false); - ASL_TEST_EXPECT(d[4] == false); - ASL_TEST_EXPECT(d[5] == false); - - buf2 = ASL_MOVE(buf); - - ASL_TEST_EXPECT(buf.size() == 0); - ASL_TEST_EXPECT(buf2.size() == 3); - - ASL_TEST_EXPECT(d[0] == false); - ASL_TEST_EXPECT(d[1] == false); - ASL_TEST_EXPECT(d[2] == false); - ASL_TEST_EXPECT(d[3] == true); - ASL_TEST_EXPECT(d[4] == true); - ASL_TEST_EXPECT(d[5] == true); - } - - ASL_TEST_EXPECT(d[0] == true); - ASL_TEST_EXPECT(d[1] == true); - ASL_TEST_EXPECT(d[2] == true); - ASL_TEST_EXPECT(d[3] == true); - ASL_TEST_EXPECT(d[4] == true); - ASL_TEST_EXPECT(d[5] == true); -} - -ASL_TEST(move_assign_trivial_heap_to_inline) -{ - isize_t alloc_count = 0; - asl::buffer buf{CounterAllocator{&alloc_count}}; - asl::buffer buf2{CounterAllocator{&alloc_count}}; - - buf.push(1); - buf.push(2); - ASL_TEST_EXPECT(alloc_count == 0); - - buf2.push(3); - buf2.push(4); - buf2.push(5); - ASL_TEST_EXPECT(alloc_count == 1); - - buf = ASL_MOVE(buf2); - ASL_TEST_EXPECT(alloc_count == 1); - - ASL_TEST_EXPECT(buf.size() == 3); - ASL_TEST_EXPECT(buf2.size() == 0); - ASL_TEST_EXPECT(buf[0] == 3); - ASL_TEST_EXPECT(buf[1] == 4); - ASL_TEST_EXPECT(buf[2] == 5); -} - -ASL_TEST(move_assign_trivial_inline_to_heap) -{ - isize_t alloc_count = 0; - asl::buffer buf{CounterAllocator{&alloc_count}}; - asl::buffer buf2{CounterAllocator{&alloc_count}}; - - buf.push(1); - buf.push(2); - ASL_TEST_EXPECT(alloc_count == 0); - - buf2.push(3); - buf2.push(4); - buf2.push(5); - ASL_TEST_EXPECT(alloc_count == 1); - - buf2 = ASL_MOVE(buf); - ASL_TEST_EXPECT(alloc_count == 1); - - ASL_TEST_EXPECT(buf.size() == 0); - ASL_TEST_EXPECT(buf2.size() == 2); - ASL_TEST_EXPECT(buf2[0] == 1); - ASL_TEST_EXPECT(buf2[1] == 2); -} - -ASL_TEST(move_assign_inline_to_heap) -{ - bool d[6]{}; - - { - asl::buffer buf; - asl::buffer buf2; - - buf.push(&d[0]); - buf.push(&d[1]); - - buf2.push(&d[2]); - buf2.push(&d[3]); - buf2.push(&d[4]); - buf2.push(&d[5]); - - buf2 = ASL_MOVE(buf); - - ASL_TEST_EXPECT(buf.size() == 0); - ASL_TEST_EXPECT(buf2.size() == 2); - ASL_TEST_EXPECT(d[0] == false); - ASL_TEST_EXPECT(d[1] == false); - ASL_TEST_EXPECT(d[2] == false); // moved but not destroyed - ASL_TEST_EXPECT(d[3] == false); // moved but not destroyed - ASL_TEST_EXPECT(d[4] == true); - ASL_TEST_EXPECT(d[5] == true); - } - - ASL_TEST_EXPECT(d[0] == true); - ASL_TEST_EXPECT(d[1] == true); - ASL_TEST_EXPECT(d[2] == false); // moved but not destroyed - ASL_TEST_EXPECT(d[3] == false); // moved but not destroyed - ASL_TEST_EXPECT(d[4] == true); - ASL_TEST_EXPECT(d[5] == true); -} - -ASL_TEST(move_assign_from_inline_incompatible_allocator) -{ - bool d[6]{}; - - { - asl::buffer buf; - asl::buffer buf2; - - buf.push(&d[0]); - buf.push(&d[1]); - - buf2.push(&d[2]); - buf2.push(&d[3]); - buf2.push(&d[4]); - buf2.push(&d[5]); - - buf2 = ASL_MOVE(buf); - - ASL_TEST_EXPECT(buf.size() == 0); - ASL_TEST_EXPECT(buf2.size() == 2); - ASL_TEST_EXPECT(d[0] == false); - ASL_TEST_EXPECT(d[1] == false); - ASL_TEST_EXPECT(d[2] == true); - ASL_TEST_EXPECT(d[3] == true); - ASL_TEST_EXPECT(d[4] == true); - ASL_TEST_EXPECT(d[5] == true); - } - - ASL_TEST_EXPECT(d[0] == true); - ASL_TEST_EXPECT(d[1] == true); - ASL_TEST_EXPECT(d[2] == true); - ASL_TEST_EXPECT(d[3] == true); - ASL_TEST_EXPECT(d[4] == true); - ASL_TEST_EXPECT(d[5] == true); -} - -ASL_TEST(copy_construct_inline) -{ - asl::buffer buf; - buf.push(0); - buf.push(1); - buf.push(2); - - asl::buffer buf2{buf}; - - ASL_TEST_EXPECT(buf.size() == buf2.size()); - ASL_TEST_EXPECT(buf.size() == 3); - ASL_TEST_EXPECT(buf[0] == 0); - ASL_TEST_EXPECT(buf[1] == 1); - ASL_TEST_EXPECT(buf[2] == 2); - ASL_TEST_EXPECT(buf2[0] == 0); - ASL_TEST_EXPECT(buf2[1] == 1); - ASL_TEST_EXPECT(buf2[2] == 2); -} - -ASL_TEST(copy_assign_into_smaller) -{ - asl::buffer buf; - buf.push(0); - buf.push(1); - buf.push(2); - - asl::buffer buf2; - buf2.push(4); - - buf2 = buf; - - ASL_TEST_EXPECT(buf.size() == 3); - ASL_TEST_EXPECT(buf2.size() == 3); - - ASL_TEST_EXPECT(buf[0] == 0); - ASL_TEST_EXPECT(buf[1] == 1); - ASL_TEST_EXPECT(buf[2] == 2); - ASL_TEST_EXPECT(buf2[0] == 0); - ASL_TEST_EXPECT(buf2[1] == 1); - ASL_TEST_EXPECT(buf2[2] == 2); -} - -ASL_TEST(copy_assign_into_larger) -{ - asl::buffer buf; - buf.push(0); - buf.push(1); - buf.push(2); - - asl::buffer buf2; - buf2.push(4); - - buf = buf2; - - ASL_TEST_EXPECT(buf.size() == 1); - ASL_TEST_EXPECT(buf2.size() == 1); - - ASL_TEST_EXPECT(buf[0] == 4); - ASL_TEST_EXPECT(buf2[0] == 4); -} - -ASL_TEST(resize_default) -{ - asl::buffer buf; - - buf.push(5); - buf.resize(4); - - ASL_TEST_ASSERT(buf.size() == 4); - ASL_TEST_EXPECT(buf[0] == 5); - ASL_TEST_EXPECT(buf[1] == 0); - ASL_TEST_EXPECT(buf[2] == 0); - ASL_TEST_EXPECT(buf[3] == 0); - - buf.resize(2); - - ASL_TEST_ASSERT(buf.size() == 2); - ASL_TEST_EXPECT(buf[0] == 5); - ASL_TEST_EXPECT(buf[1] == 0); -} - -ASL_TEST(resize) -{ - asl::buffer buf; - - buf.push(5); - buf.resize(4, 6); - - ASL_TEST_ASSERT(buf.size() == 4); - ASL_TEST_EXPECT(buf[0] == 5); - ASL_TEST_EXPECT(buf[1] == 6); - ASL_TEST_EXPECT(buf[2] == 6); - ASL_TEST_EXPECT(buf[3] == 6); - - buf.resize(2, 7); - - ASL_TEST_ASSERT(buf.size() == 2); - ASL_TEST_EXPECT(buf[0] == 5); - ASL_TEST_EXPECT(buf[1] == 6); -} - -ASL_TEST(resize_zero) -{ - asl::buffer buf; - for (int i = 0; i < 100; ++i) - { - buf.push(i); - } - - buf.resize_zero(200); - ASL_TEST_ASSERT(buf.size() == 200); - - for (int i = 0; i < 100; ++i) - { - ASL_TEST_EXPECT(buf[i] == i); - ASL_TEST_EXPECT(buf[100 + i] == 0); - } -} - diff --git a/asl/tests/float_tests.cpp b/asl/tests/float_tests.cpp deleted file mode 100644 index d645be8..0000000 --- a/asl/tests/float_tests.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "asl/float.hpp" - -#include "asl/testing/testing.hpp" - -ASL_TEST(is_infinity) -{ - ASL_TEST_EXPECT(!asl::is_infinity(0.0F)); - ASL_TEST_EXPECT(!asl::is_infinity(-25.0F)); - ASL_TEST_EXPECT(asl::is_infinity(45.0F / 0.0F)); - ASL_TEST_EXPECT(asl::is_infinity(-45.0F / 0.0F)); - ASL_TEST_EXPECT(asl::is_infinity(asl::infinity())); - ASL_TEST_EXPECT(asl::is_infinity(-asl::infinity())); -} - -ASL_TEST(is_nan) -{ - ASL_TEST_EXPECT(!asl::is_nan(0.0F)); - ASL_TEST_EXPECT(!asl::is_nan(-25.0F)); - ASL_TEST_EXPECT(!asl::is_nan(45.0F / 0.0F)); - ASL_TEST_EXPECT(asl::is_nan(asl::nan())); - ASL_TEST_EXPECT(asl::is_nan(asl::nan())); -} - diff --git a/asl/tests/format_tests.cpp b/asl/tests/format_tests.cpp deleted file mode 100644 index a91cac6..0000000 --- a/asl/tests/format_tests.cpp +++ /dev/null @@ -1,110 +0,0 @@ -#include "asl/format.hpp" -#include "asl/testing/testing.hpp" -#include "asl/float.hpp" -#include "asl/string_builder.hpp" - -static_assert(asl::formattable); - -ASL_TEST(format_args) -{ - // @Todo Introduce ASL_TEST_EXPECT_EQ, or ASL_TEST_EXPECT_STREQ - - auto s = asl::format_to_string("Hello, world!"); - ASL_TEST_EXPECT(s == "Hello, world!"_sv); - - s = asl::format_to_string(""); - ASL_TEST_EXPECT(s == ""_sv); - - s = asl::format_to_string("Hello, {}!", "world"); - ASL_TEST_EXPECT(s == "Hello, world!"_sv); - - s = asl::format_to_string("Hello, {}! {}", "world"); - ASL_TEST_EXPECT(s == "Hello, world! "_sv); - - s = asl::format_to_string("Hello, pup!", "world"); - ASL_TEST_EXPECT(s == "Hello, pup!"_sv); - - s = asl::format_to_string("{}", "CHEESE"); - ASL_TEST_EXPECT(s == "CHEESE"_sv); - - s = asl::format_to_string("{ ", "CHEESE"); - ASL_TEST_EXPECT(s == " "_sv); - - s = asl::format_to_string("{", "CHEESE"); - ASL_TEST_EXPECT(s == ""_sv); - - s = asl::format_to_string("a{{b"); - ASL_TEST_EXPECT(s == "a{b"_sv); - - s = asl::format_to_string("{{{}}} }", "CHEESE"); - ASL_TEST_EXPECT(s == "{CHEESE} }"_sv); -} - -ASL_TEST(format_integers) -{ - auto s = asl::format_to_string("{} {} {}", 0, 1, 2); - ASL_TEST_EXPECT(s == "0 1 2"_sv); - - s = asl::format_to_string("{} {} {}", 10, 11, 12); - ASL_TEST_EXPECT(s == "10 11 12"_sv); - - s = asl::format_to_string("{} {} {}", 100, 101, 102); - ASL_TEST_EXPECT(s == "100 101 102"_sv); - - s = asl::format_to_string("{} {} {}", 1000, 1001, 1002); - ASL_TEST_EXPECT(s == "1000 1001 1002"_sv); - - s = asl::format_to_string("{} {} {} {}", -1, -23, -456, -7890); - ASL_TEST_EXPECT(s == "-1 -23 -456 -7890"_sv); -} - -ASL_TEST(format_floats) -{ - auto s = asl::format_to_string("{} {} {}", 0.0F, 1.0, 2.0F); - ASL_TEST_EXPECT(s == "0 1 2"_sv); - - s = asl::format_to_string("{} {} {}", 0.1F, 0.001F, 0.123F); - ASL_TEST_EXPECT(s == "0.1 0.001 0.123"_sv); - - s = asl::format_to_string("{} {}", 1.25F, -22.3); - ASL_TEST_EXPECT(s == "1.25 -22.3"_sv); - - s = asl::format_to_string("{}", 1e32); - ASL_TEST_EXPECT(s == "100000000000000000000000000000000"_sv); - - s = asl::format_to_string("{}", 123e-8); - ASL_TEST_EXPECT(s == "0.00000123"_sv); - - s = asl::format_to_string("{} {}", asl::infinity(), -asl::infinity()); - ASL_TEST_EXPECT(s == "Infinity -Infinity"_sv); - - s = asl::format_to_string("{}", asl::nan()); - ASL_TEST_EXPECT(s == "NaN"_sv); -} - -ASL_TEST(format_boolean) -{ - auto s = asl::format_to_string("{} {}", true, false); - ASL_TEST_EXPECT(s == "true false"_sv); -} - -struct CustomFormat -{ - int x; - friend void AslFormat(asl::Formatter&, const CustomFormat&); -}; - -void AslFormat(asl::Formatter& f, const CustomFormat& c) -{ - f.write("("_sv); - AslFormat(f, c.x); - f.write(")"_sv); -} - -static_assert(asl::formattable); - -ASL_TEST(format_custom) -{ - auto s = asl::format_to_string("{}", CustomFormat{37}); - ASL_TEST_EXPECT(s == "(37)"_sv); -} diff --git a/asl/tests/functional_tests.cpp b/asl/tests/functional_tests.cpp deleted file mode 100644 index 2cdbe7a..0000000 --- a/asl/tests/functional_tests.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include "asl/functional.hpp" -#include "asl/testing/testing.hpp" - -struct HasFunction -{ - void do_something(int, float) {} -}; - -struct HasMember -{ - int member{}; - int member_array[4]{}; - void (*member_fn)(){}; -}; - -struct Functor -{ - int64_t operator()() { return 35; } - int operator()(int x) { return x; } -}; - -static int some_func0() { return 1; } -static int some_func1(int x) { return x + 1; } -[[maybe_unused]] static float some_func1(float x) { return x + 1; } -static int some_func2(int x, int b) { return x + b; } - -static_assert(asl::same_as, int64_t>); -static_assert(asl::same_as, int>); -static_assert(asl::same_as(some_func1))(float)>, float>); -static_assert(asl::same_as, void>); -static_assert(asl::same_as, int>); - -ASL_TEST(invoke_member_function) -{ - HasFunction c; - asl::invoke(&HasFunction::do_something, c, 5, 5.0F); - asl::invoke(&HasFunction::do_something, &c, 5, 5.0F); -} - -ASL_TEST(invoke_member_data) -{ - HasMember c; - - asl::invoke(&HasMember::member, c); - asl::invoke(&HasMember::member_array, c); - asl::invoke(&HasMember::member_fn, c); - asl::invoke(&HasMember::member, &c); - asl::invoke(&HasMember::member_array, &c); - asl::invoke(&HasMember::member_fn, &c); -} - -ASL_TEST(invoke_fn) -{ - ASL_TEST_EXPECT(asl::invoke(some_func0) == 1); - ASL_TEST_EXPECT(asl::invoke(static_cast(some_func1), 8) == 9); - ASL_TEST_EXPECT(asl::invoke(some_func2, 4, 8) == 12); - ASL_TEST_EXPECT(asl::invoke(&some_func0) == 1); - ASL_TEST_EXPECT(asl::invoke(static_cast(&some_func1), 8) == 9); - ASL_TEST_EXPECT(asl::invoke(&some_func2, 4, 8) == 12); -} - -ASL_TEST(invoke_operator_call) -{ - Functor f; - ASL_TEST_EXPECT(asl::invoke(f) == 35); - ASL_TEST_EXPECT(asl::invoke(f, 8) == 8); -} - -ASL_TEST(invoke_lambda) -{ - ASL_TEST_EXPECT(asl::invoke([](){ return 35; }) == 35); - ASL_TEST_EXPECT(asl::invoke([](int x){ return x + 2; }, 6) == 8); -} diff --git a/asl/tests/hash_map_tests.cpp b/asl/tests/hash_map_tests.cpp deleted file mode 100644 index 619c5e7..0000000 --- a/asl/tests/hash_map_tests.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "asl/testing/testing.hpp" -#include "asl/hash_map.hpp" - -ASL_TEST(default) -{ - asl::hash_map map; - - ASL_TEST_EXPECT(!map.contains(45)); - ASL_TEST_EXPECT(!map.contains(46)); - - map.insert(45, 5); - map.insert(46, 6); - - ASL_TEST_EXPECT(map.size() == 2); - - ASL_TEST_EXPECT(map.contains(45)); - ASL_TEST_EXPECT(map.contains(46)); - ASL_TEST_EXPECT(!map.contains(47)); - - ASL_TEST_EXPECT(*map.get(45) == 5); - ASL_TEST_EXPECT(*map.get(46) == 6); - ASL_TEST_EXPECT(map.get(47) == nullptr); - - ASL_TEST_EXPECT(map.remove(45)); - ASL_TEST_EXPECT(!map.remove(45)); - - ASL_TEST_EXPECT(map.size() == 1); - - ASL_TEST_EXPECT(!map.contains(45)); - ASL_TEST_EXPECT(map.contains(46)); - ASL_TEST_EXPECT(!map.contains(47)); - - ASL_TEST_EXPECT(map.get(45) == nullptr); - ASL_TEST_EXPECT(*map.get(46) == 6); - ASL_TEST_EXPECT(map.get(47) == nullptr); - - map.insert(46, 460); - - ASL_TEST_EXPECT(map.size() == 1); - - ASL_TEST_EXPECT(!map.contains(45)); - ASL_TEST_EXPECT(map.contains(46)); - ASL_TEST_EXPECT(!map.contains(47)); - - ASL_TEST_EXPECT(map.get(45) == nullptr); - ASL_TEST_EXPECT(*map.get(46) == 460); - ASL_TEST_EXPECT(map.get(47) == nullptr); -} diff --git a/asl/tests/hash_set_tests.cpp b/asl/tests/hash_set_tests.cpp deleted file mode 100644 index 0c00c87..0000000 --- a/asl/tests/hash_set_tests.cpp +++ /dev/null @@ -1,185 +0,0 @@ -#include "asl/hash_set.hpp" -#include "asl/testing/testing.hpp" -#include "asl/tests/test_types.hpp" -#include "asl/string.hpp" -#include "asl/string_view.hpp" - -ASL_TEST(empty) -{ - asl::hash_set set; - - ASL_TEST_EXPECT(set.size() == 0); - - for (int i = 0; i < 100; ++i) - { - ASL_TEST_EXPECT(!set.contains(i)); - } -} - -ASL_TEST(a_bunch_of_strings) -{ - asl::hash_set> set; - - set.insert("Hello, world!"); - ASL_TEST_EXPECT(set.size() == 1); - - set.insert("Hello, puppy!"); - ASL_TEST_EXPECT(set.size() == 2); - - set.insert("Hello, puppy!"); - ASL_TEST_EXPECT(set.size() == 2); - - ASL_TEST_EXPECT(set.contains("Hello, world!"_sv)); - ASL_TEST_EXPECT(set.contains("Hello, puppy!"_sv)); - ASL_TEST_EXPECT(!set.contains("Hello, Steven!"_sv)); -} - -ASL_TEST(a_bunch_of_ints) -{ - asl::hash_set set; - - int count = 3000; - - for (int i = 0; i < count; ++i) - { - set.insert(i); - } - - ASL_TEST_EXPECT(set.size() == count); - - for (int i = 0; i < count * 2; ++i) - { - ASL_TEST_EXPECT(set.contains(i) == (i < count)); - } -} - -struct HashWithDestructor: public DestructorObserver -{ - int x; - - HashWithDestructor(int x_, bool* ptr) - : DestructorObserver{ptr} - , x{x_} - {} - - constexpr bool operator==(const HashWithDestructor& other) const - { - return x == other.x; - } -}; - -struct CustomComparator -{ - static bool eq(const HashWithDestructor& a, const HashWithDestructor& b) - { - return a.x == b.x; - } - - static bool eq(const HashWithDestructor& a, int b) - { - return a.x == b; - } -}; - -struct CustomHasher -{ - static uint64_t hash(const HashWithDestructor& b) - { - return asl::hash_value(b.x); - } - - static uint64_t hash(int x) - { - return asl::hash_value(x); - } -}; - -ASL_TEST(destructor_and_remove) -{ - static constexpr int kCount = 200; - bool destroyed[kCount]{}; - - { - asl::hash_set set; - - for (int i = 0; i < kCount; ++i) - { - set.insert(i, &destroyed[i]); // NOLINT - } - - ASL_TEST_EXPECT(set.size() == kCount); - - for (int i = 0; i < kCount; ++i) - { - ASL_TEST_EXPECT(!destroyed[i]); // NOLINT - } - - for (int i = 0; i < kCount; i += 2) - { - ASL_TEST_EXPECT(set.remove(i)); - } - - for (int i = 0; i < kCount; i += 2) - { - ASL_TEST_EXPECT(!set.contains(i)); - ASL_TEST_EXPECT(set.contains(i+1)); - ASL_TEST_EXPECT(destroyed[i]); // NOLINT - ASL_TEST_EXPECT(!destroyed[i + 1]); // NOLINT - } - } - - for (int i = 0; i < kCount; ++i) - { - ASL_TEST_EXPECT(destroyed[i]); // NOLINT - } -} - -ASL_TEST(copy) -{ - asl::hash_set set1; - - for (int i = 0; i < 100; ++i) - { - set1.insert(i); - } - - asl::hash_set set2 = set1; - asl::hash_set set3; - set3 = set1; - - ASL_TEST_EXPECT(set2.size() == 100); - ASL_TEST_EXPECT(set3.size() == 100); - - for (int i = 0; i < 100; ++i) - { - ASL_TEST_EXPECT(set2.contains(i)); - ASL_TEST_EXPECT(set3.contains(i)); - } -} - -ASL_TEST(move) -{ - asl::hash_set set1; - - for (int i = 0; i < 100; ++i) - { - set1.insert(i); - } - - asl::hash_set set2 = ASL_MOVE(set1); - - ASL_TEST_EXPECT(set2.size() == 100); - for (int i = 0; i < 100; ++i) - { - ASL_TEST_EXPECT(set2.contains(i)); - } - - set1 = ASL_MOVE(set2); - - ASL_TEST_EXPECT(set1.size() == 100); - for (int i = 0; i < 100; ++i) - { - ASL_TEST_EXPECT(set1.contains(i)); - } -} - diff --git a/asl/tests/hash_tests.cpp b/asl/tests/hash_tests.cpp deleted file mode 100644 index 20a5183..0000000 --- a/asl/tests/hash_tests.cpp +++ /dev/null @@ -1,260 +0,0 @@ -#include "asl/testing/testing.hpp" -#include "asl/hash.hpp" -#include "asl/string_view.hpp" -#include "asl/string.hpp" -#include "asl/buffer.hpp" -#include "asl/box.hpp" -#include "asl/option.hpp" -#include "asl/status.hpp" -#include "asl/status_or.hpp" - -static_assert(!asl::hashable); -static_assert(!asl::hashable); -static_assert(!asl::hashable); - -static_assert(asl::hashable); -static_assert(asl::hashable); -static_assert(asl::hashable); -static_assert(asl::hashable); -static_assert(asl::hashable); - -static_assert(asl::hashable); -static_assert(asl::hashable); -static_assert(asl::hashable); -static_assert(asl::hashable); - -ASL_TEST(integers) -{ - uint64_t a = asl::hash_value(45); - uint64_t b = asl::hash_value(45); - uint64_t c = asl::hash_value(46); - uint64_t d = asl::hash_value(45); - - ASL_TEST_EXPECT(a == b); - ASL_TEST_EXPECT(a != c); - ASL_TEST_EXPECT(a != d); -} - -static_assert(asl::hashable); - -ASL_TEST(bool) -{ - ASL_TEST_EXPECT(asl::hash_value(true) == asl::hash_value(true)); - ASL_TEST_EXPECT(asl::hash_value(false) == asl::hash_value(false)); - ASL_TEST_EXPECT(asl::hash_value(true) != asl::hash_value(false)); -} - -static_assert(asl::hashable); -static_assert(asl::hashable>); - -ASL_TEST(strings) -{ - ASL_TEST_EXPECT(asl::hash_value("hello"_sv) == asl::hash_value("hello"_sv)); - ASL_TEST_EXPECT(asl::hash_value("hello"_sv) != asl::hash_value("hello "_sv)); - ASL_TEST_EXPECT(asl::hash_value("hello"_sv) != asl::hash_value("HELLO"_sv)); - - ASL_TEST_EXPECT(asl::hash_value(asl::string("hello"_sv)) == asl::hash_value(asl::string("hello"_sv))); - ASL_TEST_EXPECT(asl::hash_value(asl::string("hello"_sv)) != asl::hash_value(asl::string("hello "_sv))); - ASL_TEST_EXPECT(asl::hash_value(asl::string("hello"_sv)) != asl::hash_value(asl::string("HELLO"_sv))); - - ASL_TEST_EXPECT(asl::hash_value("hello"_sv) == asl::hash_value(asl::string("hello"_sv))); -} - -static_assert(asl::hashable>); -static_assert(!asl::hashable>); -static_assert(asl::hashable>); - -ASL_TEST(span) -{ - int ints1[] = {1, 2, 3}; - int ints2[] = {1, 2, 3}; - int ints3[] = {1, 2}; - int ints4[] = {3, 2, 1}; - - ASL_TEST_EXPECT(asl::hash_value(asl::span(ints1)) == asl::hash_value(asl::span(ints2))); - ASL_TEST_EXPECT(asl::hash_value(asl::span(ints1)) != asl::hash_value(asl::span(ints3))); - ASL_TEST_EXPECT(asl::hash_value(asl::span(ints1)) != asl::hash_value(asl::span(ints4))); - - asl::string_view strs1[] = {"a", "abc", "hello"}; - asl::string_view strs2[] = {"a", "abc", "hello"}; - asl::string_view strs3[] = {"a", "abc"}; - asl::string_view strs4[] = {"a", "abc", "hello", "what"}; - - ASL_TEST_EXPECT(asl::hash_value(asl::span(strs1)) == asl::hash_value(asl::span(strs2))); - ASL_TEST_EXPECT(asl::hash_value(asl::span(strs1)) != asl::hash_value(asl::span(strs3))); - ASL_TEST_EXPECT(asl::hash_value(asl::span(strs1)) != asl::hash_value(asl::span(strs4))); -} - -static_assert(asl::hashable>); -static_assert(!asl::hashable>); - -ASL_TEST(buffer) -{ - asl::buffer ints1; - ints1.push(1); - ints1.push(2); - ints1.push(3); - - asl::buffer ints2; - ints2.push(1); - ints2.push(2); - ints2.push(3); - - asl::buffer ints3; - ints3.push(1); - ints3.push(2); - - asl::buffer ints4; - ints4.push(1); - ints4.push(2); - ints4.push(4); - - ASL_TEST_EXPECT(asl::hash_value(ints1) == asl::hash_value(ints2)); - ASL_TEST_EXPECT(asl::hash_value(ints1) != asl::hash_value(ints3)); - ASL_TEST_EXPECT(asl::hash_value(ints1) != asl::hash_value(ints4)); - ASL_TEST_EXPECT(asl::hash_value(ints1) == asl::hash_value(ints1.as_span())); - - asl::buffer strs1; - strs1.push("Hello"); - strs1.push("World"); - - asl::buffer strs2; - strs2.push("Hello"); - strs2.push("World"); - - asl::buffer strs3; - strs3.push("Hello"); - strs3.push("world"); - - asl::buffer strs4; - strs4.push("Hello"); - strs4.push("World"); - strs4.push("World"); - - ASL_TEST_EXPECT(asl::hash_value(strs1) == asl::hash_value(strs2)); - ASL_TEST_EXPECT(asl::hash_value(strs1) != asl::hash_value(strs3)); - ASL_TEST_EXPECT(asl::hash_value(strs1) != asl::hash_value(strs4)); - ASL_TEST_EXPECT(asl::hash_value(strs1) == asl::hash_value(strs1.as_span())); -} - -enum Enum1 {}; -enum class Enum2 {}; - -static_assert(asl::hashable); -static_assert(asl::hashable); - -static_assert(!asl::hashable>); -static_assert(asl::hashable>); - -ASL_TEST(box) -{ - auto b1 = asl::make_box("Hello, world!"); - auto b2 = asl::make_box("Hello, world!"); - auto b3 = asl::make_box("Hello, world! 2"); - - ASL_TEST_EXPECT(asl::hash_value(b1) == asl::hash_value(b2)); - ASL_TEST_EXPECT(asl::hash_value(b1) != asl::hash_value(b3)); - ASL_TEST_EXPECT(asl::hash_value(b1) == asl::hash_value("Hello, world!"_sv)); -} - -struct NonZero -{ - int value; - - constexpr explicit NonZero(int x) : value(x) - { - ASL_ASSERT(x != 0); - } - - constexpr explicit NonZero(asl::niche_t) : value(0) {} - - constexpr bool operator==(asl::niche_t) const { return value == 0; } -}; - -namespace asl { template<> struct is_uniquely_represented : true_type {}; } -static_assert(asl::has_niche); -static_assert(asl::uniquely_represented); - -static_assert(asl::hashable>); -static_assert(!asl::hashable>); -static_assert(asl::hashable>); -static_assert(asl::hashable>); -static_assert(asl::uniquely_represented>); - -ASL_TEST(option) -{ - asl::option int1 = 0; - asl::option int2 = 0; - asl::option int3 = 1; - asl::option int4 = asl::nullopt; - - ASL_TEST_EXPECT(asl::hash_value(int1) == asl::hash_value(int2)); - ASL_TEST_EXPECT(asl::hash_value(int1) != asl::hash_value(int3)); - ASL_TEST_EXPECT(asl::hash_value(int1) != asl::hash_value(int4)); - - asl::option noz1{8}; - asl::option noz2{8}; - asl::option noz3{9}; - asl::option noz4 = asl::nullopt; - - ASL_TEST_EXPECT(asl::hash_value(noz1) == asl::hash_value(noz2)); - ASL_TEST_EXPECT(asl::hash_value(noz1) != asl::hash_value(noz3)); - ASL_TEST_EXPECT(asl::hash_value(noz1) != asl::hash_value(noz4)); -} - -static_assert(asl::hashable); - -ASL_TEST(status) -{ - asl::status s1 = asl::ok(); - asl::status s2 = asl::ok(); - asl::status s3 = asl::internal_error(); - asl::status s4 = asl::internal_error(); - asl::status s5 = asl::runtime_error(); - asl::status s6 = asl::internal_error("Oh, no!"); - asl::status s7 = asl::internal_error("Oh, no!"); - asl::status s8 = asl::internal_error("Oh, no"); - asl::status s9 = asl::runtime_error("Oh, no!"); - - ASL_TEST_EXPECT(asl::hash_value(s1) == asl::hash_value(s2)); - ASL_TEST_EXPECT(asl::hash_value(s3) == asl::hash_value(s4)); - ASL_TEST_EXPECT(asl::hash_value(s6) == asl::hash_value(s7)); - - ASL_TEST_EXPECT(asl::hash_value(s1) != asl::hash_value(s3)); - ASL_TEST_EXPECT(asl::hash_value(s1) != asl::hash_value(s5)); - ASL_TEST_EXPECT(asl::hash_value(s1) != asl::hash_value(s6)); - ASL_TEST_EXPECT(asl::hash_value(s1) != asl::hash_value(s9)); - - ASL_TEST_EXPECT(asl::hash_value(s3) != asl::hash_value(s5)); - ASL_TEST_EXPECT(asl::hash_value(s3) != asl::hash_value(s6)); - ASL_TEST_EXPECT(asl::hash_value(s3) != asl::hash_value(s8)); - ASL_TEST_EXPECT(asl::hash_value(s3) != asl::hash_value(s9)); - - ASL_TEST_EXPECT(asl::hash_value(s6) != asl::hash_value(s8)); - ASL_TEST_EXPECT(asl::hash_value(s6) != asl::hash_value(s9)); -} - -static_assert(asl::hashable>); -static_assert(asl::hashable>); -static_assert(!asl::hashable>); - -ASL_TEST(status_or) -{ - asl::status_or s1 = 42; - asl::status_or s2 = 42; - asl::status_or s3 = 43; - asl::status_or s4 = asl::runtime_error(); - asl::status_or s5 = asl::runtime_error(); - asl::status_or s6 = asl::runtime_error("Hello"); - asl::status_or s7 = asl::runtime_error("Hello"); - - ASL_TEST_EXPECT(asl::hash_value(s1) == asl::hash_value(s2)); - ASL_TEST_EXPECT(asl::hash_value(s4) == asl::hash_value(s5)); - ASL_TEST_EXPECT(asl::hash_value(s6) == asl::hash_value(s7)); - - ASL_TEST_EXPECT(asl::hash_value(s1) != asl::hash_value(s3)); - ASL_TEST_EXPECT(asl::hash_value(s1) != asl::hash_value(s4)); - ASL_TEST_EXPECT(asl::hash_value(s1) != asl::hash_value(s6)); - - ASL_TEST_EXPECT(asl::hash_value(s4) != asl::hash_value(s6)); -} diff --git a/asl/tests/integers_tests.cpp b/asl/tests/integers_tests.cpp deleted file mode 100644 index 1b5a20a..0000000 --- a/asl/tests/integers_tests.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "asl/integers.hpp" - -static_assert(sizeof(int8_t) == 1); -static_assert(sizeof(int16_t) == 2); -static_assert(sizeof(int32_t) == 4); -static_assert(sizeof(int64_t) == 8); - -static_assert(sizeof(uint8_t) == 1); -static_assert(sizeof(uint16_t) == 2); -static_assert(sizeof(uint32_t) == 4); -static_assert(sizeof(uint64_t) == 8); - -static_assert(sizeof(asl::byte) == 1); - -static_assert(sizeof(uintptr_t) == sizeof(void*)); diff --git a/asl/tests/maybe_uninit_tests.cpp b/asl/tests/maybe_uninit_tests.cpp deleted file mode 100644 index 9861c33..0000000 --- a/asl/tests/maybe_uninit_tests.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "asl/maybe_uninit.hpp" -#include "asl/tests/test_types.hpp" - -static_assert(asl::layout::of() == asl::layout::of>()); -static_assert(asl::size_of == asl::size_of>); -static_assert(asl::align_of == asl::align_of>); - -#define TEST_TYPE_PROPERTIES(PRP) \ - static_assert(asl::PRP> == asl::PRP); \ - static_assert(asl::PRP> == asl::PRP); \ - static_assert(asl::PRP> == asl::PRP); \ - static_assert(asl::PRP> == asl::PRP); \ - static_assert(asl::PRP> == asl::PRP); \ - static_assert(asl::PRP> == asl::PRP); - -TEST_TYPE_PROPERTIES(trivially_default_constructible); -TEST_TYPE_PROPERTIES(trivially_copy_constructible); -TEST_TYPE_PROPERTIES(trivially_move_constructible); -TEST_TYPE_PROPERTIES(trivially_copy_assignable); -TEST_TYPE_PROPERTIES(trivially_move_assignable); -TEST_TYPE_PROPERTIES(trivially_destructible); - diff --git a/asl/tests/meta_tests.cpp b/asl/tests/meta_tests.cpp deleted file mode 100644 index b015eb6..0000000 --- a/asl/tests/meta_tests.cpp +++ /dev/null @@ -1,289 +0,0 @@ -#include "asl/meta.hpp" -#include "asl/tests/test_types.hpp" -#include "asl/testing/testing.hpp" -#include "asl/box.hpp" - -struct Struct {}; -union Union {}; -enum Enum : uint8_t { EnumVariant = 0, }; -enum class EnumClass : uint8_t { Variant = 0, }; - -static_assert(!asl::same_as); -static_assert(asl::same_as); - -static_assert(asl::same_as, float>); -static_assert(asl::same_as, int>); - -static_assert(asl::default_constructible); -static_assert(asl::default_constructible); -static_assert(asl::default_constructible); - -static_assert(asl::trivially_default_constructible); -static_assert(asl::trivially_default_constructible); -static_assert(!asl::trivially_default_constructible); - -static_assert(asl::copy_constructible); -static_assert(asl::copy_constructible); -static_assert(asl::copy_constructible); -static_assert(!asl::copy_constructible); -static_assert(!asl::copy_constructible); - -static_assert(asl::trivially_copy_constructible); -static_assert(asl::trivially_copy_constructible); -static_assert(asl::trivially_copy_constructible); -static_assert(!asl::trivially_copy_constructible); -static_assert(!asl::trivially_copy_constructible); -static_assert(!asl::trivially_copy_constructible); -static_assert(!asl::trivially_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::move_constructible); - -static_assert(asl::trivially_move_constructible); -static_assert(asl::trivially_move_constructible); -static_assert(asl::trivially_move_constructible); -static_assert(!asl::trivially_move_constructible); -static_assert(!asl::trivially_move_constructible); -static_assert(!asl::trivially_move_constructible); -static_assert(!asl::trivially_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::copy_assignable); - -static_assert(asl::trivially_copy_assignable); -static_assert(asl::trivially_copy_assignable); -static_assert(asl::trivially_copy_assignable); -static_assert(asl::trivially_copy_assignable); -static_assert(!asl::trivially_copy_assignable); -static_assert(!asl::trivially_copy_assignable); -static_assert(!asl::trivially_copy_assignable); - -static_assert(asl::copyable); -static_assert(asl::copyable); -static_assert(asl::copyable); -static_assert(!asl::copyable); -static_assert(!asl::copyable); - -static_assert(asl::moveable); -static_assert(asl::moveable); -static_assert(asl::moveable); -static_assert(asl::moveable); -static_assert(!asl::moveable); - -static_assert(asl::move_assignable); -static_assert(asl::move_assignable); -static_assert(asl::move_assignable); -static_assert(asl::move_assignable); -static_assert(!asl::move_assignable); - -static_assert(asl::trivially_move_assignable); -static_assert(asl::trivially_move_assignable); -static_assert(asl::trivially_move_assignable); -static_assert(asl::trivially_move_assignable); -static_assert(!asl::trivially_move_assignable); -static_assert(!asl::trivially_move_assignable); -static_assert(!asl::trivially_move_assignable); - -static_assert(asl::trivially_destructible); -static_assert(asl::trivially_destructible); -static_assert(asl::trivially_destructible); -static_assert(!asl::trivially_destructible); -static_assert(asl::trivially_destructible); -static_assert(asl::trivially_destructible); -static_assert(asl::trivially_destructible); - -static_assert(asl::same_as>); -static_assert(asl::same_as>); -static_assert(asl::same_as>); - -static_assert(asl::same_as>); -static_assert(asl::same_as>); -static_assert(asl::same_as>); - -static_assert(asl::same_as>); -static_assert(asl::same_as>); -static_assert(asl::same_as>); -static_assert(asl::same_as>); - -static_assert(asl::is_void); -static_assert(asl::is_void); -static_assert(asl::is_void); -static_assert(asl::is_void); -static_assert(!asl::is_void); -static_assert(!asl::is_void); -static_assert(!asl::is_void); -static_assert(!asl::is_void); -static_assert(!asl::is_void); -static_assert(!asl::is_void); - -static_assert(asl::is_ref); -static_assert(asl::is_ref); -static_assert(asl::is_ref); -static_assert(asl::is_ref); -static_assert(!asl::is_ref); -static_assert(!asl::is_ref); -static_assert(!asl::is_ref); -static_assert(!asl::is_ref); - -static_assert(asl::is_ptr); -static_assert(asl::is_ptr); -static_assert(asl::is_ptr); -static_assert(!asl::is_ptr); -static_assert(!asl::is_ptr); -static_assert(!asl::is_ptr); -static_assert(!asl::is_ptr); - -static_assert(asl::same_as>); -static_assert(asl::same_as>); -static_assert(asl::same_as>); -static_assert(asl::same_as>); -static_assert(asl::same_as>); -static_assert(asl::same_as>); -static_assert(asl::same_as>); -static_assert(asl::same_as>); - -static_assert(asl::is_func); -static_assert(asl::is_func); -static_assert(asl::is_func); -static_assert(asl::is_func); -static_assert(asl::is_func); -static_assert(asl::is_func); -static_assert(!asl::is_func); -static_assert(!asl::is_func); -static_assert(!asl::is_func); -static_assert(!asl::is_func); - -static_assert(asl::is_object); -static_assert(asl::is_object); -static_assert(asl::is_object); -static_assert(asl::is_object); -static_assert(asl::is_object); -static_assert(asl::is_object); -static_assert(asl::is_object); -static_assert(asl::is_object); -static_assert(!asl::is_object); -static_assert(!asl::is_object); -static_assert(!asl::is_object); -static_assert(!asl::is_object); - -static_assert(!asl::is_array); -static_assert(!asl::is_array); -static_assert(!asl::is_array); -static_assert(!asl::is_array); -static_assert(!asl::is_array); -static_assert(asl::is_array); -static_assert(asl::is_array); -static_assert(!asl::is_array); -static_assert(!asl::is_array); -static_assert(!asl::is_array); -static_assert(!asl::is_array); -static_assert(!asl::is_array); - -static_assert(asl::same_as>); -static_assert(asl::same_as>); -static_assert(asl::same_as>); -static_assert(asl::same_as>); - -static_assert(asl::types_count == 2); -static_assert(asl::types_count == 2); -static_assert(asl::types_count == 1); -static_assert(asl::types_count<> == 0); - -class Base {}; -class Derived : public Base {}; -class C {}; -class D { public: operator C() { return c; } C c; }; // NOLINT -class E { public: template E(T&&) {} }; // NOLINT - -static_assert(asl::convertible_from); -static_assert(!asl::convertible_from); -static_assert(asl::convertible_from); -static_assert(!asl::convertible_from); -static_assert(asl::convertible_from); - -static_assert(!asl::convertible_from); -static_assert(asl::convertible_from); -static_assert(asl::convertible_from); -static_assert(asl::convertible_from); -static_assert(!asl::convertible_from); -static_assert(!asl::convertible_from); -static_assert(!asl::convertible_from); - -static_assert(asl::derived_from); -static_assert(!asl::derived_from); -static_assert(!asl::derived_from); -static_assert(!asl::derived_from); -static_assert(!asl::derived_from); -static_assert(!asl::derived_from); -static_assert(!asl::derived_from); - -static_assert(!asl::is_const); -static_assert(asl::is_const); -static_assert(!asl::is_const); -static_assert(asl::is_const); - -static_assert(asl::is_floating_point); -static_assert(asl::is_floating_point); -static_assert(asl::is_floating_point); -static_assert(!asl::is_floating_point); -static_assert(!asl::is_floating_point); -static_assert(!asl::is_floating_point); - -static_assert(asl::uniquely_represented); -static_assert(asl::uniquely_represented); -static_assert(!asl::uniquely_represented); - -enum Enum1 {}; -enum class Enum2 {}; - -static_assert(asl::uniquely_represented); -static_assert(asl::uniquely_represented); - -static_assert(!asl::is_enum); -static_assert(asl::is_enum); -static_assert(asl::is_enum); - -static_assert(asl::derefs_as); -static_assert(asl::derefs_as); -static_assert(asl::derefs_as); -static_assert(asl::derefs_as, int>); - -static_assert(asl::derefs_as); -static_assert(asl::derefs_as); -static_assert(asl::derefs_as); -static_assert(asl::derefs_as, Base>); - -static void wants_int(int) {} -static void wants_base(Base&) {} -static void wants_base_ptr(Base*) {} - -ASL_TEST(deref) -{ - int a = 4; - auto b = asl::make_box(5); - - wants_int(asl::deref(5)); - wants_int(asl::deref(a)); - wants_int(asl::deref(&a)); - wants_int(asl::deref(b)); - - Derived c{}; - auto d = asl::make_box(); - - wants_base(asl::deref(Derived{})); - wants_base(asl::deref(c)); - wants_base(asl::deref(&c)); - wants_base(asl::deref(d)); - - wants_base_ptr(&asl::deref(Derived{})); - wants_base_ptr(&asl::deref(c)); - wants_base_ptr(&asl::deref(&c)); - wants_base_ptr(&asl::deref(d)); -} - diff --git a/asl/tests/option_tests.cpp b/asl/tests/option_tests.cpp deleted file mode 100644 index c5461b1..0000000 --- a/asl/tests/option_tests.cpp +++ /dev/null @@ -1,330 +0,0 @@ -#include "asl/option.hpp" -#include "asl/tests/test_types.hpp" -#include "asl/testing/testing.hpp" - -class Base {}; -class Derived : public Base {}; - -struct NonZero -{ - int value; - - constexpr explicit NonZero(int x) : value(x) - { - ASL_ASSERT(x != 0); - } - - constexpr explicit NonZero(asl::niche_t) : value(0) {} - - constexpr bool operator==(asl::niche_t) const { return value == 0; } -}; -static_assert(asl::has_niche); -static_assert(!asl::has_niche); - -static_assert(sizeof(asl::option) >= sizeof(int)); -static_assert(sizeof(asl::option) == sizeof(NonZero)); - -static_assert(!asl::is_option); -static_assert(asl::is_option>); -static_assert(asl::is_option>); - -static_assert(asl::trivially_destructible>); -static_assert(!asl::trivially_destructible>); - -static_assert(asl::trivially_copy_constructible>); -static_assert(asl::trivially_copy_constructible>); -static_assert(asl::copy_constructible>); -static_assert(!asl::copy_constructible>); -static_assert(!asl::copy_constructible>); - -static_assert(asl::trivially_move_constructible>); -static_assert(asl::trivially_move_constructible>); -static_assert(asl::move_constructible>); -static_assert(asl::move_constructible>); -static_assert(!asl::move_constructible>); - -static_assert(asl::trivially_copy_assignable>); -static_assert(asl::trivially_copy_assignable>); -static_assert(asl::copy_assignable>); -static_assert(!asl::copy_assignable>); -static_assert(!asl::copy_assignable>); - -static_assert(asl::trivially_move_assignable>); -static_assert(asl::trivially_move_assignable>); -static_assert(asl::move_assignable>); -static_assert(asl::move_assignable>); -static_assert(!asl::move_assignable>); - -static_assert(asl::assignable_from&, asl::option>); -static_assert(!asl::assignable_from&, asl::option>); - -static_assert(asl::convertible_from, asl::option>); -static_assert(!asl::convertible_from, asl::option>); - -class ExplicitConversion { public: explicit ExplicitConversion(int) {} }; -class ImplicitConversion { public: ImplicitConversion(int) {} }; // NOLINT - -static_assert(!asl::convertible_from); -static_assert(asl::convertible_from); - -static_assert(!asl::convertible_from, int>); -static_assert(asl::convertible_from, int>); - -static_assert(!asl::convertible_from, asl::option>); -static_assert(asl::convertible_from, asl::option>); - -static_assert(asl::trivially_copy_constructible>); -static_assert(asl::trivially_copy_constructible>); -static_assert(asl::trivially_copy_constructible>); -static_assert(!asl::trivially_copy_constructible>); - -static_assert(asl::trivially_move_constructible>); -static_assert(asl::trivially_move_constructible>); -static_assert(asl::trivially_move_constructible>); -static_assert(!asl::trivially_move_constructible>); - -static_assert(asl::trivially_copy_assignable>); -static_assert(asl::trivially_copy_assignable>); -static_assert(asl::trivially_copy_assignable>); -static_assert(!asl::trivially_copy_assignable>); - -static_assert(asl::trivially_move_assignable>); -static_assert(asl::trivially_move_assignable>); -static_assert(asl::trivially_move_assignable>); -static_assert(!asl::trivially_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); -} - -ASL_TEST(convert_copy) -{ - asl::option opt8 = uint8_t{8}; - asl::option opt16 = opt8; - - ASL_TEST_ASSERT(opt16.has_value()); - ASL_TEST_EXPECT(opt16.value() == 8); - - opt8 = uint8_t{10}; - ASL_TEST_ASSERT(opt8.has_value()); - ASL_TEST_EXPECT(opt8.value() == 10); - - opt16 = asl::nullopt; - ASL_TEST_EXPECT(!opt16.has_value()); - - opt16 = opt8; - ASL_TEST_ASSERT(opt16.has_value()); - ASL_TEST_EXPECT(opt16.value() == 10); -} - -ASL_TEST(convert_move) -{ - asl::option opt8 = uint8_t{8}; - asl::option opt16 = ASL_MOVE(opt8); - - ASL_TEST_ASSERT(opt16.has_value()); - ASL_TEST_EXPECT(opt16.value() == 8); - - opt8 = ASL_MOVE(uint8_t{10}); - ASL_TEST_ASSERT(opt8.has_value()); - ASL_TEST_EXPECT(opt8.value() == 10); - - opt16 = asl::nullopt; - ASL_TEST_EXPECT(!opt16.has_value()); - - opt16 = ASL_MOVE(opt8); - ASL_TEST_ASSERT(opt16.has_value()); - ASL_TEST_EXPECT(opt16.value() == 10); -} - -ASL_TEST(value_or) -{ - asl::option a = asl::nullopt; - asl::option b = 2; - - ASL_TEST_EXPECT(a.value_or(5) == 5); - ASL_TEST_EXPECT(b.value_or(5) == 2); -} - -ASL_TEST(emplace) -{ - asl::option a = asl::nullopt; - - a.emplace(42); - ASL_TEST_ASSERT(a.has_value()); - ASL_TEST_EXPECT(a.value() == 42); -} - -ASL_TEST(emplace_destroys_previous) -{ - bool b1 = false; - bool b2 = false; - - { - asl::option a{&b1}; - ASL_TEST_EXPECT(!b1); - - a.emplace(&b2); - ASL_TEST_EXPECT(b1); - ASL_TEST_EXPECT(!b2); - } - - ASL_TEST_EXPECT(b2); -} - -ASL_TEST(and_then) -{ - asl::option a = 5; - asl::option b; - - auto fn = [](int x) -> asl::option { return static_cast(x) + 0.5F; }; - - auto a2 = a.and_then(fn); - static_assert(asl::same_as>); - ASL_TEST_ASSERT(a2.has_value()); - ASL_TEST_EXPECT(a2.value() == 5.5F); - - auto b2 = b.and_then(fn); - static_assert(asl::same_as>); - ASL_TEST_ASSERT(!b2.has_value()); -} - -ASL_TEST(transform) -{ - asl::option a = 5; - asl::option b; - - auto fn = [](int x) -> float { return static_cast(x) + 0.5F; }; - - auto a2 = a.transform(fn); - static_assert(asl::same_as>); - ASL_TEST_ASSERT(a2.has_value()); - ASL_TEST_EXPECT(a2.value() == 5.5F); - - auto b2 = b.transform