Files
Library/tests/standalone/Text/Diff.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

135 lines
4.7 KiB
C++

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