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,134 @@
|
||||
#include <Void/Text/Diff.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace Void::Diff;
|
||||
|
||||
// ── integer sequence diff ─────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test diff_identical_sequences()
|
||||
{
|
||||
const std::vector<int> a{1, 2, 3};
|
||||
const auto edits = diff(a, a);
|
||||
Void::Testing::expect_eq(count_op(edits, Op::Delete), std::size_t{0});
|
||||
Void::Testing::expect_eq(count_op(edits, Op::Insert), std::size_t{0});
|
||||
Void::Testing::expect_eq(count_op(edits, Op::Equal), std::size_t{3});
|
||||
}
|
||||
|
||||
Void::Testing::Test diff_empty_to_nonempty()
|
||||
{
|
||||
const std::vector<int> a{};
|
||||
const std::vector<int> b{1, 2, 3};
|
||||
const auto edits = diff(a, b);
|
||||
Void::Testing::expect_eq(count_op(edits, Op::Insert), std::size_t{3});
|
||||
Void::Testing::expect_eq(count_op(edits, Op::Delete), std::size_t{0});
|
||||
}
|
||||
|
||||
Void::Testing::Test diff_nonempty_to_empty()
|
||||
{
|
||||
const std::vector<int> a{1, 2};
|
||||
const std::vector<int> b{};
|
||||
const auto edits = diff(a, b);
|
||||
Void::Testing::expect_eq(count_op(edits, Op::Delete), std::size_t{2});
|
||||
Void::Testing::expect_eq(count_op(edits, Op::Insert), std::size_t{0});
|
||||
}
|
||||
|
||||
Void::Testing::Test diff_single_insert()
|
||||
{
|
||||
const std::vector<int> a{1, 3};
|
||||
const std::vector<int> b{1, 2, 3};
|
||||
const auto edits = diff(a, b);
|
||||
Void::Testing::expect_eq(count_op(edits, Op::Insert), std::size_t{1});
|
||||
Void::Testing::expect_eq(count_op(edits, Op::Equal), std::size_t{2});
|
||||
}
|
||||
|
||||
Void::Testing::Test diff_single_delete()
|
||||
{
|
||||
const std::vector<int> a{1, 2, 3};
|
||||
const std::vector<int> b{1, 3};
|
||||
const auto edits = diff(a, b);
|
||||
Void::Testing::expect_eq(count_op(edits, Op::Delete), std::size_t{1});
|
||||
Void::Testing::expect_eq(count_op(edits, Op::Equal), std::size_t{2});
|
||||
}
|
||||
|
||||
Void::Testing::Test diff_substitution()
|
||||
{
|
||||
const std::vector<int> a{1, 2, 3};
|
||||
const std::vector<int> b{1, 9, 3};
|
||||
const auto edits = diff(a, b);
|
||||
Void::Testing::expect_eq(count_op(edits, Op::Delete), std::size_t{1});
|
||||
Void::Testing::expect_eq(count_op(edits, Op::Insert), std::size_t{1});
|
||||
Void::Testing::expect_eq(count_op(edits, Op::Equal), std::size_t{2});
|
||||
}
|
||||
|
||||
Void::Testing::Test diff_apply_reconstructs_b()
|
||||
{
|
||||
const std::vector<int> a{1, 2, 3, 4, 5};
|
||||
const std::vector<int> b{1, 3, 5, 6};
|
||||
const auto edits = diff(a, b);
|
||||
const auto result = apply(edits);
|
||||
Void::Testing::expect_eq(result, b);
|
||||
}
|
||||
|
||||
Void::Testing::Test diff_completely_different()
|
||||
{
|
||||
const std::vector<int> a{1, 2, 3};
|
||||
const std::vector<int> b{4, 5, 6};
|
||||
const auto edits = diff(a, b);
|
||||
Void::Testing::expect_eq(count_op(edits, Op::Equal), std::size_t{0});
|
||||
}
|
||||
|
||||
Void::Testing::Test diff_empty_both()
|
||||
{
|
||||
const std::vector<int> a{}, b{};
|
||||
const auto edits = diff(a, b);
|
||||
Void::Testing::expect(edits.empty());
|
||||
}
|
||||
|
||||
// ── string sequence diff ──────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test diff_string_chars()
|
||||
{
|
||||
const std::vector<char> a{'a', 'b', 'c'};
|
||||
const std::vector<char> b{'a', 'x', 'c'};
|
||||
const auto edits = diff(a, b);
|
||||
Void::Testing::expect_eq(count_op(edits, Op::Equal), std::size_t{2});
|
||||
Void::Testing::expect_eq(count_op(edits, Op::Delete), std::size_t{1});
|
||||
Void::Testing::expect_eq(count_op(edits, Op::Insert), std::size_t{1});
|
||||
}
|
||||
|
||||
// ── line diff ─────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test diff_line_diff_identical()
|
||||
{
|
||||
const auto edits = line_diff("a\nb\nc", "a\nb\nc");
|
||||
Void::Testing::expect_eq(count_op(edits, Op::Insert), std::size_t{0});
|
||||
Void::Testing::expect_eq(count_op(edits, Op::Delete), std::size_t{0});
|
||||
}
|
||||
|
||||
Void::Testing::Test diff_line_diff_insert_line()
|
||||
{
|
||||
const auto edits = line_diff("a\nc", "a\nb\nc");
|
||||
Void::Testing::expect_eq(count_op(edits, Op::Insert), std::size_t{1});
|
||||
}
|
||||
|
||||
Void::Testing::Test diff_format_patch()
|
||||
{
|
||||
const auto edits = line_diff("a\nb", "a\nc");
|
||||
const auto patch = format_patch(edits);
|
||||
Void::Testing::expect(patch.find('-') != std::string::npos);
|
||||
Void::Testing::expect(patch.find('+') != std::string::npos);
|
||||
}
|
||||
|
||||
Void::Testing::Test diff_apply_line_reconstructs_b()
|
||||
{
|
||||
const std::string a = "foo\nbar\nbaz";
|
||||
const std::string b = "foo\nqux\nbaz";
|
||||
const auto edits = line_diff(a, b);
|
||||
const auto result_lines = apply(edits);
|
||||
Void::Testing::expect_eq(result_lines.size(), std::size_t{3});
|
||||
Void::Testing::expect_eq(result_lines[1], std::string{"qux"});
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
#include <Void/Text/Base64.hpp>
|
||||
#include <Void/Text/Hex.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
// ── Base64 encode ─────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test base64_encode_empty()
|
||||
{
|
||||
Void::Testing::expect(Void::Encoding::Base64::encode("").empty());
|
||||
}
|
||||
|
||||
Void::Testing::Test base64_encode_man()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Encoding::Base64::encode("Man"),
|
||||
std::string{"TWFu"});
|
||||
}
|
||||
|
||||
Void::Testing::Test base64_encode_ma()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Encoding::Base64::encode("Ma"),
|
||||
std::string{"TWE="});
|
||||
}
|
||||
|
||||
Void::Testing::Test base64_encode_m()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Encoding::Base64::encode("M"),
|
||||
std::string{"TQ=="});
|
||||
}
|
||||
|
||||
Void::Testing::Test base64_encode_hello_world()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Encoding::Base64::encode("Hello, World!"),
|
||||
std::string{"SGVsbG8sIFdvcmxkIQ=="});
|
||||
}
|
||||
|
||||
// ── Base64 decode ─────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test base64_decode_empty()
|
||||
{
|
||||
const auto r = Void::Encoding::Base64::decode("");
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect(r->empty());
|
||||
}
|
||||
|
||||
Void::Testing::Test base64_decode_man()
|
||||
{
|
||||
const auto r = Void::Encoding::Base64::decode("TWFu");
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(*r, std::string{"Man"});
|
||||
}
|
||||
|
||||
Void::Testing::Test base64_decode_with_padding()
|
||||
{
|
||||
const auto r = Void::Encoding::Base64::decode("SGVsbG8sIFdvcmxkIQ==");
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(*r, std::string{"Hello, World!"});
|
||||
}
|
||||
|
||||
Void::Testing::Test base64_decode_invalid_returns_nullopt()
|
||||
{
|
||||
const auto r = Void::Encoding::Base64::decode("!!");
|
||||
Void::Testing::expect(!r.has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test base64_round_trip()
|
||||
{
|
||||
const std::string original = "The quick brown fox jumps over the lazy dog";
|
||||
const auto encoded = Void::Encoding::Base64::encode(original);
|
||||
const auto decoded = Void::Encoding::Base64::decode(encoded);
|
||||
Void::Testing::expect(decoded.has_value());
|
||||
Void::Testing::expect_eq(*decoded, original);
|
||||
}
|
||||
|
||||
// ── Base64 URL ────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test base64url_no_padding()
|
||||
{
|
||||
const auto s = Void::Encoding::Base64::encode_url("Man");
|
||||
Void::Testing::expect_eq(s, std::string{"TWFu"});
|
||||
Void::Testing::expect(s.find('=') == std::string::npos);
|
||||
}
|
||||
|
||||
Void::Testing::Test base64url_no_plus_or_slash()
|
||||
{
|
||||
// encode something that would produce + or / in standard base64
|
||||
const std::string tricky = "\xfb\xff\xfe";
|
||||
const auto s = Void::Encoding::Base64::encode_url(tricky);
|
||||
Void::Testing::expect(s.find('+') == std::string::npos);
|
||||
Void::Testing::expect(s.find('/') == std::string::npos);
|
||||
}
|
||||
|
||||
// ── Hex encode ───────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test hex_encode_empty()
|
||||
{
|
||||
Void::Testing::expect(Void::Encoding::Hex::encode("").empty());
|
||||
}
|
||||
|
||||
Void::Testing::Test hex_encode_hello()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Encoding::Hex::encode("Hi"),
|
||||
std::string{"4869"});
|
||||
}
|
||||
|
||||
Void::Testing::Test hex_encode_binary()
|
||||
{
|
||||
const std::string bin{'\x00', '\xff', '\xab'};
|
||||
Void::Testing::expect_eq(Void::Encoding::Hex::encode(bin),
|
||||
std::string{"00ffab"});
|
||||
}
|
||||
|
||||
Void::Testing::Test hex_encode_upper()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::Encoding::Hex::encode_upper("Hi"),
|
||||
std::string{"4869"});
|
||||
}
|
||||
|
||||
// ── Hex decode ───────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test hex_decode_empty()
|
||||
{
|
||||
const auto r = Void::Encoding::Hex::decode("");
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect(r->empty());
|
||||
}
|
||||
|
||||
Void::Testing::Test hex_decode_hello()
|
||||
{
|
||||
const auto r = Void::Encoding::Hex::decode("4869");
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(*r, std::string{"Hi"});
|
||||
}
|
||||
|
||||
Void::Testing::Test hex_decode_uppercase()
|
||||
{
|
||||
const auto r = Void::Encoding::Hex::decode("4869");
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(*r, std::string{"Hi"});
|
||||
}
|
||||
|
||||
Void::Testing::Test hex_decode_odd_length_fails()
|
||||
{
|
||||
Void::Testing::expect(!Void::Encoding::Hex::decode("abc").has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test hex_decode_invalid_char_fails()
|
||||
{
|
||||
Void::Testing::expect(!Void::Encoding::Hex::decode("zz").has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test hex_round_trip()
|
||||
{
|
||||
const std::string original = "binary\x00\x01\x02\xff";
|
||||
const auto encoded = Void::Encoding::Hex::encode(original);
|
||||
const auto decoded = Void::Encoding::Hex::decode(encoded);
|
||||
Void::Testing::expect(decoded.has_value());
|
||||
Void::Testing::expect_eq(*decoded, original);
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
#include <Void/Text/Format.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// ── render (named) ────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test render_single_placeholder()
|
||||
{
|
||||
const auto r = Void::Format::render("Hello, {name}!",
|
||||
{{"name", "World"}});
|
||||
Void::Testing::expect_eq(r, std::string{"Hello, World!"});
|
||||
}
|
||||
|
||||
Void::Testing::Test render_multiple_placeholders()
|
||||
{
|
||||
const auto r = Void::Format::render("{a} + {b} = {c}",
|
||||
{{"a","1"},{"b","2"},{"c","3"}});
|
||||
Void::Testing::expect_eq(r, std::string{"1 + 2 = 3"});
|
||||
}
|
||||
|
||||
Void::Testing::Test render_unknown_key_left_as_is()
|
||||
{
|
||||
const auto r = Void::Format::render("Hello {unknown}!", {});
|
||||
Void::Testing::expect_eq(r, std::string{"Hello {unknown}!"});
|
||||
}
|
||||
|
||||
Void::Testing::Test render_escaped_braces()
|
||||
{
|
||||
const auto r = Void::Format::render("{{not a placeholder}}", {});
|
||||
Void::Testing::expect_eq(r, std::string{"{not a placeholder}"});
|
||||
}
|
||||
|
||||
Void::Testing::Test render_no_placeholders()
|
||||
{
|
||||
const auto r = Void::Format::render("plain text", {});
|
||||
Void::Testing::expect_eq(r, std::string{"plain text"});
|
||||
}
|
||||
|
||||
// ── render_pos (positional) ───────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test render_pos_basic()
|
||||
{
|
||||
const auto r = Void::Format::render_pos("{0} and {1}", {"hello", "world"});
|
||||
Void::Testing::expect_eq(r, std::string{"hello and world"});
|
||||
}
|
||||
|
||||
Void::Testing::Test render_pos_repeat_arg()
|
||||
{
|
||||
const auto r = Void::Format::render_pos("{0} {0}", {"echo"});
|
||||
Void::Testing::expect_eq(r, std::string{"echo echo"});
|
||||
}
|
||||
|
||||
Void::Testing::Test render_pos_out_of_range_left_as_is()
|
||||
{
|
||||
const auto r = Void::Format::render_pos("{5}", {"a"});
|
||||
Void::Testing::expect_eq(r, std::string{"{5}"});
|
||||
}
|
||||
|
||||
// ── indent ────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test indent_adds_spaces()
|
||||
{
|
||||
const auto r = Void::Format::indent("hello\nworld", 2);
|
||||
Void::Testing::expect_eq(r, std::string{" hello\n world"});
|
||||
}
|
||||
|
||||
Void::Testing::Test indent_empty_string()
|
||||
{
|
||||
Void::Testing::expect(Void::Format::indent("", 4).empty());
|
||||
}
|
||||
|
||||
Void::Testing::Test indent_single_line()
|
||||
{
|
||||
const auto r = Void::Format::indent("hi", 3);
|
||||
Void::Testing::expect_eq(r, std::string{" hi"});
|
||||
}
|
||||
|
||||
// ── word_wrap ─────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test word_wrap_short_text_unchanged()
|
||||
{
|
||||
const auto r = Void::Format::word_wrap("hello world", 80);
|
||||
Void::Testing::expect_eq(r, std::string{"hello world"});
|
||||
}
|
||||
|
||||
Void::Testing::Test word_wrap_breaks_at_width()
|
||||
{
|
||||
const auto r = Void::Format::word_wrap("hello world foo", 11);
|
||||
Void::Testing::expect(r.find('\n') != std::string::npos);
|
||||
}
|
||||
|
||||
Void::Testing::Test word_wrap_preserves_explicit_newlines()
|
||||
{
|
||||
const auto r = Void::Format::word_wrap("line1\nline2", 80);
|
||||
Void::Testing::expect(r.find('\n') != std::string::npos);
|
||||
}
|
||||
|
||||
// ── format_table ─────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test format_table_aligns_columns()
|
||||
{
|
||||
const std::vector<std::vector<std::string>> rows = {
|
||||
{"Name", "Age"},
|
||||
{"Alice", "30"},
|
||||
{"Bob", "25"},
|
||||
};
|
||||
const auto t = Void::Format::format_table(rows);
|
||||
Void::Testing::expect(t.find("Name") != std::string::npos);
|
||||
Void::Testing::expect(t.find("Alice") != std::string::npos);
|
||||
}
|
||||
|
||||
Void::Testing::Test format_table_empty_returns_empty()
|
||||
{
|
||||
Void::Testing::expect(
|
||||
Void::Format::format_table({}).empty());
|
||||
}
|
||||
|
||||
Void::Testing::Test format_table_row_count()
|
||||
{
|
||||
const std::vector<std::vector<std::string>> rows = {
|
||||
{"a", "b"},
|
||||
{"c", "d"},
|
||||
};
|
||||
const auto t = Void::Format::format_table(rows);
|
||||
int newlines = 0;
|
||||
for (char c : t) { if (c == '\n') ++newlines; }
|
||||
Void::Testing::expect_eq(newlines, 2);
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
#include <Void/Text/Semver.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
// ── parse ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test semver_parse_simple()
|
||||
{
|
||||
const auto v = Void::Semver::parse("1.2.3");
|
||||
Void::Testing::expect(v.has_value());
|
||||
Void::Testing::expect_eq(v->major, 1u);
|
||||
Void::Testing::expect_eq(v->minor, 2u);
|
||||
Void::Testing::expect_eq(v->patch, 3u);
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_parse_with_v_prefix()
|
||||
{
|
||||
const auto v = Void::Semver::parse("v2.0.0");
|
||||
Void::Testing::expect(v.has_value());
|
||||
Void::Testing::expect_eq(v->major, 2u);
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_parse_pre_release()
|
||||
{
|
||||
const auto v = Void::Semver::parse("1.0.0-alpha.1");
|
||||
Void::Testing::expect(v.has_value());
|
||||
Void::Testing::expect_eq(v->pre_release, std::string{"alpha.1"});
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_parse_build_metadata()
|
||||
{
|
||||
const auto v = Void::Semver::parse("1.0.0+build.123");
|
||||
Void::Testing::expect(v.has_value());
|
||||
Void::Testing::expect_eq(v->build, std::string{"build.123"});
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_parse_full()
|
||||
{
|
||||
const auto v = Void::Semver::parse("2.3.4-beta.2+20240101");
|
||||
Void::Testing::expect(v.has_value());
|
||||
Void::Testing::expect_eq(v->major, 2u);
|
||||
Void::Testing::expect_eq(v->pre_release, std::string{"beta.2"});
|
||||
Void::Testing::expect_eq(v->build, std::string{"20240101"});
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_parse_invalid()
|
||||
{
|
||||
Void::Testing::expect(!Void::Semver::parse("not-a-version").has_value());
|
||||
Void::Testing::expect(!Void::Semver::parse("1.2").has_value());
|
||||
}
|
||||
|
||||
// ── to_string ─────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test semver_to_string_simple()
|
||||
{
|
||||
Void::Semver::Version v{1, 2, 3};
|
||||
Void::Testing::expect_eq(v.to_string(), std::string{"1.2.3"});
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_to_string_with_pre_release()
|
||||
{
|
||||
Void::Semver::Version v{1, 0, 0};
|
||||
v.pre_release = "alpha";
|
||||
Void::Testing::expect_eq(v.to_string(), std::string{"1.0.0-alpha"});
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_round_trip()
|
||||
{
|
||||
const auto v = Void::Semver::parse("3.1.4-rc.1+build1");
|
||||
Void::Testing::expect(v.has_value());
|
||||
Void::Testing::expect_eq(v->to_string(), std::string{"3.1.4-rc.1+build1"});
|
||||
}
|
||||
|
||||
// ── comparison ───────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test semver_compare_major()
|
||||
{
|
||||
const auto a = *Void::Semver::parse("2.0.0");
|
||||
const auto b = *Void::Semver::parse("1.9.9");
|
||||
Void::Testing::expect(a > b);
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_compare_minor()
|
||||
{
|
||||
const auto a = *Void::Semver::parse("1.2.0");
|
||||
const auto b = *Void::Semver::parse("1.1.9");
|
||||
Void::Testing::expect(a > b);
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_compare_patch()
|
||||
{
|
||||
const auto a = *Void::Semver::parse("1.0.1");
|
||||
const auto b = *Void::Semver::parse("1.0.0");
|
||||
Void::Testing::expect(a > b);
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_release_gt_pre_release()
|
||||
{
|
||||
const auto a = *Void::Semver::parse("1.0.0");
|
||||
const auto b = *Void::Semver::parse("1.0.0-alpha");
|
||||
Void::Testing::expect(a > b);
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_equal()
|
||||
{
|
||||
const auto a = *Void::Semver::parse("1.2.3");
|
||||
const auto b = *Void::Semver::parse("1.2.3");
|
||||
Void::Testing::expect(a == b);
|
||||
}
|
||||
|
||||
// ── bump ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test semver_bump_major()
|
||||
{
|
||||
const auto v = Void::Semver::Version{1, 2, 3};
|
||||
const auto b = v.bumped_major();
|
||||
Void::Testing::expect_eq(b.major, 2u);
|
||||
Void::Testing::expect_eq(b.minor, 0u);
|
||||
Void::Testing::expect_eq(b.patch, 0u);
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_bump_minor()
|
||||
{
|
||||
const auto v = Void::Semver::Version{1, 2, 3};
|
||||
const auto b = v.bumped_minor();
|
||||
Void::Testing::expect_eq(b.minor, 3u);
|
||||
Void::Testing::expect_eq(b.patch, 0u);
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_bump_patch()
|
||||
{
|
||||
const auto v = Void::Semver::Version{1, 2, 3};
|
||||
Void::Testing::expect_eq(v.bumped_patch().patch, 4u);
|
||||
}
|
||||
|
||||
// ── compatible_with ───────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test semver_compatible_same_major()
|
||||
{
|
||||
const auto a = *Void::Semver::parse("1.3.0");
|
||||
const auto req = *Void::Semver::parse("1.2.0");
|
||||
Void::Testing::expect(a.compatible_with(req));
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_incompatible_different_major()
|
||||
{
|
||||
const auto a = *Void::Semver::parse("2.0.0");
|
||||
const auto req = *Void::Semver::parse("1.9.9");
|
||||
Void::Testing::expect(!a.compatible_with(req));
|
||||
}
|
||||
|
||||
Void::Testing::Test semver_is_stable()
|
||||
{
|
||||
Void::Testing::expect(Void::Semver::Version{1,0,0}.is_stable());
|
||||
Void::Testing::expect(!Void::Semver::Version{0,9,0}.is_stable());
|
||||
Void::Semver::Version pre{1,0,0};
|
||||
pre.pre_release = "alpha";
|
||||
Void::Testing::expect(!pre.is_stable());
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
#include <Void/Text/Str.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace Void::Str;
|
||||
|
||||
// ── trim ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test str_trim_left()
|
||||
{
|
||||
Void::Testing::expect_eq(trim_left(" hello"), std::string_view{"hello"});
|
||||
Void::Testing::expect_eq(trim_left("hello"), std::string_view{"hello"});
|
||||
}
|
||||
|
||||
Void::Testing::Test str_trim_right()
|
||||
{
|
||||
Void::Testing::expect_eq(trim_right("hello "), std::string_view{"hello"});
|
||||
}
|
||||
|
||||
Void::Testing::Test str_trim_both()
|
||||
{
|
||||
Void::Testing::expect_eq(trim(" hello "), std::string_view{"hello"});
|
||||
Void::Testing::expect_eq(trim(""), std::string_view{""});
|
||||
}
|
||||
|
||||
// ── case ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test str_to_lower()
|
||||
{
|
||||
Void::Testing::expect_eq(to_lower("Hello World"), std::string{"hello world"});
|
||||
}
|
||||
|
||||
Void::Testing::Test str_to_upper()
|
||||
{
|
||||
Void::Testing::expect_eq(to_upper("hello"), std::string{"HELLO"});
|
||||
}
|
||||
|
||||
// ── predicates ────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test str_starts_with()
|
||||
{
|
||||
Void::Testing::expect(starts_with("foobar", "foo"));
|
||||
Void::Testing::expect(!starts_with("foobar", "bar"));
|
||||
}
|
||||
|
||||
Void::Testing::Test str_ends_with()
|
||||
{
|
||||
Void::Testing::expect(ends_with("foobar", "bar"));
|
||||
Void::Testing::expect(!ends_with("foobar", "foo"));
|
||||
}
|
||||
|
||||
Void::Testing::Test str_contains()
|
||||
{
|
||||
Void::Testing::expect(contains("hello world", "world"));
|
||||
Void::Testing::expect(!contains("hello", "xyz"));
|
||||
}
|
||||
|
||||
Void::Testing::Test str_is_alpha()
|
||||
{
|
||||
Void::Testing::expect(is_alpha("abc"));
|
||||
Void::Testing::expect(!is_alpha("ab1"));
|
||||
Void::Testing::expect(!is_alpha(""));
|
||||
}
|
||||
|
||||
Void::Testing::Test str_is_digit()
|
||||
{
|
||||
Void::Testing::expect(is_digit("123"));
|
||||
Void::Testing::expect(!is_digit("12a"));
|
||||
}
|
||||
|
||||
Void::Testing::Test str_is_alnum()
|
||||
{
|
||||
Void::Testing::expect(is_alnum("abc123"));
|
||||
Void::Testing::expect(!is_alnum("abc!"));
|
||||
}
|
||||
|
||||
// ── split / join ──────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test str_split_basic()
|
||||
{
|
||||
const auto parts = split("a,b,c", ",");
|
||||
Void::Testing::expect_eq(parts.size(), std::size_t{3});
|
||||
Void::Testing::expect_eq(parts[0], std::string_view{"a"});
|
||||
Void::Testing::expect_eq(parts[2], std::string_view{"c"});
|
||||
}
|
||||
|
||||
Void::Testing::Test str_split_no_delim()
|
||||
{
|
||||
const auto parts = split("hello", ",");
|
||||
Void::Testing::expect_eq(parts.size(), std::size_t{1});
|
||||
Void::Testing::expect_eq(parts[0], std::string_view{"hello"});
|
||||
}
|
||||
|
||||
Void::Testing::Test str_split_once()
|
||||
{
|
||||
const auto parts = split_once("key=value=extra", "=");
|
||||
Void::Testing::expect_eq(parts.size(), std::size_t{2});
|
||||
Void::Testing::expect_eq(parts[0], std::string_view{"key"});
|
||||
Void::Testing::expect_eq(parts[1], std::string_view{"value=extra"});
|
||||
}
|
||||
|
||||
Void::Testing::Test str_join()
|
||||
{
|
||||
const std::vector<std::string> v{"a", "b", "c"};
|
||||
Void::Testing::expect_eq(join(v, ", "), std::string{"a, b, c"});
|
||||
}
|
||||
|
||||
// ── replace ───────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test str_replace_all()
|
||||
{
|
||||
Void::Testing::expect_eq(replace_all("aabaa", "aa", "x"), std::string{"xbx"});
|
||||
}
|
||||
|
||||
Void::Testing::Test str_replace_all_no_match()
|
||||
{
|
||||
Void::Testing::expect_eq(replace_all("hello", "xyz", "!"), std::string{"hello"});
|
||||
}
|
||||
|
||||
// ── repeat ────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test str_repeat()
|
||||
{
|
||||
Void::Testing::expect_eq(repeat("ab", 3), std::string{"ababab"});
|
||||
Void::Testing::expect_eq(repeat("x", 0), std::string{""});
|
||||
}
|
||||
|
||||
// ── count ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test str_count_occurrences()
|
||||
{
|
||||
Void::Testing::expect_eq(count("ababab", "ab"), std::size_t{3});
|
||||
Void::Testing::expect_eq(count("hello", "xyz"), std::size_t{0});
|
||||
}
|
||||
|
||||
// ── pad ───────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test str_pad_left()
|
||||
{
|
||||
Void::Testing::expect_eq(pad_left("hi", 5), std::string{" hi"});
|
||||
Void::Testing::expect_eq(pad_left("hello", 3), std::string{"hello"});
|
||||
}
|
||||
|
||||
Void::Testing::Test str_pad_right()
|
||||
{
|
||||
Void::Testing::expect_eq(pad_right("hi", 5), std::string{"hi "});
|
||||
}
|
||||
|
||||
// ── numeric conversion ────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test str_to_int_valid()
|
||||
{
|
||||
int v = 0;
|
||||
Void::Testing::expect(to_int("42", v));
|
||||
Void::Testing::expect_eq(v, 42);
|
||||
}
|
||||
|
||||
Void::Testing::Test str_to_int_invalid()
|
||||
{
|
||||
int v = 0;
|
||||
Void::Testing::expect(!to_int("abc", v));
|
||||
Void::Testing::expect(!to_int("12x", v));
|
||||
}
|
||||
|
||||
Void::Testing::Test str_to_double_valid()
|
||||
{
|
||||
double v = 0.0;
|
||||
Void::Testing::expect(to_double("3.14", v));
|
||||
Void::Testing::expect(v > 3.13 && v < 3.15);
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
#include <Void/Text/Tokenizer.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
using namespace Void::Tokenizer;
|
||||
|
||||
// ── helpers ───────────────────────────────────────────────────────────────────
|
||||
|
||||
static Tokenizer make_expr_tokenizer()
|
||||
{
|
||||
Tokenizer t;
|
||||
t.add_rule({"NUMBER", integer_literal()});
|
||||
t.add_rule({"IDENT", identifier()});
|
||||
t.add_rule({"PLUS", literal("+")});
|
||||
t.add_rule({"MINUS", literal("-")});
|
||||
t.add_rule({"STAR", literal("*")});
|
||||
t.add_rule({"SLASH", literal("/")});
|
||||
t.add_rule({"LPAREN", literal("(")});
|
||||
t.add_rule({"RPAREN", literal(")")});
|
||||
t.skip("WS", whitespace());
|
||||
return t;
|
||||
}
|
||||
|
||||
// ── literal matching ──────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test tokenizer_empty_input()
|
||||
{
|
||||
const Tokenizer t;
|
||||
const auto result = t.tokenize("");
|
||||
const auto* tokens = std::get_if<std::vector<Token>>(&result);
|
||||
Void::Testing::expect(tokens != nullptr);
|
||||
Void::Testing::expect(tokens->empty());
|
||||
}
|
||||
|
||||
Void::Testing::Test tokenizer_single_token()
|
||||
{
|
||||
Tokenizer t;
|
||||
t.add_rule({"WORD", identifier()});
|
||||
const auto tokens = t.tokenize_or_throw("hello");
|
||||
Void::Testing::expect_eq(tokens.size(), std::size_t{1});
|
||||
Void::Testing::expect_eq(tokens[0].kind, std::string{"WORD"});
|
||||
Void::Testing::expect_eq(tokens[0].value, std::string{"hello"});
|
||||
}
|
||||
|
||||
Void::Testing::Test tokenizer_multiple_tokens()
|
||||
{
|
||||
const auto t = make_expr_tokenizer();
|
||||
const auto tokens = t.tokenize_or_throw("x + 42");
|
||||
Void::Testing::expect_eq(tokens.size(), std::size_t{3});
|
||||
Void::Testing::expect_eq(tokens[0].kind, std::string{"IDENT"});
|
||||
Void::Testing::expect_eq(tokens[1].kind, std::string{"PLUS"});
|
||||
Void::Testing::expect_eq(tokens[2].kind, std::string{"NUMBER"});
|
||||
Void::Testing::expect_eq(tokens[2].value, std::string{"42"});
|
||||
}
|
||||
|
||||
Void::Testing::Test tokenizer_whitespace_skipped()
|
||||
{
|
||||
const auto t = make_expr_tokenizer();
|
||||
const auto tokens = t.tokenize_or_throw(" 1 + 2 ");
|
||||
Void::Testing::expect_eq(tokens.size(), std::size_t{3});
|
||||
}
|
||||
|
||||
Void::Testing::Test tokenizer_no_whitespace_skip()
|
||||
{
|
||||
Tokenizer t;
|
||||
t.add_rule({"NUM", digit()});
|
||||
// no WS rule — a space triggers an error
|
||||
const auto result = t.tokenize("1 2");
|
||||
Void::Testing::expect(std::holds_alternative<Tokenizer::Error>(result));
|
||||
}
|
||||
|
||||
// ── line/col tracking ─────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test tokenizer_line_col_first_token()
|
||||
{
|
||||
Tokenizer t;
|
||||
t.add_rule({"ID", identifier()});
|
||||
const auto tokens = t.tokenize_or_throw("foo");
|
||||
Void::Testing::expect_eq(tokens[0].line, std::size_t{1});
|
||||
Void::Testing::expect_eq(tokens[0].col, std::size_t{1});
|
||||
}
|
||||
|
||||
Void::Testing::Test tokenizer_line_col_after_newline()
|
||||
{
|
||||
Tokenizer t;
|
||||
t.add_rule({"ID", identifier()});
|
||||
t.skip("NL", literal("\n"));
|
||||
t.skip("WS", whitespace());
|
||||
const auto tokens = t.tokenize_or_throw("foo\nbar");
|
||||
Void::Testing::expect_eq(tokens.size(), std::size_t{2});
|
||||
Void::Testing::expect_eq(tokens[1].line, std::size_t{2});
|
||||
Void::Testing::expect_eq(tokens[1].col, std::size_t{1});
|
||||
}
|
||||
|
||||
// ── unrecognized character ────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test tokenizer_error_on_unknown()
|
||||
{
|
||||
Tokenizer t;
|
||||
t.add_rule({"NUM", digit()});
|
||||
const auto result = t.tokenize("@");
|
||||
const auto* err = std::get_if<Tokenizer::Error>(&result);
|
||||
Void::Testing::expect(err != nullptr);
|
||||
Void::Testing::expect_eq(err->unexpected, '@');
|
||||
Void::Testing::expect_eq(err->line, std::size_t{1});
|
||||
}
|
||||
|
||||
// ── built-in matchers ─────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test tokenizer_identifier_rule()
|
||||
{
|
||||
Tokenizer t;
|
||||
t.add_rule({"ID", identifier()});
|
||||
const auto tokens = t.tokenize_or_throw("_foo123");
|
||||
Void::Testing::expect_eq(tokens[0].value, std::string{"_foo123"});
|
||||
}
|
||||
|
||||
Void::Testing::Test tokenizer_integer_literal_rule()
|
||||
{
|
||||
Tokenizer t;
|
||||
t.add_rule({"NUM", integer_literal()});
|
||||
t.skip("WS", whitespace());
|
||||
const auto tokens = t.tokenize_or_throw("42 100 0");
|
||||
Void::Testing::expect_eq(tokens.size(), std::size_t{3});
|
||||
Void::Testing::expect_eq(tokens[1].value, std::string{"100"});
|
||||
}
|
||||
|
||||
Void::Testing::Test tokenizer_quoted_string_rule()
|
||||
{
|
||||
Tokenizer t;
|
||||
t.add_rule({"STR", quoted_string()});
|
||||
const auto tokens = t.tokenize_or_throw("\"hello world\"");
|
||||
Void::Testing::expect_eq(tokens.size(), std::size_t{1});
|
||||
Void::Testing::expect_eq(tokens[0].value, std::string{"\"hello world\""});
|
||||
}
|
||||
|
||||
Void::Testing::Test tokenizer_quoted_string_with_escape()
|
||||
{
|
||||
Tokenizer t;
|
||||
t.add_rule({"STR", quoted_string()});
|
||||
const auto tokens = t.tokenize_or_throw("\"he\\\"llo\"");
|
||||
Void::Testing::expect_eq(tokens.size(), std::size_t{1});
|
||||
}
|
||||
|
||||
// ── greedy first-match precedence ─────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test tokenizer_keyword_over_ident()
|
||||
{
|
||||
Tokenizer t;
|
||||
t.add_rule({"IF", literal("if")}); // keywords before identifiers
|
||||
t.add_rule({"IDENT", identifier()});
|
||||
t.skip("WS", whitespace());
|
||||
const auto tokens = t.tokenize_or_throw("if foo");
|
||||
Void::Testing::expect_eq(tokens[0].kind, std::string{"IF"});
|
||||
Void::Testing::expect_eq(tokens[1].kind, std::string{"IDENT"});
|
||||
}
|
||||
|
||||
// ── expression tokenization ───────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test tokenizer_expression()
|
||||
{
|
||||
const auto t = make_expr_tokenizer();
|
||||
const auto tokens = t.tokenize_or_throw("(a + b) * 3");
|
||||
Void::Testing::expect_eq(tokens.size(), std::size_t{7});
|
||||
Void::Testing::expect_eq(tokens[0].kind, std::string{"LPAREN"});
|
||||
Void::Testing::expect_eq(tokens[6].kind, std::string{"NUMBER"});
|
||||
}
|
||||
Reference in new issue
Block a user