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>
50 lines
1.2 KiB
C++
50 lines
1.2 KiB
C++
#include <Void/Functional/Error.hpp>
|
|
#include <Void/Functional/Result.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <string>
|
|
|
|
namespace
|
|
{
|
|
Void::Result::Result<int> parse_int(const std::string& s)
|
|
{
|
|
try {
|
|
return Void::Result::ok(std::stoi(s));
|
|
} catch (...) {
|
|
return Void::Result::fail("not a number");
|
|
}
|
|
}
|
|
|
|
Void::Result::Result<int> doubled(int n) { return Void::Result::ok(n * 2); }
|
|
} // namespace
|
|
|
|
Void::Testing::Test and_then_chains_on_success()
|
|
{
|
|
auto r = parse_int("21").and_then(doubled);
|
|
Void::Testing::expect(r.has_value());
|
|
Void::Testing::expect_eq(*r, 42);
|
|
}
|
|
|
|
Void::Testing::Test and_then_short_circuits_on_failure()
|
|
{
|
|
auto r = parse_int("xyz").and_then(doubled);
|
|
Void::Testing::expect(!r.has_value());
|
|
Void::Testing::expect_eq(r.error().message(), std::string{"not a number"});
|
|
}
|
|
|
|
Void::Testing::Test transform_maps_value()
|
|
{
|
|
auto r = parse_int("3").transform([](int n) { return n + 100; });
|
|
Void::Testing::expect(r.has_value());
|
|
Void::Testing::expect_eq(*r, 103);
|
|
}
|
|
|
|
Void::Testing::Test or_else_recovers_on_failure()
|
|
{
|
|
auto r = parse_int("xyz").or_else(
|
|
[](const Void::Result::Error&) { return Void::Result::ok(0); });
|
|
Void::Testing::expect(r.has_value());
|
|
Void::Testing::expect_eq(*r, 0);
|
|
}
|