#include #include #include #include #include // ── 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> 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> 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); }