Also fixes Diff/Memo/PriorityQueue from previous session: LineDiff is now an alias for Edit<string> so count_op/apply work on line diffs; Memoized uses std::apply instead of type-based get to handle duplicate arg types. 874/877 tests pass (3 are platform-gated plugin tests). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
91 lines
2.6 KiB
C++
91 lines
2.6 KiB
C++
#include <Void/Lazy/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());
|
|
}
|