Files
Library/tests/standalone/Text/Str.cpp
faumarayandClaude Fable 5 28b94883fd 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>
2026-06-12 18:50:02 +03:00

174 lines
6.0 KiB
C++

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