Files
Library/tests/standalone/Core/Lazy.cpp
T
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

91 lines
2.6 KiB
C++

#include <Void/Core/Lazy.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <string>
using namespace Void::Lazy;
// ── Lazy<T> ───────────────────────────────────────────────────────────────────
Void::Testing::Test lazy_not_evaluated_on_construction()
{
int calls = 0;
auto lz = make_lazy([&] { ++calls; return 42; });
Void::Testing::expect(!lz.evaluated());
Void::Testing::expect_eq(calls, 0);
}
Void::Testing::Test lazy_evaluates_on_first_get()
{
int calls = 0;
auto lz = make_lazy([&] { ++calls; return 42; });
Void::Testing::expect_eq(*lz, 42);
Void::Testing::expect_eq(calls, 1);
Void::Testing::expect(lz.evaluated());
}
Void::Testing::Test lazy_evaluates_only_once()
{
int calls = 0;
auto lz = make_lazy([&] { ++calls; return 7; });
(void)*lz;
(void)*lz;
(void)*lz;
Void::Testing::expect_eq(calls, 1);
}
Void::Testing::Test lazy_arrow_operator()
{
auto lz = make_lazy([] { return std::string{"hello"}; });
Void::Testing::expect_eq(lz->size(), std::size_t{5});
}
Void::Testing::Test lazy_reset_clears_value()
{
int calls = 0;
auto lz = make_lazy([&] { ++calls; return 1; });
(void)*lz;
lz.reset();
Void::Testing::expect(!lz.evaluated());
(void)*lz;
Void::Testing::expect_eq(calls, 2);
}
Void::Testing::Test lazy_const_access()
{
const auto lz = make_lazy([] { return 99; });
Void::Testing::expect_eq(*lz, 99);
Void::Testing::expect(lz.evaluated());
}
Void::Testing::Test lazy_string_value()
{
auto lz = make_lazy([] { return std::string{"lazy value"}; });
Void::Testing::expect_eq(lz.get(), std::string{"lazy value"});
}
// ── LazySync<T> ───────────────────────────────────────────────────────────────
Void::Testing::Test lazy_sync_evaluates_once()
{
int calls = 0;
auto lz = make_lazy_sync([&] { ++calls; return 55; });
Void::Testing::expect_eq(*lz, 55);
Void::Testing::expect_eq(*lz, 55);
Void::Testing::expect_eq(calls, 1);
}
Void::Testing::Test lazy_sync_arrow_operator()
{
auto lz = make_lazy_sync([] { return std::string{"synced"}; });
Void::Testing::expect_eq(lz->length(), std::size_t{6});
}
Void::Testing::Test lazy_sync_const_access()
{
const auto lz = make_lazy_sync([] { return 123; });
Void::Testing::expect_eq(*lz, 123);
Void::Testing::expect(lz.evaluated());
}