Files
Library/tests/standalone/Uuid/Uuid.cpp
T
faumarayandClaude Sonnet 4.6 a09e000f0f Add Hash, Random, Uuid, Encoding, Bits, Math modules + make Testing deps optional
New header-only modules:
- Void::Hash — FNV-1a 32/64, CRC-32, DJB2, MurmurHash3-32, UDL literals
- Void::Random — Xoshiro256** PRNG, uniform_int/real, coin_flip, shuffle, random_string
- Void::Uuid — v4 (random), v5_lite (name-based), parse, RFC 4122 namespaces
- Void::Encoding — Base64 (standard + URL-safe), Hex encode/decode
- Void::Bits — popcount, bit extract/deposit, rotation, align, byteswap, masks
- Void::Math — Vec2/Vec3/Vec4, Mat4 (identity, translation, scale, rotation)

Testing module: move Stacktrace from INTERNAL_DEPS to OPTIONAL_DEPS. Added
Detail/Color.hpp shim that delegates to Stacktrace::Color when present or
provides inline ANSI fallback otherwise. All Stacktrace calls in SignalHandler,
ConsoleReporter, and Runner are gated on VOID_HAS_STACKTRACE.

Fix Repr.hpp reflect_struct to handle template specializations that lack
std::meta::identifier_of (now guarded by has_identifier check).

33/33 tests pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 21:52:22 +03:00

114 lines
3.7 KiB
C++

#include <Void/Uuid/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());
}