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>
132 lines
4.5 KiB
C++
132 lines
4.5 KiB
C++
#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);
|
|
}
|