Restructure into umbrella modules (~55 -> 16 targets)
Headers move, CMake targets merge, C++ namespaces stay unchanged: - Core: Scope, Lazy, Counted, Flags, Hash, Bits, Uuid, TypeList, TypeMap, Variant - Functional: Pipeline, Either, Result, Retry - Containers: Ring, Pool, PriorityQueue, LRU, Trie, Graph, DisjointSet, Bitset, Interval - Math: +Matrix, Numeric, Random, Histogram - Text: Str, Format, Tokenizer, Diff, Encoding, Semver - Data: Json, Csv, Ini - Async: Coro, Concurrency, EventBus, Observable - Time: +Bench - Log: Log facade + Logging framework (facade now header-only, breaking the Stacktrace<->Log link cycle the merge would have created) - System: FileSystem + Process - Configuration: +Argparse - Unchanged: Stacktrace, Plugin, StateMachine, Testing, TestingMock, Detail Module system fixes: - OPTIONAL_DEPS resolution deferred to void_finalize_modules() so it no longer depends on the alphabetical discovery order of src/ subdirs (Testing -> Text would have been silently dropped). - Every header-only module now has a tracked module.cmake; previously the empty src/<Name> marker dirs were untracked, so a fresh clone would have silently skipped those modules. - VOID_HAS_LOGGING/CONCURRENCY/STR consumers renamed to LOG/ASYNC/TEXT. Tests move to tests/standalone/<Umbrella>/<Feature>.cpp (Result suite files prefixed: ResultBasic etc.). Test count verified identical (831) before and after. README/CLAUDE.md module tables updated. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
da2e93c405
commit
28b94883fd
156 files changed
+278
-220
No files matched your search
@@ -0,0 +1,138 @@
|
||||
#include <Void/Core/Bits.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// ── popcount ──────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test popcount_zero()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Bits::popcount(0u), 0);
|
||||
}
|
||||
|
||||
Void::Testing::Test popcount_all_ones_u8()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Bits::popcount(std::uint8_t{0xFF}), 8);
|
||||
}
|
||||
|
||||
Void::Testing::Test popcount_u32()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Bits::popcount(std::uint32_t{0x0F0F0F0F}), 16);
|
||||
}
|
||||
|
||||
// ── test/set/clear/toggle ────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test test_bit_set()
|
||||
{
|
||||
Void::Testing::expect(Void::Bits::test_bit(std::uint8_t{0b00000100u}, 2));
|
||||
}
|
||||
|
||||
Void::Testing::Test test_bit_clear()
|
||||
{
|
||||
Void::Testing::expect(!Void::Bits::test_bit(std::uint8_t{0b00000100u}, 0));
|
||||
}
|
||||
|
||||
Void::Testing::Test set_bit_works()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Bits::set_bit(std::uint8_t{0u}, 3),
|
||||
std::uint8_t{0b00001000u});
|
||||
}
|
||||
|
||||
Void::Testing::Test clear_bit_works()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Bits::clear_bit(std::uint8_t{0xFF}, 3),
|
||||
std::uint8_t{0b11110111u});
|
||||
}
|
||||
|
||||
Void::Testing::Test toggle_bit_works()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Bits::toggle_bit(std::uint8_t{0u}, 5),
|
||||
std::uint8_t{0b00100000u});
|
||||
}
|
||||
|
||||
// ── extract / deposit ─────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test extract_bits_works()
|
||||
{
|
||||
// bits 4-7 of 0b10110100 = 0b1011
|
||||
Void::Testing::expect_eq(
|
||||
Void::Bits::extract_bits(std::uint8_t{0b10110100u}, 4, 4),
|
||||
std::uint8_t{0b1011u});
|
||||
}
|
||||
|
||||
Void::Testing::Test deposit_bits_works()
|
||||
{
|
||||
// deposit 0b1010 into bits 4-7 of 0x00
|
||||
Void::Testing::expect_eq(
|
||||
Void::Bits::deposit_bits(std::uint8_t{0u}, std::uint8_t{0b1010u}, 4, 4),
|
||||
std::uint8_t{0b10100000u});
|
||||
}
|
||||
|
||||
// ── rotation ─────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test rotl_8()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Bits::rotl(std::uint8_t{0b10000001u}, 1),
|
||||
std::uint8_t{0b00000011u});
|
||||
}
|
||||
|
||||
Void::Testing::Test rotr_8()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Bits::rotr(std::uint8_t{0b10000001u}, 1),
|
||||
std::uint8_t{0b11000000u});
|
||||
}
|
||||
|
||||
// ── pow2 helpers ──────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test has_single_bit()
|
||||
{
|
||||
Void::Testing::expect(Void::Bits::has_single_bit(64u));
|
||||
Void::Testing::expect(!Void::Bits::has_single_bit(63u));
|
||||
}
|
||||
|
||||
Void::Testing::Test ceil_pow2_works()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Bits::ceil_pow2(5u), 8u);
|
||||
Void::Testing::expect_eq(Void::Bits::ceil_pow2(8u), 8u);
|
||||
}
|
||||
|
||||
Void::Testing::Test floor_pow2_works()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Bits::floor_pow2(5u), 4u);
|
||||
}
|
||||
|
||||
// ── align ────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test align_up_works()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Bits::align_up(13u, 8u), 16u);
|
||||
Void::Testing::expect_eq(Void::Bits::align_up(8u, 8u), 8u);
|
||||
}
|
||||
|
||||
Void::Testing::Test align_down_works()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Bits::align_down(13u, 8u), 8u);
|
||||
}
|
||||
|
||||
// ── masks ────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test low_mask_works()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Bits::low_mask<std::uint8_t>(4),
|
||||
std::uint8_t{0x0F});
|
||||
}
|
||||
|
||||
Void::Testing::Test range_mask_works()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Bits::range_mask<std::uint8_t>(2, 5),
|
||||
std::uint8_t{0b00111100u});
|
||||
}
|
||||
|
||||
// ── byteswap / endian ────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test byteswap_u32()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Bits::byteswap(std::uint32_t{0x12345678u}),
|
||||
std::uint32_t{0x78563412u});
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
#include <Void/Core/Counted.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
using namespace Void::Counted;
|
||||
|
||||
// ── InstanceCounter ───────────────────────────────────────────────────────────
|
||||
|
||||
struct Widget : InstanceCounter<Widget> {
|
||||
int value;
|
||||
explicit Widget(int v) : value{v} {}
|
||||
};
|
||||
|
||||
struct Gadget : InstanceCounter<Gadget> {};
|
||||
|
||||
Void::Testing::Test instance_counter_starts_at_zero()
|
||||
{
|
||||
// Run in isolation — Widget count may have been affected by other tests.
|
||||
// Check relative behavior instead.
|
||||
const std::size_t before = Widget::instance_count();
|
||||
{
|
||||
Widget w{1};
|
||||
Void::Testing::expect_eq(Widget::instance_count(), before + 1);
|
||||
}
|
||||
Void::Testing::expect_eq(Widget::instance_count(), before);
|
||||
}
|
||||
|
||||
Void::Testing::Test instance_counter_multiple_objects()
|
||||
{
|
||||
const std::size_t before = Widget::instance_count();
|
||||
{
|
||||
Widget a{1}, b{2}, c{3};
|
||||
Void::Testing::expect_eq(Widget::instance_count(), before + 3);
|
||||
}
|
||||
Void::Testing::expect_eq(Widget::instance_count(), before);
|
||||
}
|
||||
|
||||
Void::Testing::Test instance_counter_copy_increments()
|
||||
{
|
||||
const std::size_t before = Widget::instance_count();
|
||||
{
|
||||
Widget a{1};
|
||||
Widget b = a; // copy
|
||||
Void::Testing::expect_eq(Widget::instance_count(), before + 2);
|
||||
}
|
||||
Void::Testing::expect_eq(Widget::instance_count(), before);
|
||||
}
|
||||
|
||||
Void::Testing::Test instance_counter_separate_per_type()
|
||||
{
|
||||
const std::size_t widgets_before = Widget::instance_count();
|
||||
const std::size_t gadgets_before = Gadget::instance_count();
|
||||
{
|
||||
Widget w{42};
|
||||
Gadget g;
|
||||
Void::Testing::expect_eq(Widget::instance_count(), widgets_before + 1);
|
||||
Void::Testing::expect_eq(Gadget::instance_count(), gadgets_before + 1);
|
||||
}
|
||||
Void::Testing::expect_eq(Gadget::instance_count(), gadgets_before);
|
||||
}
|
||||
|
||||
// ── AtomicCounter ─────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test atomic_counter_initial_value()
|
||||
{
|
||||
AtomicCounter c;
|
||||
Void::Testing::expect_eq(c.get(), std::size_t{0});
|
||||
AtomicCounter c2{10};
|
||||
Void::Testing::expect_eq(c2.get(), std::size_t{10});
|
||||
}
|
||||
|
||||
Void::Testing::Test atomic_counter_increment()
|
||||
{
|
||||
AtomicCounter c;
|
||||
c.increment();
|
||||
c.increment(5);
|
||||
Void::Testing::expect_eq(c.get(), std::size_t{6});
|
||||
}
|
||||
|
||||
Void::Testing::Test atomic_counter_decrement()
|
||||
{
|
||||
AtomicCounter c{10};
|
||||
c.decrement(3);
|
||||
Void::Testing::expect_eq(c.get(), std::size_t{7});
|
||||
}
|
||||
|
||||
Void::Testing::Test atomic_counter_reset()
|
||||
{
|
||||
AtomicCounter c{100};
|
||||
c.reset();
|
||||
Void::Testing::expect_eq(c.get(), std::size_t{0});
|
||||
c.reset(42);
|
||||
Void::Testing::expect_eq(c.get(), std::size_t{42});
|
||||
}
|
||||
|
||||
Void::Testing::Test atomic_counter_prefix_operators()
|
||||
{
|
||||
AtomicCounter c{5};
|
||||
++c;
|
||||
Void::Testing::expect_eq(c.get(), std::size_t{6});
|
||||
--c;
|
||||
Void::Testing::expect_eq(c.get(), std::size_t{5});
|
||||
}
|
||||
|
||||
Void::Testing::Test atomic_counter_postfix_returns_old()
|
||||
{
|
||||
AtomicCounter c{3};
|
||||
const auto old_inc = c++;
|
||||
Void::Testing::expect_eq(old_inc, std::size_t{3});
|
||||
Void::Testing::expect_eq(c.get(), std::size_t{4});
|
||||
}
|
||||
|
||||
Void::Testing::Test atomic_counter_thread_safe_increment()
|
||||
{
|
||||
AtomicCounter c;
|
||||
constexpr int threads = 4;
|
||||
constexpr int per_thread = 1000;
|
||||
|
||||
std::vector<std::thread> ts;
|
||||
ts.reserve(threads);
|
||||
for (int i = 0; i < threads; ++i)
|
||||
ts.emplace_back([&] { for (int j = 0; j < per_thread; ++j) c.increment(); });
|
||||
for (auto& t : ts) t.join();
|
||||
|
||||
Void::Testing::expect_eq(c.get(), std::size_t{threads * per_thread});
|
||||
}
|
||||
|
||||
// ── SeqId ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test seq_id_monotonic()
|
||||
{
|
||||
struct MyTag {};
|
||||
SeqId<MyTag> a, b, c;
|
||||
Void::Testing::expect(a.id() < b.id());
|
||||
Void::Testing::expect(b.id() < c.id());
|
||||
}
|
||||
|
||||
Void::Testing::Test seq_id_unique_per_tag()
|
||||
{
|
||||
struct TagA {};
|
||||
struct TagB {};
|
||||
SeqId<TagA> a1, a2;
|
||||
SeqId<TagB> b1;
|
||||
// TagA and TagB sequences are independent
|
||||
Void::Testing::expect(a1.id() != b1.id() || a2.id() != b1.id()); // at least one differs
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
#include <Void/Core/Flags.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
using namespace Void::Flags;
|
||||
|
||||
enum class Perm : unsigned { Read = 1, Write = 2, Exec = 4 };
|
||||
|
||||
// ── construction ──────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test flags_default_is_empty()
|
||||
{
|
||||
const Flags<Perm> f;
|
||||
Void::Testing::expect(f.none());
|
||||
Void::Testing::expect(!f.any());
|
||||
}
|
||||
|
||||
Void::Testing::Test flags_single_bit()
|
||||
{
|
||||
const Flags<Perm> f{Perm::Read};
|
||||
Void::Testing::expect(f.test(Perm::Read));
|
||||
Void::Testing::expect(!f.test(Perm::Write));
|
||||
}
|
||||
|
||||
Void::Testing::Test flags_initializer_list()
|
||||
{
|
||||
const Flags<Perm> f{Perm::Read, Perm::Write};
|
||||
Void::Testing::expect(f.test(Perm::Read));
|
||||
Void::Testing::expect(f.test(Perm::Write));
|
||||
Void::Testing::expect(!f.test(Perm::Exec));
|
||||
}
|
||||
|
||||
Void::Testing::Test flags_make_flags()
|
||||
{
|
||||
const auto f = make_flags({Perm::Read, Perm::Exec});
|
||||
Void::Testing::expect(f.test(Perm::Read));
|
||||
Void::Testing::expect(!f.test(Perm::Write));
|
||||
Void::Testing::expect(f.test(Perm::Exec));
|
||||
}
|
||||
|
||||
// ── query ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test flags_all()
|
||||
{
|
||||
const Flags<Perm> f{Perm::Read, Perm::Write};
|
||||
Void::Testing::expect(f.all(Flags<Perm>{Perm::Read}));
|
||||
Void::Testing::expect(f.all(Flags<Perm>{Perm::Read, Perm::Write}));
|
||||
Void::Testing::expect(!f.all(Flags<Perm>{Perm::Read, Perm::Write, Perm::Exec}));
|
||||
}
|
||||
|
||||
Void::Testing::Test flags_any_of()
|
||||
{
|
||||
const Flags<Perm> f{Perm::Read};
|
||||
Void::Testing::expect(f.any_of(Flags<Perm>{Perm::Read, Perm::Exec}));
|
||||
Void::Testing::expect(!f.any_of(Flags<Perm>{Perm::Write, Perm::Exec}));
|
||||
}
|
||||
|
||||
// ── mutation ──────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test flags_set_unset()
|
||||
{
|
||||
Flags<Perm> f;
|
||||
f.set(Perm::Read);
|
||||
Void::Testing::expect(f.test(Perm::Read));
|
||||
f.unset(Perm::Read);
|
||||
Void::Testing::expect(!f.test(Perm::Read));
|
||||
}
|
||||
|
||||
Void::Testing::Test flags_toggle()
|
||||
{
|
||||
Flags<Perm> f{Perm::Write};
|
||||
f.toggle(Perm::Write);
|
||||
Void::Testing::expect(!f.test(Perm::Write));
|
||||
f.toggle(Perm::Write);
|
||||
Void::Testing::expect(f.test(Perm::Write));
|
||||
}
|
||||
|
||||
Void::Testing::Test flags_clear()
|
||||
{
|
||||
Flags<Perm> f{Perm::Read, Perm::Write, Perm::Exec};
|
||||
f.clear();
|
||||
Void::Testing::expect(f.none());
|
||||
}
|
||||
|
||||
// ── operators ─────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test flags_or_operator()
|
||||
{
|
||||
const auto f = Flags<Perm>{Perm::Read} | Perm::Write;
|
||||
Void::Testing::expect(f.test(Perm::Read));
|
||||
Void::Testing::expect(f.test(Perm::Write));
|
||||
}
|
||||
|
||||
Void::Testing::Test flags_and_operator()
|
||||
{
|
||||
const Flags<Perm> a{Perm::Read, Perm::Write};
|
||||
const Flags<Perm> b{Perm::Write, Perm::Exec};
|
||||
const auto c = a & b;
|
||||
Void::Testing::expect(!c.test(Perm::Read));
|
||||
Void::Testing::expect(c.test(Perm::Write));
|
||||
Void::Testing::expect(!c.test(Perm::Exec));
|
||||
}
|
||||
|
||||
Void::Testing::Test flags_xor_operator()
|
||||
{
|
||||
const Flags<Perm> a{Perm::Read, Perm::Write};
|
||||
const Flags<Perm> b{Perm::Write, Perm::Exec};
|
||||
const auto c = a ^ b;
|
||||
Void::Testing::expect(c.test(Perm::Read));
|
||||
Void::Testing::expect(!c.test(Perm::Write));
|
||||
Void::Testing::expect(c.test(Perm::Exec));
|
||||
}
|
||||
|
||||
Void::Testing::Test flags_or_two_enums()
|
||||
{
|
||||
const auto f = Perm::Read | Perm::Exec;
|
||||
Void::Testing::expect(f.test(Perm::Read));
|
||||
Void::Testing::expect(!f.test(Perm::Write));
|
||||
Void::Testing::expect(f.test(Perm::Exec));
|
||||
}
|
||||
|
||||
Void::Testing::Test flags_equality()
|
||||
{
|
||||
const Flags<Perm> a{Perm::Read, Perm::Write};
|
||||
const Flags<Perm> b{Perm::Read, Perm::Write};
|
||||
const Flags<Perm> c{Perm::Read};
|
||||
Void::Testing::expect(a == b);
|
||||
Void::Testing::expect(!(a == c));
|
||||
}
|
||||
|
||||
Void::Testing::Test flags_bool_conversion()
|
||||
{
|
||||
const Flags<Perm> empty;
|
||||
const Flags<Perm> nonempty{Perm::Read};
|
||||
Void::Testing::expect(!static_cast<bool>(empty));
|
||||
Void::Testing::expect(static_cast<bool>(nonempty));
|
||||
}
|
||||
|
||||
Void::Testing::Test flags_raw_value()
|
||||
{
|
||||
const Flags<Perm> f{Perm::Read, Perm::Exec};
|
||||
Void::Testing::expect_eq(f.raw(), unsigned{5});
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
#include <Void/Core/Hash.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace Void::Hash::Literals;
|
||||
|
||||
// ── FNV-1a 32 ────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test fnv1a32_empty_string()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Hash::fnv1a32(""), 2166136261u);
|
||||
}
|
||||
|
||||
Void::Testing::Test fnv1a32_hello_world()
|
||||
{
|
||||
const auto a = Void::Hash::fnv1a32("hello");
|
||||
const auto b = Void::Hash::fnv1a32("world");
|
||||
Void::Testing::expect(a != b);
|
||||
Void::Testing::expect(a != 0u);
|
||||
}
|
||||
|
||||
Void::Testing::Test fnv1a32_deterministic()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Hash::fnv1a32("test"),
|
||||
Void::Hash::fnv1a32("test"));
|
||||
}
|
||||
|
||||
Void::Testing::Test fnv1a32_different_strings_differ()
|
||||
{
|
||||
Void::Testing::expect(Void::Hash::fnv1a32("abc") !=
|
||||
Void::Hash::fnv1a32("abd"));
|
||||
}
|
||||
|
||||
// ── FNV-1a 64 ────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test fnv1a64_empty_basis()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Hash::fnv1a64(""),
|
||||
14695981039346656037ull);
|
||||
}
|
||||
|
||||
Void::Testing::Test fnv1a64_hello_is_stable()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Hash::fnv1a64("hello"),
|
||||
Void::Hash::fnv1a64("hello"));
|
||||
}
|
||||
|
||||
Void::Testing::Test fnv1a64_wider_than_32()
|
||||
{
|
||||
// 64-bit should differ from 32-bit value for same input
|
||||
Void::Testing::expect(Void::Hash::fnv1a64("test") !=
|
||||
static_cast<std::uint64_t>(Void::Hash::fnv1a32("test")));
|
||||
}
|
||||
|
||||
// ── CRC-32 ───────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test crc32_known_value()
|
||||
{
|
||||
// CRC-32 of "123456789" is a well-known check value: 0xCBF43926
|
||||
Void::Testing::expect_eq(Void::Hash::crc32("123456789"), std::uint32_t{0xCBF43926u});
|
||||
}
|
||||
|
||||
Void::Testing::Test crc32_empty_is_zero()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Hash::crc32(""), std::uint32_t{0u});
|
||||
}
|
||||
|
||||
Void::Testing::Test crc32_deterministic()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Hash::crc32("void"), Void::Hash::crc32("void"));
|
||||
}
|
||||
|
||||
// ── DJB2 ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test djb2_non_zero_for_nonempty()
|
||||
{
|
||||
Void::Testing::expect(Void::Hash::djb2("hello") != 0u);
|
||||
}
|
||||
|
||||
Void::Testing::Test djb2_differs_per_string()
|
||||
{
|
||||
Void::Testing::expect(Void::Hash::djb2("foo") != Void::Hash::djb2("bar"));
|
||||
}
|
||||
|
||||
// ── MurmurHash3 ──────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test murmur3_32_deterministic()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Hash::murmur3_32("hello", 42u),
|
||||
Void::Hash::murmur3_32("hello", 42u));
|
||||
}
|
||||
|
||||
Void::Testing::Test murmur3_32_seed_affects_output()
|
||||
{
|
||||
Void::Testing::expect(Void::Hash::murmur3_32("hello", 0u) !=
|
||||
Void::Hash::murmur3_32("hello", 1u));
|
||||
}
|
||||
|
||||
Void::Testing::Test murmur3_32_empty_with_zero_seed()
|
||||
{
|
||||
// MurmurHash3("", 0) = 0
|
||||
Void::Testing::expect_eq(Void::Hash::murmur3_32("", 0u), std::uint32_t{0u});
|
||||
}
|
||||
|
||||
// ── UDL literals ─────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test udl_fnv32_comptime()
|
||||
{
|
||||
constexpr auto h = "hello"_fnv32;
|
||||
static_assert(h != 0u);
|
||||
Void::Testing::expect_eq(h, Void::Hash::fnv1a32("hello"));
|
||||
}
|
||||
|
||||
Void::Testing::Test udl_fnv64_comptime()
|
||||
{
|
||||
constexpr auto h = "hello"_fnv64;
|
||||
static_assert(h != 0u);
|
||||
Void::Testing::expect_eq(h, Void::Hash::fnv1a64("hello"));
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
#include <Void/Core/Lazy.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace Void::Lazy;
|
||||
|
||||
// ── Lazy<T> ───────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test lazy_not_evaluated_on_construction()
|
||||
{
|
||||
int calls = 0;
|
||||
auto lz = make_lazy([&] { ++calls; return 42; });
|
||||
Void::Testing::expect(!lz.evaluated());
|
||||
Void::Testing::expect_eq(calls, 0);
|
||||
}
|
||||
|
||||
Void::Testing::Test lazy_evaluates_on_first_get()
|
||||
{
|
||||
int calls = 0;
|
||||
auto lz = make_lazy([&] { ++calls; return 42; });
|
||||
Void::Testing::expect_eq(*lz, 42);
|
||||
Void::Testing::expect_eq(calls, 1);
|
||||
Void::Testing::expect(lz.evaluated());
|
||||
}
|
||||
|
||||
Void::Testing::Test lazy_evaluates_only_once()
|
||||
{
|
||||
int calls = 0;
|
||||
auto lz = make_lazy([&] { ++calls; return 7; });
|
||||
(void)*lz;
|
||||
(void)*lz;
|
||||
(void)*lz;
|
||||
Void::Testing::expect_eq(calls, 1);
|
||||
}
|
||||
|
||||
Void::Testing::Test lazy_arrow_operator()
|
||||
{
|
||||
auto lz = make_lazy([] { return std::string{"hello"}; });
|
||||
Void::Testing::expect_eq(lz->size(), std::size_t{5});
|
||||
}
|
||||
|
||||
Void::Testing::Test lazy_reset_clears_value()
|
||||
{
|
||||
int calls = 0;
|
||||
auto lz = make_lazy([&] { ++calls; return 1; });
|
||||
(void)*lz;
|
||||
lz.reset();
|
||||
Void::Testing::expect(!lz.evaluated());
|
||||
(void)*lz;
|
||||
Void::Testing::expect_eq(calls, 2);
|
||||
}
|
||||
|
||||
Void::Testing::Test lazy_const_access()
|
||||
{
|
||||
const auto lz = make_lazy([] { return 99; });
|
||||
Void::Testing::expect_eq(*lz, 99);
|
||||
Void::Testing::expect(lz.evaluated());
|
||||
}
|
||||
|
||||
Void::Testing::Test lazy_string_value()
|
||||
{
|
||||
auto lz = make_lazy([] { return std::string{"lazy value"}; });
|
||||
Void::Testing::expect_eq(lz.get(), std::string{"lazy value"});
|
||||
}
|
||||
|
||||
// ── LazySync<T> ───────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test lazy_sync_evaluates_once()
|
||||
{
|
||||
int calls = 0;
|
||||
auto lz = make_lazy_sync([&] { ++calls; return 55; });
|
||||
Void::Testing::expect_eq(*lz, 55);
|
||||
Void::Testing::expect_eq(*lz, 55);
|
||||
Void::Testing::expect_eq(calls, 1);
|
||||
}
|
||||
|
||||
Void::Testing::Test lazy_sync_arrow_operator()
|
||||
{
|
||||
auto lz = make_lazy_sync([] { return std::string{"synced"}; });
|
||||
Void::Testing::expect_eq(lz->length(), std::size_t{6});
|
||||
}
|
||||
|
||||
Void::Testing::Test lazy_sync_const_access()
|
||||
{
|
||||
const auto lz = make_lazy_sync([] { return 123; });
|
||||
Void::Testing::expect_eq(*lz, 123);
|
||||
Void::Testing::expect(lz.evaluated());
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
#include <Void/Core/Scope.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
using namespace Void::Scope;
|
||||
|
||||
// ── on_exit ───────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test on_exit_runs_on_normal_exit()
|
||||
{
|
||||
bool ran = false;
|
||||
{
|
||||
auto guard = on_exit([&] { ran = true; });
|
||||
}
|
||||
Void::Testing::expect(ran);
|
||||
}
|
||||
|
||||
Void::Testing::Test on_exit_runs_on_exception()
|
||||
{
|
||||
bool ran = false;
|
||||
try {
|
||||
auto guard = on_exit([&] { ran = true; });
|
||||
throw std::runtime_error{"test"};
|
||||
} catch (...) {}
|
||||
Void::Testing::expect(ran);
|
||||
}
|
||||
|
||||
Void::Testing::Test on_exit_release_prevents_run()
|
||||
{
|
||||
bool ran = false;
|
||||
{
|
||||
auto guard = on_exit([&] { ran = true; });
|
||||
guard.release();
|
||||
}
|
||||
Void::Testing::expect(!ran);
|
||||
}
|
||||
|
||||
Void::Testing::Test on_exit_dismiss_prevents_run()
|
||||
{
|
||||
bool ran = false;
|
||||
{
|
||||
auto guard = on_exit([&] { ran = true; });
|
||||
guard.dismiss();
|
||||
}
|
||||
Void::Testing::expect(!ran);
|
||||
}
|
||||
|
||||
Void::Testing::Test on_exit_active_reflects_state()
|
||||
{
|
||||
auto guard = on_exit([] {});
|
||||
Void::Testing::expect(guard.active());
|
||||
guard.dismiss();
|
||||
Void::Testing::expect(!guard.active());
|
||||
}
|
||||
|
||||
Void::Testing::Test on_exit_move_transfers_ownership()
|
||||
{
|
||||
int called = 0;
|
||||
{
|
||||
auto g1 = on_exit([&] { ++called; });
|
||||
auto g2 = std::move(g1);
|
||||
Void::Testing::expect(!g1.active());
|
||||
Void::Testing::expect(g2.active());
|
||||
}
|
||||
Void::Testing::expect_eq(called, 1);
|
||||
}
|
||||
|
||||
Void::Testing::Test on_exit_lifo_order()
|
||||
{
|
||||
std::string order;
|
||||
{
|
||||
auto a = on_exit([&] { order += "A"; });
|
||||
auto b = on_exit([&] { order += "B"; });
|
||||
auto c = on_exit([&] { order += "C"; });
|
||||
}
|
||||
Void::Testing::expect_eq(order, std::string{"CBA"});
|
||||
}
|
||||
|
||||
Void::Testing::Test on_exit_multiple_guards_lifo()
|
||||
{
|
||||
int order = 0, a = 0, b = 0;
|
||||
{
|
||||
auto ga = on_exit([&] { a = ++order; });
|
||||
auto gb = on_exit([&] { b = ++order; });
|
||||
}
|
||||
Void::Testing::expect(b < a);
|
||||
}
|
||||
|
||||
Void::Testing::Test on_exit_resource_cleanup()
|
||||
{
|
||||
bool released = false;
|
||||
{
|
||||
int handle = 42;
|
||||
auto cleanup = on_exit([&] { if (handle) released = true; });
|
||||
(void)handle;
|
||||
}
|
||||
Void::Testing::expect(released);
|
||||
}
|
||||
|
||||
Void::Testing::Test on_exit_conditional_commit()
|
||||
{
|
||||
int value = 10;
|
||||
{
|
||||
auto rollback = on_exit([&] { value = 0; });
|
||||
rollback.dismiss();
|
||||
}
|
||||
Void::Testing::expect_eq(value, 10);
|
||||
}
|
||||
|
||||
// ── on_success ────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test on_success_runs_on_normal_exit()
|
||||
{
|
||||
bool ran = false;
|
||||
{
|
||||
auto guard = on_success([&] { ran = true; });
|
||||
}
|
||||
Void::Testing::expect(ran);
|
||||
}
|
||||
|
||||
Void::Testing::Test on_success_does_not_run_on_exception()
|
||||
{
|
||||
bool ran = false;
|
||||
try {
|
||||
auto guard = on_success([&] { ran = true; });
|
||||
throw std::runtime_error{"test"};
|
||||
} catch (...) {}
|
||||
Void::Testing::expect(!ran);
|
||||
}
|
||||
|
||||
Void::Testing::Test on_success_release_prevents_run()
|
||||
{
|
||||
bool ran = false;
|
||||
{
|
||||
auto guard = on_success([&] { ran = true; });
|
||||
guard.release();
|
||||
}
|
||||
Void::Testing::expect(!ran);
|
||||
}
|
||||
|
||||
// ── on_fail ───────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test on_fail_does_not_run_on_normal_exit()
|
||||
{
|
||||
bool ran = false;
|
||||
{
|
||||
auto guard = on_fail([&] { ran = true; });
|
||||
}
|
||||
Void::Testing::expect(!ran);
|
||||
}
|
||||
|
||||
Void::Testing::Test on_fail_runs_on_exception()
|
||||
{
|
||||
bool ran = false;
|
||||
try {
|
||||
auto guard = on_fail([&] { ran = true; });
|
||||
throw std::runtime_error{"test"};
|
||||
} catch (...) {}
|
||||
Void::Testing::expect(ran);
|
||||
}
|
||||
|
||||
Void::Testing::Test on_fail_release_prevents_run()
|
||||
{
|
||||
bool ran = false;
|
||||
try {
|
||||
auto guard = on_fail([&] { ran = true; });
|
||||
guard.release();
|
||||
throw std::runtime_error{"test"};
|
||||
} catch (...) {}
|
||||
Void::Testing::expect(!ran);
|
||||
}
|
||||
|
||||
// ── scope_exit / scope_success / scope_failure aliases ───────────────────────
|
||||
|
||||
Void::Testing::Test scope_exit_alias_fires()
|
||||
{
|
||||
int called = 0;
|
||||
{
|
||||
auto g = scope_exit([&] { ++called; });
|
||||
}
|
||||
Void::Testing::expect_eq(called, 1);
|
||||
}
|
||||
|
||||
Void::Testing::Test scope_success_alias_fires_on_normal()
|
||||
{
|
||||
int called = 0;
|
||||
{
|
||||
auto g = scope_success([&] { ++called; });
|
||||
}
|
||||
Void::Testing::expect_eq(called, 1);
|
||||
}
|
||||
|
||||
Void::Testing::Test scope_failure_alias_fires_on_exception()
|
||||
{
|
||||
int called = 0;
|
||||
try {
|
||||
auto g = scope_failure([&] { ++called; });
|
||||
throw std::runtime_error{"x"};
|
||||
} catch (...) {}
|
||||
Void::Testing::expect_eq(called, 1);
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
#include <Void/Core/TypeList.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
using namespace Void::TypeList;
|
||||
|
||||
using List3 = TypeList<int, float, double>;
|
||||
using Empty = TypeList<>;
|
||||
|
||||
// ── size_of ───────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test size_of_empty()
|
||||
{
|
||||
static_assert(size_of<Empty> == 0);
|
||||
Void::Testing::expect_eq(size_of<Empty>, std::size_t{0});
|
||||
}
|
||||
|
||||
Void::Testing::Test size_of_nonempty()
|
||||
{
|
||||
static_assert(size_of<List3> == 3);
|
||||
Void::Testing::expect_eq(size_of<List3>, std::size_t{3});
|
||||
}
|
||||
|
||||
// ── at ────────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test at_first()
|
||||
{
|
||||
static_assert(std::is_same_v<at<0, List3>, int>);
|
||||
Void::Testing::expect(true);
|
||||
}
|
||||
|
||||
Void::Testing::Test at_last()
|
||||
{
|
||||
static_assert(std::is_same_v<at<2, List3>, double>);
|
||||
Void::Testing::expect(true);
|
||||
}
|
||||
|
||||
// ── front / back ─────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test front_of_list()
|
||||
{
|
||||
static_assert(std::is_same_v<front<List3>, int>);
|
||||
Void::Testing::expect(true);
|
||||
}
|
||||
|
||||
Void::Testing::Test back_of_list()
|
||||
{
|
||||
static_assert(std::is_same_v<back<List3>, double>);
|
||||
Void::Testing::expect(true);
|
||||
}
|
||||
|
||||
// ── contains ─────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test contains_present()
|
||||
{
|
||||
static_assert(contains<float, List3>);
|
||||
Void::Testing::expect(true);
|
||||
}
|
||||
|
||||
Void::Testing::Test contains_absent()
|
||||
{
|
||||
static_assert(!contains<char, List3>);
|
||||
Void::Testing::expect(true);
|
||||
}
|
||||
|
||||
// ── index_of ─────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test index_of_first()
|
||||
{
|
||||
static_assert(index_of<int, List3> == 0);
|
||||
Void::Testing::expect_eq(index_of<int, List3>, std::size_t{0});
|
||||
}
|
||||
|
||||
Void::Testing::Test index_of_last()
|
||||
{
|
||||
static_assert(index_of<double, List3> == 2);
|
||||
Void::Testing::expect_eq(index_of<double, List3>, std::size_t{2});
|
||||
}
|
||||
|
||||
// ── push_front / push_back ───────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test push_front_adds_at_head()
|
||||
{
|
||||
using L = push_front<char, List3>;
|
||||
static_assert(std::is_same_v<front<L>, char>);
|
||||
static_assert(size_of<L> == 4);
|
||||
Void::Testing::expect(true);
|
||||
}
|
||||
|
||||
Void::Testing::Test push_back_adds_at_tail()
|
||||
{
|
||||
using L = push_back<char, List3>;
|
||||
static_assert(std::is_same_v<back<L>, char>);
|
||||
static_assert(size_of<L> == 4);
|
||||
Void::Testing::expect(true);
|
||||
}
|
||||
|
||||
// ── pop_front ─────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test pop_front_removes_head()
|
||||
{
|
||||
using L = pop_front<List3>;
|
||||
static_assert(std::is_same_v<front<L>, float>);
|
||||
static_assert(size_of<L> == 2);
|
||||
Void::Testing::expect(true);
|
||||
}
|
||||
|
||||
// ── concat ───────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test concat_two_lists()
|
||||
{
|
||||
using A = TypeList<int, float>;
|
||||
using B = TypeList<double, char>;
|
||||
using C = concat<A, B>;
|
||||
static_assert(size_of<C> == 4);
|
||||
static_assert(std::is_same_v<at<2, C>, double>);
|
||||
Void::Testing::expect(true);
|
||||
}
|
||||
|
||||
// ── filter ───────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test filter_keeps_matching()
|
||||
{
|
||||
using L = filter<std::is_integral, TypeList<int, float, char, double>>;
|
||||
static_assert(size_of<L> == 2);
|
||||
static_assert(std::is_same_v<at<0, L>, int>);
|
||||
static_assert(std::is_same_v<at<1, L>, char>);
|
||||
Void::Testing::expect(true);
|
||||
}
|
||||
|
||||
// ── transform ────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test transform_applies_to_all()
|
||||
{
|
||||
using L = transform<std::add_pointer, TypeList<int, float>>;
|
||||
static_assert(std::is_same_v<at<0, L>, int*>);
|
||||
static_assert(std::is_same_v<at<1, L>, float*>);
|
||||
Void::Testing::expect(true);
|
||||
}
|
||||
|
||||
// ── reverse ──────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test reverse_flips_order()
|
||||
{
|
||||
using R = reverse<List3>;
|
||||
static_assert(std::is_same_v<at<0, R>, double>);
|
||||
static_assert(std::is_same_v<at<2, R>, int>);
|
||||
Void::Testing::expect(true);
|
||||
}
|
||||
|
||||
// ── unique ───────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test unique_removes_duplicates()
|
||||
{
|
||||
using L = TypeList<int, float, int, double, float>;
|
||||
using U = unique<L>;
|
||||
static_assert(size_of<U> == 3);
|
||||
static_assert(std::is_same_v<at<0, U>, int>);
|
||||
Void::Testing::expect(true);
|
||||
}
|
||||
|
||||
// ── for_each ─────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test for_each_visits_all_types()
|
||||
{
|
||||
std::size_t count = 0;
|
||||
for_each<TypeList<int, float, double>>(
|
||||
[&]<typename T>() { ++count; });
|
||||
Void::Testing::expect_eq(count, std::size_t{3});
|
||||
}
|
||||
|
||||
// ── all_of / any_of / none_of ────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test all_of_true()
|
||||
{
|
||||
static_assert(all_of<std::is_integral, TypeList<int, char, long>>);
|
||||
Void::Testing::expect(true);
|
||||
}
|
||||
|
||||
Void::Testing::Test all_of_false()
|
||||
{
|
||||
static_assert(!all_of<std::is_integral, TypeList<int, float>>);
|
||||
Void::Testing::expect(true);
|
||||
}
|
||||
|
||||
Void::Testing::Test any_of_true()
|
||||
{
|
||||
static_assert(any_of<std::is_floating_point, TypeList<int, float>>);
|
||||
Void::Testing::expect(true);
|
||||
}
|
||||
|
||||
Void::Testing::Test none_of_true()
|
||||
{
|
||||
static_assert(none_of<std::is_pointer, TypeList<int, float>>);
|
||||
Void::Testing::expect(true);
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
#include <Void/Core/TypeMap.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace Void::TypeMap;
|
||||
|
||||
Void::Testing::Test typemap_put_and_get()
|
||||
{
|
||||
TypeMap m;
|
||||
m.put<int>(42);
|
||||
const auto v = m.get<int>();
|
||||
Void::Testing::expect(v.has_value());
|
||||
Void::Testing::expect_eq(*v, 42);
|
||||
}
|
||||
|
||||
Void::Testing::Test typemap_get_absent_returns_nullopt()
|
||||
{
|
||||
TypeMap m;
|
||||
Void::Testing::expect(!m.get<int>().has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test typemap_multiple_types()
|
||||
{
|
||||
TypeMap m;
|
||||
m.put<int>(1);
|
||||
m.put<double>(3.14);
|
||||
m.put<std::string>(std::string{"hello"});
|
||||
Void::Testing::expect_eq(*m.get<int>(), 1);
|
||||
Void::Testing::expect(*m.get<double>() > 3.1 && *m.get<double>() < 3.2);
|
||||
Void::Testing::expect_eq(*m.get<std::string>(), std::string{"hello"});
|
||||
}
|
||||
|
||||
Void::Testing::Test typemap_put_overwrites()
|
||||
{
|
||||
TypeMap m;
|
||||
m.put<int>(10);
|
||||
m.put<int>(20);
|
||||
Void::Testing::expect_eq(*m.get<int>(), 20);
|
||||
Void::Testing::expect_eq(m.size(), std::size_t{1});
|
||||
}
|
||||
|
||||
Void::Testing::Test typemap_contains()
|
||||
{
|
||||
TypeMap m;
|
||||
m.put<int>(1);
|
||||
Void::Testing::expect(m.contains<int>());
|
||||
Void::Testing::expect(!m.contains<double>());
|
||||
}
|
||||
|
||||
Void::Testing::Test typemap_erase()
|
||||
{
|
||||
TypeMap m;
|
||||
m.put<int>(1);
|
||||
const bool erased = m.erase<int>();
|
||||
Void::Testing::expect(erased);
|
||||
Void::Testing::expect(!m.contains<int>());
|
||||
Void::Testing::expect(!m.erase<int>()); // second erase returns false
|
||||
}
|
||||
|
||||
Void::Testing::Test typemap_get_or_throw_absent()
|
||||
{
|
||||
TypeMap m;
|
||||
bool threw = false;
|
||||
try { [[maybe_unused]] auto v = m.get_or_throw<int>(); } catch (...) { threw = true; }
|
||||
Void::Testing::expect(threw);
|
||||
}
|
||||
|
||||
Void::Testing::Test typemap_get_or_default()
|
||||
{
|
||||
TypeMap m;
|
||||
Void::Testing::expect_eq(m.get_or<int>(99), 99);
|
||||
m.put<int>(42);
|
||||
Void::Testing::expect_eq(m.get_or<int>(99), 42);
|
||||
}
|
||||
|
||||
Void::Testing::Test typemap_get_or_insert()
|
||||
{
|
||||
TypeMap m;
|
||||
int& r1 = m.get_or_insert<int>(100);
|
||||
Void::Testing::expect_eq(r1, 100);
|
||||
int& r2 = m.get_or_insert<int>(999); // should not overwrite
|
||||
Void::Testing::expect_eq(r2, 100);
|
||||
}
|
||||
|
||||
Void::Testing::Test typemap_size_and_empty()
|
||||
{
|
||||
TypeMap m;
|
||||
Void::Testing::expect(m.empty());
|
||||
Void::Testing::expect_eq(m.size(), std::size_t{0});
|
||||
m.put<int>(1);
|
||||
m.put<double>(2.0);
|
||||
Void::Testing::expect_eq(m.size(), std::size_t{2});
|
||||
Void::Testing::expect(!m.empty());
|
||||
}
|
||||
|
||||
Void::Testing::Test typemap_clear()
|
||||
{
|
||||
TypeMap m;
|
||||
m.put<int>(1);
|
||||
m.put<std::string>(std::string{"x"});
|
||||
m.clear();
|
||||
Void::Testing::expect(m.empty());
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
#include <Void/Core/Uuid.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
// ── v4 ───────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test v4_not_nil()
|
||||
{
|
||||
Void::Testing::expect(!Void::Uuid::v4().is_nil());
|
||||
}
|
||||
|
||||
Void::Testing::Test v4_version_nibble()
|
||||
{
|
||||
const auto u = Void::Uuid::v4();
|
||||
Void::Testing::expect_eq(u.bytes[6] >> 4, std::uint8_t{4});
|
||||
}
|
||||
|
||||
Void::Testing::Test v4_variant_bits()
|
||||
{
|
||||
const auto u = Void::Uuid::v4();
|
||||
// top two bits of byte 8 must be 10
|
||||
Void::Testing::expect_eq(u.bytes[8] >> 6, std::uint8_t{2});
|
||||
}
|
||||
|
||||
Void::Testing::Test v4_unique()
|
||||
{
|
||||
Void::Testing::expect(Void::Uuid::v4() != Void::Uuid::v4());
|
||||
}
|
||||
|
||||
Void::Testing::Test v4_string_length()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Uuid::v4().to_string().size(),
|
||||
std::size_t{36});
|
||||
}
|
||||
|
||||
Void::Testing::Test v4_string_has_dashes()
|
||||
{
|
||||
const auto s = Void::Uuid::v4().to_string();
|
||||
Void::Testing::expect_eq(s[8], '-');
|
||||
Void::Testing::expect_eq(s[13], '-');
|
||||
Void::Testing::expect_eq(s[18], '-');
|
||||
Void::Testing::expect_eq(s[23], '-');
|
||||
}
|
||||
|
||||
// ── v5_lite ───────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test v5_lite_deterministic()
|
||||
{
|
||||
const auto a = Void::Uuid::v5_lite(Void::Uuid::Namespace::Dns, "example.com");
|
||||
const auto b = Void::Uuid::v5_lite(Void::Uuid::Namespace::Dns, "example.com");
|
||||
Void::Testing::expect_eq(a, b);
|
||||
}
|
||||
|
||||
Void::Testing::Test v5_lite_different_names()
|
||||
{
|
||||
const auto a = Void::Uuid::v5_lite(Void::Uuid::Namespace::Dns, "foo.com");
|
||||
const auto b = Void::Uuid::v5_lite(Void::Uuid::Namespace::Dns, "bar.com");
|
||||
Void::Testing::expect(a != b);
|
||||
}
|
||||
|
||||
Void::Testing::Test v5_lite_different_namespaces()
|
||||
{
|
||||
const auto a = Void::Uuid::v5_lite(Void::Uuid::Namespace::Dns, "example");
|
||||
const auto b = Void::Uuid::v5_lite(Void::Uuid::Namespace::Url, "example");
|
||||
Void::Testing::expect(a != b);
|
||||
}
|
||||
|
||||
Void::Testing::Test v5_lite_version_nibble()
|
||||
{
|
||||
const auto u = Void::Uuid::v5_lite(Void::Uuid::Namespace::Dns, "test");
|
||||
Void::Testing::expect_eq(u.bytes[6] >> 4, std::uint8_t{5});
|
||||
}
|
||||
|
||||
// ── parse ────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test parse_round_trip()
|
||||
{
|
||||
const auto u = Void::Uuid::v4();
|
||||
const auto s = u.to_string();
|
||||
const auto parsed = Void::Uuid::parse(s);
|
||||
Void::Testing::expect(parsed.has_value());
|
||||
Void::Testing::expect_eq(*parsed, u);
|
||||
}
|
||||
|
||||
Void::Testing::Test parse_uppercase()
|
||||
{
|
||||
const auto opt = Void::Uuid::parse(
|
||||
"550E8400-E29B-41D4-A716-446655440000");
|
||||
Void::Testing::expect(opt.has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test parse_invalid_returns_nullopt()
|
||||
{
|
||||
Void::Testing::expect(!Void::Uuid::parse("not-a-uuid").has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test parse_32_char_hex()
|
||||
{
|
||||
const auto opt = Void::Uuid::parse("550e8400e29b41d4a716446655440000");
|
||||
Void::Testing::expect(opt.has_value());
|
||||
}
|
||||
|
||||
// ── nil ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test nil_uuid_is_nil()
|
||||
{
|
||||
Void::Testing::expect(Void::Uuid::Uuid::nil().is_nil());
|
||||
}
|
||||
|
||||
Void::Testing::Test v4_not_nil_check()
|
||||
{
|
||||
Void::Testing::expect(!Void::Uuid::v4().is_nil());
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
#include <Void/Core/Variant.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
using namespace Void::Variant;
|
||||
using V3 = std::variant<int, double, std::string>;
|
||||
|
||||
// ── match ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test variant_match_int()
|
||||
{
|
||||
V3 v = 42;
|
||||
const auto s = match(v,
|
||||
[](int i) { return std::to_string(i); },
|
||||
[](double d) { return std::to_string(d); },
|
||||
[](const std::string& s) { return s; });
|
||||
Void::Testing::expect_eq(s, std::string{"42"});
|
||||
}
|
||||
|
||||
Void::Testing::Test variant_match_string()
|
||||
{
|
||||
V3 v = std::string{"hello"};
|
||||
bool got_string = false;
|
||||
match(v,
|
||||
[](int) {},
|
||||
[](double) {},
|
||||
[&](const std::string&) { got_string = true; });
|
||||
Void::Testing::expect(got_string);
|
||||
}
|
||||
|
||||
Void::Testing::Test variant_match_returns_value()
|
||||
{
|
||||
V3 v = 3.14;
|
||||
const int result = match(v,
|
||||
[](int i) { return i; },
|
||||
[](double d) { return static_cast<int>(d); },
|
||||
[](const std::string&) { return 0; });
|
||||
Void::Testing::expect_eq(result, 3);
|
||||
}
|
||||
|
||||
// ── overload ──────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test variant_overload_helper()
|
||||
{
|
||||
V3 v = 99;
|
||||
const auto visitor = overload{
|
||||
[](int i) { return i * 2; },
|
||||
[](double d) { return static_cast<int>(d); },
|
||||
[](const std::string&) { return -1; }
|
||||
};
|
||||
Void::Testing::expect_eq(std::visit(visitor, v), 198);
|
||||
}
|
||||
|
||||
// ── holds ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test variant_holds_correct_type()
|
||||
{
|
||||
V3 v = 1;
|
||||
Void::Testing::expect(holds<int>(v));
|
||||
Void::Testing::expect(!holds<double>(v));
|
||||
Void::Testing::expect(!holds<std::string>(v));
|
||||
}
|
||||
|
||||
Void::Testing::Test variant_holds_after_assignment()
|
||||
{
|
||||
V3 v = 1;
|
||||
v = 3.14;
|
||||
Void::Testing::expect(!holds<int>(v));
|
||||
Void::Testing::expect(holds<double>(v));
|
||||
}
|
||||
|
||||
// ── get_or ────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test variant_get_or_present()
|
||||
{
|
||||
V3 v = 7;
|
||||
Void::Testing::expect_eq(get_or<int>(v, 0), 7);
|
||||
}
|
||||
|
||||
Void::Testing::Test variant_get_or_absent()
|
||||
{
|
||||
V3 v = 3.14;
|
||||
Void::Testing::expect_eq(get_or<int>(v, -1), -1);
|
||||
}
|
||||
|
||||
// ── try_get ───────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test variant_try_get_present()
|
||||
{
|
||||
V3 v = std::string{"world"};
|
||||
const auto r = try_get<std::string>(v);
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(*r, std::string{"world"});
|
||||
}
|
||||
|
||||
Void::Testing::Test variant_try_get_absent()
|
||||
{
|
||||
V3 v = 1;
|
||||
Void::Testing::expect(!try_get<std::string>(v).has_value());
|
||||
}
|
||||
|
||||
// ── index_of ─────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test variant_index_of_compile_time()
|
||||
{
|
||||
static_assert(index_of<int, V3> == 0);
|
||||
static_assert(index_of<double, V3> == 1);
|
||||
static_assert(index_of<std::string, V3> == 2);
|
||||
Void::Testing::expect(true); // compile-time assertion passed
|
||||
}
|
||||
|
||||
// ── apply_to ─────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test variant_apply_to_matching()
|
||||
{
|
||||
V3 v = 5;
|
||||
const auto r = apply_to<int>(v, [](int i) { return i * 10; });
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(*r, 50);
|
||||
}
|
||||
|
||||
Void::Testing::Test variant_apply_to_non_matching()
|
||||
{
|
||||
V3 v = 3.14;
|
||||
const auto r = apply_to<int>(v, [](int i) { return i; });
|
||||
Void::Testing::expect(!r.has_value());
|
||||
}
|
||||
|
||||
// ── narrow ────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test variant_narrow_convertible()
|
||||
{
|
||||
V3 v = 7;
|
||||
const auto r = narrow<double>(v); // int is convertible to double
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(*r, 7.0);
|
||||
}
|
||||
|
||||
Void::Testing::Test variant_narrow_not_convertible()
|
||||
{
|
||||
V3 v = std::string{"x"};
|
||||
const auto r = narrow<double>(v);
|
||||
Void::Testing::expect(!r.has_value());
|
||||
}
|
||||
Reference in new issue
Block a user