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>
187 lines
6.0 KiB
C++
187 lines
6.0 KiB
C++
#include <Void/String/String.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
// ── trim ─────────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test trim_removes_leading_and_trailing_spaces()
|
|
{
|
|
Void::Testing::expect_eq(
|
|
std::string{Void::String::trim(" hello ")},
|
|
std::string{"hello"});
|
|
}
|
|
|
|
Void::Testing::Test trim_leaves_interior_whitespace()
|
|
{
|
|
Void::Testing::expect_eq(
|
|
std::string{Void::String::trim(" a b ")},
|
|
std::string{"a b"});
|
|
}
|
|
|
|
Void::Testing::Test trim_empty_string_stays_empty()
|
|
{
|
|
Void::Testing::expect(Void::String::trim("").empty());
|
|
}
|
|
|
|
Void::Testing::Test trim_only_whitespace_returns_empty()
|
|
{
|
|
Void::Testing::expect(Void::String::trim(" \t\n ").empty());
|
|
}
|
|
|
|
Void::Testing::Test trim_left_only_removes_prefix()
|
|
{
|
|
Void::Testing::expect_eq(
|
|
std::string{Void::String::trim_left(" hi ")},
|
|
std::string{"hi "});
|
|
}
|
|
|
|
Void::Testing::Test trim_right_only_removes_suffix()
|
|
{
|
|
Void::Testing::expect_eq(
|
|
std::string{Void::String::trim_right(" hi ")},
|
|
std::string{" hi"});
|
|
}
|
|
|
|
// ── split ─────────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test split_char_produces_correct_parts()
|
|
{
|
|
const auto parts = Void::String::split("a,b,c", ',');
|
|
Void::Testing::expect_eq(parts.size(), std::size_t{3});
|
|
Void::Testing::expect_eq(std::string{parts[0]}, std::string{"a"});
|
|
Void::Testing::expect_eq(std::string{parts[1]}, std::string{"b"});
|
|
Void::Testing::expect_eq(std::string{parts[2]}, std::string{"c"});
|
|
}
|
|
|
|
Void::Testing::Test split_char_preserves_empty_tokens()
|
|
{
|
|
const auto parts = Void::String::split("a,,b", ',');
|
|
Void::Testing::expect_eq(parts.size(), std::size_t{3});
|
|
Void::Testing::expect(parts[1].empty());
|
|
}
|
|
|
|
Void::Testing::Test split_char_no_delimiter_returns_whole_string()
|
|
{
|
|
const auto parts = Void::String::split("hello", ',');
|
|
Void::Testing::expect_eq(parts.size(), std::size_t{1});
|
|
Void::Testing::expect_eq(std::string{parts[0]}, std::string{"hello"});
|
|
}
|
|
|
|
Void::Testing::Test split_string_delimiter_works()
|
|
{
|
|
const auto parts = Void::String::split("a::b::c", "::");
|
|
Void::Testing::expect_eq(parts.size(), std::size_t{3});
|
|
Void::Testing::expect_eq(std::string{parts[1]}, std::string{"b"});
|
|
}
|
|
|
|
Void::Testing::Test split_empty_delimiter_returns_whole()
|
|
{
|
|
const auto parts = Void::String::split("abc", "");
|
|
Void::Testing::expect_eq(parts.size(), std::size_t{1});
|
|
}
|
|
|
|
// ── join ──────────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test join_vector_of_string_view()
|
|
{
|
|
const std::vector<std::string_view> parts{"a", "b", "c"};
|
|
Void::Testing::expect_eq(Void::String::join(parts, ", "),
|
|
std::string{"a, b, c"});
|
|
}
|
|
|
|
Void::Testing::Test join_single_element_no_separator()
|
|
{
|
|
const std::vector<std::string_view> parts{"only"};
|
|
Void::Testing::expect_eq(Void::String::join(parts, "-"),
|
|
std::string{"only"});
|
|
}
|
|
|
|
Void::Testing::Test join_empty_range_returns_empty()
|
|
{
|
|
const std::vector<std::string_view> parts;
|
|
Void::Testing::expect(Void::String::join(parts, ",").empty());
|
|
}
|
|
|
|
// ── case ──────────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test to_lower_converts_ascii()
|
|
{
|
|
Void::Testing::expect_eq(Void::String::to_lower("Hello World"),
|
|
std::string{"hello world"});
|
|
}
|
|
|
|
Void::Testing::Test to_upper_converts_ascii()
|
|
{
|
|
Void::Testing::expect_eq(Void::String::to_upper("Hello World"),
|
|
std::string{"HELLO WORLD"});
|
|
}
|
|
|
|
// ── replace_all ───────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test replace_all_replaces_all_occurrences()
|
|
{
|
|
Void::Testing::expect_eq(Void::String::replace_all("aXbXc", "X", "--"),
|
|
std::string{"a--b--c"});
|
|
}
|
|
|
|
Void::Testing::Test replace_all_with_empty_from_returns_original()
|
|
{
|
|
Void::Testing::expect_eq(Void::String::replace_all("abc", "", "x"),
|
|
std::string{"abc"});
|
|
}
|
|
|
|
Void::Testing::Test replace_all_no_match_returns_original()
|
|
{
|
|
Void::Testing::expect_eq(Void::String::replace_all("abc", "z", "x"),
|
|
std::string{"abc"});
|
|
}
|
|
|
|
// ── pad ───────────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test pad_right_pads_to_width()
|
|
{
|
|
Void::Testing::expect_eq(Void::String::pad_right("hi", 5),
|
|
std::string{"hi "});
|
|
}
|
|
|
|
Void::Testing::Test pad_right_no_op_when_already_wide()
|
|
{
|
|
Void::Testing::expect_eq(Void::String::pad_right("hello", 3),
|
|
std::string{"hello"});
|
|
}
|
|
|
|
Void::Testing::Test pad_left_pads_to_width()
|
|
{
|
|
Void::Testing::expect_eq(Void::String::pad_left("hi", 5),
|
|
std::string{" hi"});
|
|
}
|
|
|
|
// ── misc ──────────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test repeat_produces_correct_output()
|
|
{
|
|
Void::Testing::expect_eq(Void::String::repeat("ab", 3),
|
|
std::string{"ababab"});
|
|
}
|
|
|
|
Void::Testing::Test repeat_zero_returns_empty()
|
|
{
|
|
Void::Testing::expect(Void::String::repeat("ab", 0).empty());
|
|
}
|
|
|
|
Void::Testing::Test count_occurrences_finds_all()
|
|
{
|
|
Void::Testing::expect_eq(Void::String::count_occurrences("abab", "ab"),
|
|
std::size_t{2});
|
|
}
|
|
|
|
Void::Testing::Test count_occurrences_no_match_returns_zero()
|
|
{
|
|
Void::Testing::expect_eq(Void::String::count_occurrences("abc", "x"),
|
|
std::size_t{0});
|
|
}
|