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>
122 lines
3.7 KiB
C++
122 lines
3.7 KiB
C++
#include <Void/Time/Format.hpp>
|
|
#include <Void/Time/Stopwatch.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <chrono>
|
|
#include <string>
|
|
#include <thread>
|
|
|
|
// ── Stopwatch ─────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test stopwatch_elapsed_is_non_negative()
|
|
{
|
|
Void::Time::Stopwatch sw;
|
|
Void::Testing::expect(sw.elapsed().count() >= 0);
|
|
}
|
|
|
|
Void::Testing::Test stopwatch_elapsed_as_milliseconds()
|
|
{
|
|
Void::Time::Stopwatch sw;
|
|
std::this_thread::sleep_for(std::chrono::milliseconds{5});
|
|
const auto ms = sw.elapsed_as<std::chrono::milliseconds>().count();
|
|
Void::Testing::expect(ms >= 4);
|
|
Void::Testing::expect(ms < 500);
|
|
}
|
|
|
|
Void::Testing::Test stopwatch_reset_restarts_from_zero()
|
|
{
|
|
Void::Time::Stopwatch sw;
|
|
std::this_thread::sleep_for(std::chrono::milliseconds{5});
|
|
sw.reset();
|
|
const auto ns = sw.elapsed().count();
|
|
Void::Testing::expect(ns < 5'000'000); // < 5ms since reset
|
|
}
|
|
|
|
Void::Testing::Test stopwatch_split_returns_elapsed_and_resets()
|
|
{
|
|
Void::Time::Stopwatch sw;
|
|
std::this_thread::sleep_for(std::chrono::milliseconds{5});
|
|
const auto d = sw.split();
|
|
const auto after = sw.elapsed().count();
|
|
Void::Testing::expect(d.count() >= 0);
|
|
Void::Testing::expect(after < d.count()); // after reset < before reset
|
|
}
|
|
|
|
// ── format_duration ───────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test format_duration_nanoseconds()
|
|
{
|
|
using namespace std::chrono_literals;
|
|
Void::Testing::expect_eq(Void::Time::format_duration(500ns),
|
|
std::string{"500ns"});
|
|
}
|
|
|
|
Void::Testing::Test format_duration_microseconds()
|
|
{
|
|
using namespace std::chrono_literals;
|
|
Void::Testing::expect(
|
|
Void::Time::format_duration(4500ns).find("\xc2\xb5s") !=
|
|
std::string::npos);
|
|
}
|
|
|
|
Void::Testing::Test format_duration_milliseconds()
|
|
{
|
|
using namespace std::chrono_literals;
|
|
Void::Testing::expect(
|
|
Void::Time::format_duration(2'300'000ns).find("ms") !=
|
|
std::string::npos);
|
|
}
|
|
|
|
Void::Testing::Test format_duration_seconds()
|
|
{
|
|
using namespace std::chrono_literals;
|
|
Void::Testing::expect(
|
|
Void::Time::format_duration(1'500'000'000ns).find('s') !=
|
|
std::string::npos);
|
|
}
|
|
|
|
Void::Testing::Test format_duration_minutes()
|
|
{
|
|
Void::Testing::expect(
|
|
Void::Time::format_duration(std::chrono::seconds{90}).find('m') !=
|
|
std::string::npos);
|
|
}
|
|
|
|
Void::Testing::Test format_duration_hours()
|
|
{
|
|
Void::Testing::expect(
|
|
Void::Time::format_duration(std::chrono::seconds{3700}).find('h') !=
|
|
std::string::npos);
|
|
}
|
|
|
|
Void::Testing::Test format_duration_works_with_chrono_milliseconds()
|
|
{
|
|
using namespace std::chrono_literals;
|
|
const auto s = Void::Time::format_duration(15ms);
|
|
Void::Testing::expect(s.find("ms") != std::string::npos);
|
|
}
|
|
|
|
// ── utc timestamps ────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test utc_now_iso8601_has_correct_format()
|
|
{
|
|
const auto s = Void::Time::utc_now_iso8601();
|
|
// "2026-05-14T10:30:00Z"
|
|
Void::Testing::expect_eq(s.size(), std::size_t{20});
|
|
Void::Testing::expect_eq(s[4], '-');
|
|
Void::Testing::expect_eq(s[7], '-');
|
|
Void::Testing::expect_eq(s[10], 'T');
|
|
Void::Testing::expect_eq(s.back(), 'Z');
|
|
}
|
|
|
|
Void::Testing::Test utc_now_iso8601_ms_has_correct_format()
|
|
{
|
|
const auto s = Void::Time::utc_now_iso8601_ms();
|
|
// "2026-05-14T10:30:00.123Z"
|
|
Void::Testing::expect_eq(s.size(), std::size_t{24});
|
|
Void::Testing::expect_eq(s[10], 'T');
|
|
Void::Testing::expect_eq(s[19], '.');
|
|
Void::Testing::expect_eq(s.back(), 'Z');
|
|
}
|