Finish module consolidation: fold Memo into Pipeline, dedupe Channel/Stopwatch
Completes the in-progress merges (Optional->Either/Opt, Curry+Memo->Pipeline,
ScopeGuard->Scope, String->Str):
- Pipeline/Memo.hpp now carries the full Memo API (memoize with recursion
support, TupleHash, SimpleCache) alongside memoize_fn; old Memo module
and its test dir removed.
- Duplicate Channel module removed; Concurrency::Channel gains empty() and
the unique test cases (drain-after-close, multi-producer, string payloads).
- StopWatch module merged into Time::Stopwatch: one class with explicit
start/stop/laps plus a started() factory for the auto-start RAII style;
ScopedTimer moved along.
- Testing optional dep retargeted String->Str (pad_right lives in Str now).
- Stale empty dirs removed: src/{ScopeGuard,String,Core}, include/Void/{Core,
Filesystem,Memo,Channel,StopWatch}.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
58ff7b38a0
commit
da2e93c405
29 files changed
+752
-1593
No files matched your search
@@ -1,144 +0,0 @@
|
||||
#include <Void/Channel/Channel.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
using namespace Void::Channel;
|
||||
|
||||
// ── non-blocking operations ───────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test channel_try_send_recv()
|
||||
{
|
||||
Channel<int> ch{4};
|
||||
Void::Testing::expect(ch.try_send(1));
|
||||
Void::Testing::expect(ch.try_send(2));
|
||||
const auto v = ch.try_recv();
|
||||
Void::Testing::expect(v.has_value());
|
||||
Void::Testing::expect_eq(*v, 1);
|
||||
}
|
||||
|
||||
Void::Testing::Test channel_fifo_order()
|
||||
{
|
||||
Channel<int> ch{8};
|
||||
for (int i = 0; i < 5; ++i) ch.try_send(i);
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
const auto v = ch.try_recv();
|
||||
Void::Testing::expect(v.has_value());
|
||||
Void::Testing::expect_eq(*v, i);
|
||||
}
|
||||
}
|
||||
|
||||
Void::Testing::Test channel_try_send_fails_when_full()
|
||||
{
|
||||
Channel<int> ch{2};
|
||||
Void::Testing::expect(ch.try_send(1));
|
||||
Void::Testing::expect(ch.try_send(2));
|
||||
Void::Testing::expect(!ch.try_send(3)); // full
|
||||
}
|
||||
|
||||
Void::Testing::Test channel_try_recv_empty_returns_nullopt()
|
||||
{
|
||||
Channel<int> ch{4};
|
||||
Void::Testing::expect(!ch.try_recv().has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test channel_size_and_empty()
|
||||
{
|
||||
Channel<int> ch{4};
|
||||
Void::Testing::expect(ch.empty());
|
||||
Void::Testing::expect_eq(ch.size(), std::size_t{0});
|
||||
ch.try_send(1);
|
||||
ch.try_send(2);
|
||||
Void::Testing::expect_eq(ch.size(), std::size_t{2});
|
||||
Void::Testing::expect(!ch.empty());
|
||||
}
|
||||
|
||||
Void::Testing::Test channel_capacity()
|
||||
{
|
||||
Channel<int> ch{16};
|
||||
Void::Testing::expect_eq(ch.capacity(), std::size_t{16});
|
||||
}
|
||||
|
||||
// ── close semantics ───────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test channel_send_after_close_returns_false()
|
||||
{
|
||||
Channel<int> ch{4};
|
||||
ch.close();
|
||||
Void::Testing::expect(!ch.try_send(1));
|
||||
}
|
||||
|
||||
Void::Testing::Test channel_recv_drains_then_nullopt()
|
||||
{
|
||||
Channel<int> ch{4};
|
||||
ch.try_send(10);
|
||||
ch.try_send(20);
|
||||
ch.close();
|
||||
Void::Testing::expect_eq(*ch.try_recv(), 10);
|
||||
Void::Testing::expect_eq(*ch.try_recv(), 20);
|
||||
Void::Testing::expect(!ch.try_recv().has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test channel_closed_flag()
|
||||
{
|
||||
Channel<int> ch{4};
|
||||
Void::Testing::expect(!ch.closed());
|
||||
ch.close();
|
||||
Void::Testing::expect(ch.closed());
|
||||
}
|
||||
|
||||
// ── blocking with threads ─────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test channel_producer_consumer_thread()
|
||||
{
|
||||
Channel<int> ch{16};
|
||||
std::vector<int> received;
|
||||
const int count = 10;
|
||||
|
||||
std::thread producer([&] {
|
||||
for (int i = 0; i < count; ++i) ch.send(i);
|
||||
ch.close();
|
||||
});
|
||||
|
||||
while (auto v = ch.recv())
|
||||
received.push_back(*v);
|
||||
|
||||
producer.join();
|
||||
|
||||
Void::Testing::expect_eq(static_cast<int>(received.size()), count);
|
||||
for (int i = 0; i < count; ++i)
|
||||
Void::Testing::expect_eq(received[i], i);
|
||||
}
|
||||
|
||||
Void::Testing::Test channel_multiple_producers()
|
||||
{
|
||||
Channel<int> ch{64};
|
||||
std::atomic<int> total{0};
|
||||
|
||||
auto producer = [&](int n) {
|
||||
for (int i = 0; i < n; ++i) ch.send(i);
|
||||
};
|
||||
|
||||
std::thread t1(producer, 5);
|
||||
std::thread t2(producer, 5);
|
||||
t1.join();
|
||||
t2.join();
|
||||
ch.close();
|
||||
|
||||
while (auto v = ch.recv()) total += *v;
|
||||
|
||||
// Sum of 0+1+2+3+4 = 10, two producers → 20
|
||||
Void::Testing::expect_eq(total.load(), 20);
|
||||
}
|
||||
|
||||
Void::Testing::Test channel_string_values()
|
||||
{
|
||||
Channel<std::string> ch{4};
|
||||
ch.try_send("hello");
|
||||
ch.try_send("world");
|
||||
Void::Testing::expect_eq(*ch.try_recv(), std::string{"hello"});
|
||||
Void::Testing::expect_eq(*ch.try_recv(), std::string{"world"});
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
@@ -82,3 +84,59 @@ Void::Testing::Test send_returns_false_when_closed()
|
||||
bool ok = ch.send(42);
|
||||
Void::Testing::expect(!ok);
|
||||
}
|
||||
|
||||
Void::Testing::Test size_and_empty()
|
||||
{
|
||||
Channel<int> ch{4};
|
||||
Void::Testing::expect(ch.empty());
|
||||
Void::Testing::expect_eq(ch.size(), std::size_t{0});
|
||||
ch.try_send(1);
|
||||
ch.try_send(2);
|
||||
Void::Testing::expect_eq(ch.size(), std::size_t{2});
|
||||
Void::Testing::expect(!ch.empty());
|
||||
}
|
||||
|
||||
Void::Testing::Test receive_drains_then_nullopt_after_close()
|
||||
{
|
||||
Channel<int> ch{4};
|
||||
ch.try_send(10);
|
||||
ch.try_send(20);
|
||||
ch.close();
|
||||
Void::Testing::expect_eq(*ch.try_receive(), 10);
|
||||
Void::Testing::expect_eq(*ch.try_receive(), 20);
|
||||
Void::Testing::expect(!ch.try_receive().has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test multiple_producers_sum()
|
||||
{
|
||||
Channel<int> ch{64};
|
||||
std::atomic<int> total{0};
|
||||
|
||||
auto producer = [&](int n) {
|
||||
for (int i = 0; i < n; ++i) {
|
||||
ch.send(i);
|
||||
}
|
||||
};
|
||||
|
||||
std::thread t1(producer, 5);
|
||||
std::thread t2(producer, 5);
|
||||
t1.join();
|
||||
t2.join();
|
||||
ch.close();
|
||||
|
||||
while (auto v = ch.receive()) {
|
||||
total += *v;
|
||||
}
|
||||
|
||||
// Sum of 0+1+2+3+4 = 10, two producers → 20
|
||||
Void::Testing::expect_eq(total.load(), 20);
|
||||
}
|
||||
|
||||
Void::Testing::Test string_values_roundtrip()
|
||||
{
|
||||
Channel<std::string> ch{4};
|
||||
ch.try_send("hello");
|
||||
ch.try_send("world");
|
||||
Void::Testing::expect_eq(*ch.try_receive(), std::string{"hello"});
|
||||
Void::Testing::expect_eq(*ch.try_receive(), std::string{"world"});
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
#include <Void/Curry/Curry.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace Void::Curry;
|
||||
|
||||
// ── curry ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test curry_binary_full_apply()
|
||||
{
|
||||
auto add = curry([](int a, int b) { return a + b; });
|
||||
Void::Testing::expect_eq(add(3)(4), 7);
|
||||
}
|
||||
|
||||
Void::Testing::Test curry_binary_partial_then_complete()
|
||||
{
|
||||
auto add = curry([](int a, int b) { return a + b; });
|
||||
auto add10 = add(10);
|
||||
Void::Testing::expect_eq(add10(5), 15);
|
||||
Void::Testing::expect_eq(add10(20), 30);
|
||||
}
|
||||
|
||||
Void::Testing::Test curry_ternary()
|
||||
{
|
||||
auto sum3 = curry([](int a, int b, int c) { return a + b + c; });
|
||||
Void::Testing::expect_eq(sum3(1)(2)(3), 6);
|
||||
}
|
||||
|
||||
Void::Testing::Test curry_ternary_partial_twice()
|
||||
{
|
||||
auto sum3 = curry([](int a, int b, int c) { return a + b + c; });
|
||||
const auto sum3_with_1 = sum3(1);
|
||||
const auto sum3_with_1_2 = sum3_with_1(2);
|
||||
Void::Testing::expect_eq(sum3_with_1_2(10), 13);
|
||||
}
|
||||
|
||||
Void::Testing::Test curry_type_change()
|
||||
{
|
||||
auto prefix = curry([](std::string p, std::string s) { return p + s; });
|
||||
const auto add_hello = prefix(std::string{"hello "});
|
||||
Void::Testing::expect_eq(add_hello(std::string{"world"}), std::string{"hello world"});
|
||||
}
|
||||
|
||||
Void::Testing::Test curry_unary_invokes_immediately()
|
||||
{
|
||||
auto square = curry([](int x) { return x * x; });
|
||||
Void::Testing::expect_eq(square(5), 25);
|
||||
}
|
||||
|
||||
Void::Testing::Test curry_reuse_partial()
|
||||
{
|
||||
auto mul = curry([](int a, int b) { return a * b; });
|
||||
const auto triple = mul(3);
|
||||
Void::Testing::expect_eq(triple(4), 12);
|
||||
Void::Testing::expect_eq(triple(5), 15);
|
||||
Void::Testing::expect_eq(triple(6), 18);
|
||||
}
|
||||
|
||||
Void::Testing::Test curry_with_lambda_capture()
|
||||
{
|
||||
int offset = 100;
|
||||
auto add_offset = curry([&](int a, int b) { return a + b + offset; });
|
||||
Void::Testing::expect_eq(add_offset(1)(2), 103);
|
||||
}
|
||||
@@ -1,13 +1,16 @@
|
||||
#include <Void/Either/Either.hpp>
|
||||
#include <Void/Either/Opt.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
using namespace Void::Either;
|
||||
using E = Either<std::string, int>;
|
||||
|
||||
// ── construction & query ──────────────────────────────────────────────────────
|
||||
// ── Either construction & query ───────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test either_left_is_left()
|
||||
{
|
||||
@@ -25,8 +28,6 @@ Void::Testing::Test either_right_is_right()
|
||||
Void::Testing::expect_eq(e.right_value(), 42);
|
||||
}
|
||||
|
||||
// ── map ───────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test either_map_transforms_right()
|
||||
{
|
||||
const auto e = E::right(5);
|
||||
@@ -51,16 +52,6 @@ Void::Testing::Test either_map_left_transforms_left()
|
||||
Void::Testing::expect_eq(m.left_value(), std::size_t{3});
|
||||
}
|
||||
|
||||
Void::Testing::Test either_map_left_skips_right()
|
||||
{
|
||||
const auto e = E::right(7);
|
||||
const auto m = e.map_left([](const std::string& s) { return s.size(); });
|
||||
Void::Testing::expect(m.is_right());
|
||||
Void::Testing::expect_eq(m.right_value(), 7);
|
||||
}
|
||||
|
||||
// ── fold ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test either_fold_right()
|
||||
{
|
||||
const auto e = E::right(10);
|
||||
@@ -79,20 +70,124 @@ Void::Testing::Test either_fold_left()
|
||||
Void::Testing::expect_eq(v, 4);
|
||||
}
|
||||
|
||||
// ── equality ──────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test either_equality_right()
|
||||
Void::Testing::Test either_swap()
|
||||
{
|
||||
const auto a = E::right(1);
|
||||
const auto b = E::right(1);
|
||||
const auto c = E::right(2);
|
||||
Void::Testing::expect(a == b);
|
||||
Void::Testing::expect(!(a == c));
|
||||
const auto e = E::right(5);
|
||||
const auto s = e.swap();
|
||||
Void::Testing::expect(s.is_left());
|
||||
Void::Testing::expect_eq(s.left_value(), 5);
|
||||
}
|
||||
|
||||
Void::Testing::Test either_equality_left_vs_right()
|
||||
Void::Testing::Test either_equality()
|
||||
{
|
||||
const auto a = E::left("x");
|
||||
const auto b = E::right(0);
|
||||
Void::Testing::expect(!(a == b));
|
||||
Void::Testing::expect(E::right(1) == E::right(1));
|
||||
Void::Testing::expect(!(E::right(1) == E::right(2)));
|
||||
Void::Testing::expect(!(E::left("x") == E::right(0)));
|
||||
}
|
||||
|
||||
// ── Opt<T> ────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test opt_some_has_value()
|
||||
{
|
||||
const auto o = some(42);
|
||||
Void::Testing::expect(o.has_value());
|
||||
Void::Testing::expect_eq(*o, 42);
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_none_empty()
|
||||
{
|
||||
const auto o = none<int>();
|
||||
Void::Testing::expect(!o.has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_map_chain()
|
||||
{
|
||||
const auto r = some(3)
|
||||
.map([](int x) { return x + 1; })
|
||||
.map([](int x) { return x * 2; });
|
||||
Void::Testing::expect_eq(*r, 8);
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_filter_fluent()
|
||||
{
|
||||
Void::Testing::expect(some(10).filter([](int x) { return x > 5; }).has_value());
|
||||
Void::Testing::expect(!some(2).filter([](int x) { return x > 5; }).has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_flat_map_fluent()
|
||||
{
|
||||
const auto r = some(5).flat_map([](int x) -> Opt<std::string> {
|
||||
return some(std::to_string(x));
|
||||
});
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(*r, std::string{"5"});
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_value_or()
|
||||
{
|
||||
Void::Testing::expect_eq(some(7).value_or(0), 7);
|
||||
Void::Testing::expect_eq(none<int>().value_or(99), 99);
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_ok_or_converts_to_either()
|
||||
{
|
||||
const auto r = some(42).ok_or(std::string{"missing"});
|
||||
Void::Testing::expect(r.is_right());
|
||||
Void::Testing::expect_eq(r.right_value(), 42);
|
||||
|
||||
const auto err = none<int>().ok_or(std::string{"missing"});
|
||||
Void::Testing::expect(err.is_left());
|
||||
}
|
||||
|
||||
// ── free optional utilities ───────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test opt_transform_present()
|
||||
{
|
||||
const std::optional<int> o{5};
|
||||
const auto r = opt_transform(o, [](int x) { return x * 2; });
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(*r, 10);
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_transform_empty()
|
||||
{
|
||||
const std::optional<int> o;
|
||||
const auto r = opt_transform(o, [](int x) { return x * 2; });
|
||||
Void::Testing::expect(!r.has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_filter_free()
|
||||
{
|
||||
const std::optional<int> o{10};
|
||||
Void::Testing::expect(opt_filter(o, [](int x) { return x > 5; }).has_value());
|
||||
Void::Testing::expect(!opt_filter(o, [](int x) { return x > 15; }).has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_expect_throws_on_empty()
|
||||
{
|
||||
const std::optional<int> o;
|
||||
bool threw = false;
|
||||
try { [[maybe_unused]] auto v = opt_expect(o, "empty"); } catch (...) { threw = true; }
|
||||
Void::Testing::expect(threw);
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_zip_both_present()
|
||||
{
|
||||
const auto r = opt_zip(std::optional<int>{1}, std::optional<std::string>{"hi"});
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(r->first, 1);
|
||||
Void::Testing::expect_eq(r->second, std::string{"hi"});
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_zip_one_empty()
|
||||
{
|
||||
const auto r = opt_zip(std::optional<int>{1}, std::optional<int>{});
|
||||
Void::Testing::expect(!r.has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_flatten_nested()
|
||||
{
|
||||
const std::optional<std::optional<int>> o{std::optional<int>{7}};
|
||||
Void::Testing::expect_eq(*opt_flatten(o), 7);
|
||||
Void::Testing::expect(!opt_flatten(std::optional<std::optional<int>>{std::optional<int>{}}).has_value());
|
||||
}
|
||||
@@ -1,168 +0,0 @@
|
||||
#include <Void/Optional/Optional.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
using namespace Void::Optional;
|
||||
|
||||
// ── free functions ────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test opt_transform_present()
|
||||
{
|
||||
const std::optional<int> o{5};
|
||||
const auto r = transform(o, [](int x) { return x * 2; });
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(*r, 10);
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_transform_empty()
|
||||
{
|
||||
const std::optional<int> o;
|
||||
const auto r = transform(o, [](int x) { return x * 2; });
|
||||
Void::Testing::expect(!r.has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_and_then_chain()
|
||||
{
|
||||
const std::optional<int> o{4};
|
||||
const auto r = and_then(o, [](int x) -> std::optional<std::string> {
|
||||
if (x > 0) return std::to_string(x);
|
||||
return std::nullopt;
|
||||
});
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(*r, std::string{"4"});
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_and_then_short_circuits()
|
||||
{
|
||||
const std::optional<int> o;
|
||||
bool called = false;
|
||||
const auto r = and_then(o, [&](int) -> std::optional<int> { called = true; return 1; });
|
||||
Void::Testing::expect(!called);
|
||||
Void::Testing::expect(!r.has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_filter_passes()
|
||||
{
|
||||
const std::optional<int> o{10};
|
||||
const auto r = filter(o, [](int x) { return x > 5; });
|
||||
Void::Testing::expect(r.has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_filter_blocks()
|
||||
{
|
||||
const std::optional<int> o{3};
|
||||
const auto r = filter(o, [](int x) { return x > 5; });
|
||||
Void::Testing::expect(!r.has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_expect_present()
|
||||
{
|
||||
const std::optional<int> o{42};
|
||||
Void::Testing::expect_eq(expect(o), 42);
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_expect_throws_on_empty()
|
||||
{
|
||||
const std::optional<int> o;
|
||||
bool threw = false;
|
||||
try { [[maybe_unused]] auto v = expect(o, "must have value"); } catch (...) { threw = true; }
|
||||
Void::Testing::expect(threw);
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_zip_both_present()
|
||||
{
|
||||
const std::optional<int> a{1};
|
||||
const std::optional<std::string> b{"hello"};
|
||||
const auto r = zip(a, b);
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(r->first, 1);
|
||||
Void::Testing::expect_eq(r->second, std::string{"hello"});
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_zip_one_empty()
|
||||
{
|
||||
const std::optional<int> a{1};
|
||||
const std::optional<int> b;
|
||||
const auto r = zip(a, b);
|
||||
Void::Testing::expect(!r.has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_flatten()
|
||||
{
|
||||
const std::optional<std::optional<int>> o{std::optional<int>{7}};
|
||||
const auto r = flatten(o);
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(*r, 7);
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_flatten_inner_empty()
|
||||
{
|
||||
const std::optional<std::optional<int>> o{std::optional<int>{}};
|
||||
Void::Testing::expect(!flatten(o).has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_or_else_calls_on_empty()
|
||||
{
|
||||
const std::optional<int> o;
|
||||
const auto r = or_else(o, [] { return std::optional<int>{99}; });
|
||||
Void::Testing::expect_eq(*r, 99);
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_or_else_skips_on_present()
|
||||
{
|
||||
const std::optional<int> o{5};
|
||||
bool called = false;
|
||||
const auto r = or_else(o, [&] { called = true; return std::optional<int>{99}; });
|
||||
Void::Testing::expect(!called);
|
||||
Void::Testing::expect_eq(*r, 5);
|
||||
}
|
||||
|
||||
// ── Opt<T> fluent wrapper ─────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test opt_some_has_value()
|
||||
{
|
||||
const auto o = some(42);
|
||||
Void::Testing::expect(o.has_value());
|
||||
Void::Testing::expect_eq(*o, 42);
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_none_empty()
|
||||
{
|
||||
const auto o = none<int>();
|
||||
Void::Testing::expect(!o.has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_map_chain()
|
||||
{
|
||||
const auto r = some(3)
|
||||
.map([](int x) { return x + 1; })
|
||||
.map([](int x) { return x * 2; });
|
||||
Void::Testing::expect_eq(*r, 8);
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_filter_fluent()
|
||||
{
|
||||
const auto r = some(10).filter([](int x) { return x > 5; });
|
||||
Void::Testing::expect(r.has_value());
|
||||
const auto r2 = some(2).filter([](int x) { return x > 5; });
|
||||
Void::Testing::expect(!r2.has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_flat_map_fluent()
|
||||
{
|
||||
const auto r = some(5).flat_map([](int x) -> Opt<std::string> {
|
||||
return some(std::to_string(x));
|
||||
});
|
||||
Void::Testing::expect(r.has_value());
|
||||
Void::Testing::expect_eq(*r, std::string{"5"});
|
||||
}
|
||||
|
||||
Void::Testing::Test opt_value_or()
|
||||
{
|
||||
Void::Testing::expect_eq(some(7).value_or(0), 7);
|
||||
Void::Testing::expect_eq(none<int>().value_or(99), 99);
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
#include <Void/Memo/Memo.hpp>
|
||||
#include <Void/Pipeline/Memo.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
using namespace Void::Memo;
|
||||
using namespace Void::Pipeline;
|
||||
|
||||
// ── Memoized ──────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include <Void/Pipeline/Curry.hpp>
|
||||
#include <Void/Pipeline/Memo.hpp>
|
||||
#include <Void/Pipeline/Pipeline.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
@@ -31,26 +33,12 @@ Void::Testing::Test pipe_type_change()
|
||||
Void::Testing::expect_eq(result, std::string{"[42]"});
|
||||
}
|
||||
|
||||
Void::Testing::Test pipe_get_accessor()
|
||||
{
|
||||
auto p = pipe(99);
|
||||
Void::Testing::expect_eq(p.get(), 99);
|
||||
}
|
||||
|
||||
Void::Testing::Test pipe_implicit_conversion()
|
||||
{
|
||||
int v = pipe(7) | [](int x) { return x + 1; };
|
||||
Void::Testing::expect_eq(v, 8);
|
||||
}
|
||||
|
||||
Void::Testing::Test pipe_string_chain()
|
||||
{
|
||||
const std::string result = pipe(std::string{"hello"})
|
||||
| [](std::string s) { s += " world"; return s; }
|
||||
| [](std::string s) { s[0] = 'H'; return s; };
|
||||
Void::Testing::expect_eq(result, std::string{"Hello world"});
|
||||
}
|
||||
|
||||
// ── compose ───────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test compose_two()
|
||||
@@ -115,3 +103,78 @@ Void::Testing::Test constant_ignores_args()
|
||||
Void::Testing::expect_eq(always5(), 5);
|
||||
Void::Testing::expect_eq(always5(1, 2, 3), 5);
|
||||
}
|
||||
|
||||
// ── negate ────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test negate_predicate()
|
||||
{
|
||||
auto is_positive = [](int x) { return x > 0; };
|
||||
auto is_non_positive = negate(is_positive);
|
||||
Void::Testing::expect(!is_non_positive(5));
|
||||
Void::Testing::expect(is_non_positive(-3));
|
||||
Void::Testing::expect(is_non_positive(0));
|
||||
}
|
||||
|
||||
// ── curry ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test curry_binary_full_apply()
|
||||
{
|
||||
auto add = curry([](int a, int b) { return a + b; });
|
||||
Void::Testing::expect_eq(add(3)(4), 7);
|
||||
}
|
||||
|
||||
Void::Testing::Test curry_binary_partial_then_complete()
|
||||
{
|
||||
auto add = curry([](int a, int b) { return a + b; });
|
||||
auto add10 = add(10);
|
||||
Void::Testing::expect_eq(add10(5), 15);
|
||||
Void::Testing::expect_eq(add10(20), 30);
|
||||
}
|
||||
|
||||
Void::Testing::Test curry_ternary()
|
||||
{
|
||||
auto sum3 = curry([](int a, int b, int c) { return a + b + c; });
|
||||
Void::Testing::expect_eq(sum3(1)(2)(3), 6);
|
||||
}
|
||||
|
||||
Void::Testing::Test curry_type_change()
|
||||
{
|
||||
auto prefix = curry([](std::string p, std::string s) { return p + s; });
|
||||
const auto add_hello = prefix(std::string{"hello "});
|
||||
Void::Testing::expect_eq(add_hello(std::string{"world"}), std::string{"hello world"});
|
||||
}
|
||||
|
||||
Void::Testing::Test curry_unary_invokes_immediately()
|
||||
{
|
||||
auto square = curry([](int x) { return x * x; });
|
||||
Void::Testing::expect_eq(square(5), 25);
|
||||
}
|
||||
|
||||
Void::Testing::Test curry_reuse_partial()
|
||||
{
|
||||
auto mul = curry([](int a, int b) { return a * b; });
|
||||
const auto triple = mul(3);
|
||||
Void::Testing::expect_eq(triple(4), 12);
|
||||
Void::Testing::expect_eq(triple(5), 15);
|
||||
}
|
||||
|
||||
// ── memoize_fn ────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test memoize_fn_caches_result()
|
||||
{
|
||||
int call_count = 0;
|
||||
auto fn = memoize_fn<int>([&](int x) { ++call_count; return x * x; });
|
||||
fn(5);
|
||||
fn(5);
|
||||
fn(5);
|
||||
Void::Testing::expect_eq(call_count, 1);
|
||||
fn(6);
|
||||
Void::Testing::expect_eq(call_count, 2);
|
||||
}
|
||||
|
||||
Void::Testing::Test memoize_fn_correct_result()
|
||||
{
|
||||
auto sq = memoize_fn<int>([](int x) { return x * x; });
|
||||
Void::Testing::expect_eq(sq(4), 16);
|
||||
Void::Testing::expect_eq(sq(7), 49);
|
||||
}
|
||||
@@ -5,13 +5,15 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
using namespace Void::Scope;
|
||||
|
||||
// ── on_exit ───────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test on_exit_runs_on_normal_exit()
|
||||
{
|
||||
bool ran = false;
|
||||
{
|
||||
auto guard = Void::Scope::on_exit([&] { ran = true; });
|
||||
auto guard = on_exit([&] { ran = true; });
|
||||
}
|
||||
Void::Testing::expect(ran);
|
||||
}
|
||||
@@ -20,7 +22,7 @@ Void::Testing::Test on_exit_runs_on_exception()
|
||||
{
|
||||
bool ran = false;
|
||||
try {
|
||||
auto guard = Void::Scope::on_exit([&] { ran = true; });
|
||||
auto guard = on_exit([&] { ran = true; });
|
||||
throw std::runtime_error{"test"};
|
||||
} catch (...) {}
|
||||
Void::Testing::expect(ran);
|
||||
@@ -30,31 +32,82 @@ Void::Testing::Test on_exit_release_prevents_run()
|
||||
{
|
||||
bool ran = false;
|
||||
{
|
||||
auto guard = Void::Scope::on_exit([&] { ran = true; });
|
||||
auto guard = on_exit([&] { ran = true; });
|
||||
guard.release();
|
||||
}
|
||||
Void::Testing::expect(!ran);
|
||||
}
|
||||
|
||||
Void::Testing::Test on_exit_dismiss_prevents_run()
|
||||
{
|
||||
bool ran = false;
|
||||
{
|
||||
auto guard = on_exit([&] { ran = true; });
|
||||
guard.dismiss();
|
||||
}
|
||||
Void::Testing::expect(!ran);
|
||||
}
|
||||
|
||||
Void::Testing::Test on_exit_active_reflects_state()
|
||||
{
|
||||
auto guard = on_exit([] {});
|
||||
Void::Testing::expect(guard.active());
|
||||
guard.dismiss();
|
||||
Void::Testing::expect(!guard.active());
|
||||
}
|
||||
|
||||
Void::Testing::Test on_exit_move_transfers_ownership()
|
||||
{
|
||||
int called = 0;
|
||||
{
|
||||
auto g1 = on_exit([&] { ++called; });
|
||||
auto g2 = std::move(g1);
|
||||
Void::Testing::expect(!g1.active());
|
||||
Void::Testing::expect(g2.active());
|
||||
}
|
||||
Void::Testing::expect_eq(called, 1);
|
||||
}
|
||||
|
||||
Void::Testing::Test on_exit_lifo_order()
|
||||
{
|
||||
std::string order;
|
||||
{
|
||||
auto a = Void::Scope::on_exit([&] { order += "A"; });
|
||||
auto b = Void::Scope::on_exit([&] { order += "B"; });
|
||||
auto c = Void::Scope::on_exit([&] { order += "C"; });
|
||||
auto a = on_exit([&] { order += "A"; });
|
||||
auto b = on_exit([&] { order += "B"; });
|
||||
auto c = on_exit([&] { order += "C"; });
|
||||
}
|
||||
Void::Testing::expect_eq(order, std::string{"CBA"});
|
||||
}
|
||||
|
||||
Void::Testing::Test on_exit_captures_by_ref()
|
||||
Void::Testing::Test on_exit_multiple_guards_lifo()
|
||||
{
|
||||
int count = 0;
|
||||
int order = 0, a = 0, b = 0;
|
||||
{
|
||||
auto guard = Void::Scope::on_exit([&] { count += 10; });
|
||||
count = 5;
|
||||
auto ga = on_exit([&] { a = ++order; });
|
||||
auto gb = on_exit([&] { b = ++order; });
|
||||
}
|
||||
Void::Testing::expect_eq(count, 15);
|
||||
Void::Testing::expect(b < a);
|
||||
}
|
||||
|
||||
Void::Testing::Test on_exit_resource_cleanup()
|
||||
{
|
||||
bool released = false;
|
||||
{
|
||||
int handle = 42;
|
||||
auto cleanup = on_exit([&] { if (handle) released = true; });
|
||||
(void)handle;
|
||||
}
|
||||
Void::Testing::expect(released);
|
||||
}
|
||||
|
||||
Void::Testing::Test on_exit_conditional_commit()
|
||||
{
|
||||
int value = 10;
|
||||
{
|
||||
auto rollback = on_exit([&] { value = 0; });
|
||||
rollback.dismiss();
|
||||
}
|
||||
Void::Testing::expect_eq(value, 10);
|
||||
}
|
||||
|
||||
// ── on_success ────────────────────────────────────────────────────────────────
|
||||
@@ -63,7 +116,7 @@ Void::Testing::Test on_success_runs_on_normal_exit()
|
||||
{
|
||||
bool ran = false;
|
||||
{
|
||||
auto guard = Void::Scope::on_success([&] { ran = true; });
|
||||
auto guard = on_success([&] { ran = true; });
|
||||
}
|
||||
Void::Testing::expect(ran);
|
||||
}
|
||||
@@ -72,7 +125,7 @@ Void::Testing::Test on_success_does_not_run_on_exception()
|
||||
{
|
||||
bool ran = false;
|
||||
try {
|
||||
auto guard = Void::Scope::on_success([&] { ran = true; });
|
||||
auto guard = on_success([&] { ran = true; });
|
||||
throw std::runtime_error{"test"};
|
||||
} catch (...) {}
|
||||
Void::Testing::expect(!ran);
|
||||
@@ -82,7 +135,7 @@ Void::Testing::Test on_success_release_prevents_run()
|
||||
{
|
||||
bool ran = false;
|
||||
{
|
||||
auto guard = Void::Scope::on_success([&] { ran = true; });
|
||||
auto guard = on_success([&] { ran = true; });
|
||||
guard.release();
|
||||
}
|
||||
Void::Testing::expect(!ran);
|
||||
@@ -94,7 +147,7 @@ Void::Testing::Test on_fail_does_not_run_on_normal_exit()
|
||||
{
|
||||
bool ran = false;
|
||||
{
|
||||
auto guard = Void::Scope::on_fail([&] { ran = true; });
|
||||
auto guard = on_fail([&] { ran = true; });
|
||||
}
|
||||
Void::Testing::expect(!ran);
|
||||
}
|
||||
@@ -103,7 +156,7 @@ Void::Testing::Test on_fail_runs_on_exception()
|
||||
{
|
||||
bool ran = false;
|
||||
try {
|
||||
auto guard = Void::Scope::on_fail([&] { ran = true; });
|
||||
auto guard = on_fail([&] { ran = true; });
|
||||
throw std::runtime_error{"test"};
|
||||
} catch (...) {}
|
||||
Void::Testing::expect(ran);
|
||||
@@ -113,9 +166,39 @@ Void::Testing::Test on_fail_release_prevents_run()
|
||||
{
|
||||
bool ran = false;
|
||||
try {
|
||||
auto guard = Void::Scope::on_fail([&] { ran = true; });
|
||||
auto guard = on_fail([&] { ran = true; });
|
||||
guard.release();
|
||||
throw std::runtime_error{"test"};
|
||||
} catch (...) {}
|
||||
Void::Testing::expect(!ran);
|
||||
}
|
||||
|
||||
// ── scope_exit / scope_success / scope_failure aliases ───────────────────────
|
||||
|
||||
Void::Testing::Test scope_exit_alias_fires()
|
||||
{
|
||||
int called = 0;
|
||||
{
|
||||
auto g = scope_exit([&] { ++called; });
|
||||
}
|
||||
Void::Testing::expect_eq(called, 1);
|
||||
}
|
||||
|
||||
Void::Testing::Test scope_success_alias_fires_on_normal()
|
||||
{
|
||||
int called = 0;
|
||||
{
|
||||
auto g = scope_success([&] { ++called; });
|
||||
}
|
||||
Void::Testing::expect_eq(called, 1);
|
||||
}
|
||||
|
||||
Void::Testing::Test scope_failure_alias_fires_on_exception()
|
||||
{
|
||||
int called = 0;
|
||||
try {
|
||||
auto g = scope_failure([&] { ++called; });
|
||||
throw std::runtime_error{"x"};
|
||||
} catch (...) {}
|
||||
Void::Testing::expect_eq(called, 1);
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
#include <Void/ScopeGuard/ScopeGuard.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace Void::ScopeGuard;
|
||||
|
||||
// ── scope_exit ────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test scope_exit_fires_on_normal_exit()
|
||||
{
|
||||
int called = 0;
|
||||
{
|
||||
auto g = scope_exit([&] { ++called; });
|
||||
}
|
||||
Void::Testing::expect_eq(called, 1);
|
||||
}
|
||||
|
||||
Void::Testing::Test scope_exit_fires_on_exception()
|
||||
{
|
||||
int called = 0;
|
||||
try {
|
||||
auto g = scope_exit([&] { ++called; });
|
||||
throw std::runtime_error{"oops"};
|
||||
} catch (...) {}
|
||||
Void::Testing::expect_eq(called, 1);
|
||||
}
|
||||
|
||||
Void::Testing::Test scope_exit_dismiss_prevents_call()
|
||||
{
|
||||
int called = 0;
|
||||
{
|
||||
auto g = scope_exit([&] { ++called; });
|
||||
g.dismiss();
|
||||
}
|
||||
Void::Testing::expect_eq(called, 0);
|
||||
}
|
||||
|
||||
Void::Testing::Test scope_exit_active_reflects_state()
|
||||
{
|
||||
auto g = scope_exit([] {});
|
||||
Void::Testing::expect(g.active());
|
||||
g.dismiss();
|
||||
Void::Testing::expect(!g.active());
|
||||
}
|
||||
|
||||
Void::Testing::Test scope_exit_move_transfers_ownership()
|
||||
{
|
||||
int called = 0;
|
||||
{
|
||||
auto g1 = scope_exit([&] { ++called; });
|
||||
auto g2 = std::move(g1);
|
||||
Void::Testing::expect(!g1.active());
|
||||
Void::Testing::expect(g2.active());
|
||||
}
|
||||
Void::Testing::expect_eq(called, 1);
|
||||
}
|
||||
|
||||
Void::Testing::Test scope_exit_multiple_guards()
|
||||
{
|
||||
int order = 0, a = 0, b = 0;
|
||||
{
|
||||
auto ga = scope_exit([&] { a = ++order; });
|
||||
auto gb = scope_exit([&] { b = ++order; });
|
||||
}
|
||||
// gb fires before ga (LIFO destruction)
|
||||
Void::Testing::expect(b < a);
|
||||
}
|
||||
|
||||
// ── scope_success ─────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test scope_success_fires_on_normal_exit()
|
||||
{
|
||||
int called = 0;
|
||||
{
|
||||
auto g = scope_success([&] { ++called; });
|
||||
}
|
||||
Void::Testing::expect_eq(called, 1);
|
||||
}
|
||||
|
||||
Void::Testing::Test scope_success_does_not_fire_on_exception()
|
||||
{
|
||||
int called = 0;
|
||||
try {
|
||||
auto g = scope_success([&] { ++called; });
|
||||
throw std::runtime_error{"oops"};
|
||||
} catch (...) {}
|
||||
Void::Testing::expect_eq(called, 0);
|
||||
}
|
||||
|
||||
// ── scope_failure ─────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test scope_failure_does_not_fire_on_normal_exit()
|
||||
{
|
||||
int called = 0;
|
||||
{
|
||||
auto g = scope_failure([&] { ++called; });
|
||||
}
|
||||
Void::Testing::expect_eq(called, 0);
|
||||
}
|
||||
|
||||
Void::Testing::Test scope_failure_fires_on_exception()
|
||||
{
|
||||
int called = 0;
|
||||
try {
|
||||
auto g = scope_failure([&] { ++called; });
|
||||
throw std::runtime_error{"oops"};
|
||||
} catch (...) {}
|
||||
Void::Testing::expect_eq(called, 1);
|
||||
}
|
||||
|
||||
// ── practical usage ───────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test scope_exit_resource_cleanup()
|
||||
{
|
||||
bool released = false;
|
||||
auto acquire = [&]() -> int { return 42; };
|
||||
{
|
||||
int handle = acquire();
|
||||
auto cleanup = scope_exit([&] { if (handle) released = true; });
|
||||
(void)handle;
|
||||
}
|
||||
Void::Testing::expect(released);
|
||||
}
|
||||
|
||||
Void::Testing::Test scope_exit_conditional_commit()
|
||||
{
|
||||
int value = 0;
|
||||
bool committed = false;
|
||||
{
|
||||
value = 10;
|
||||
auto rollback = scope_exit([&] { value = 0; });
|
||||
// Simulate successful operation — commit.
|
||||
committed = true;
|
||||
if (committed) rollback.dismiss();
|
||||
}
|
||||
Void::Testing::expect_eq(value, 10);
|
||||
}
|
||||
@@ -1,186 +0,0 @@
|
||||
#include <Void/String/String.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
// ── trim ─────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test trim_removes_leading_and_trailing_spaces()
|
||||
{
|
||||
Void::Testing::expect_eq(
|
||||
std::string{Void::String::trim(" hello ")},
|
||||
std::string{"hello"});
|
||||
}
|
||||
|
||||
Void::Testing::Test trim_leaves_interior_whitespace()
|
||||
{
|
||||
Void::Testing::expect_eq(
|
||||
std::string{Void::String::trim(" a b ")},
|
||||
std::string{"a b"});
|
||||
}
|
||||
|
||||
Void::Testing::Test trim_empty_string_stays_empty()
|
||||
{
|
||||
Void::Testing::expect(Void::String::trim("").empty());
|
||||
}
|
||||
|
||||
Void::Testing::Test trim_only_whitespace_returns_empty()
|
||||
{
|
||||
Void::Testing::expect(Void::String::trim(" \t\n ").empty());
|
||||
}
|
||||
|
||||
Void::Testing::Test trim_left_only_removes_prefix()
|
||||
{
|
||||
Void::Testing::expect_eq(
|
||||
std::string{Void::String::trim_left(" hi ")},
|
||||
std::string{"hi "});
|
||||
}
|
||||
|
||||
Void::Testing::Test trim_right_only_removes_suffix()
|
||||
{
|
||||
Void::Testing::expect_eq(
|
||||
std::string{Void::String::trim_right(" hi ")},
|
||||
std::string{" hi"});
|
||||
}
|
||||
|
||||
// ── split ─────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test split_char_produces_correct_parts()
|
||||
{
|
||||
const auto parts = Void::String::split("a,b,c", ',');
|
||||
Void::Testing::expect_eq(parts.size(), std::size_t{3});
|
||||
Void::Testing::expect_eq(std::string{parts[0]}, std::string{"a"});
|
||||
Void::Testing::expect_eq(std::string{parts[1]}, std::string{"b"});
|
||||
Void::Testing::expect_eq(std::string{parts[2]}, std::string{"c"});
|
||||
}
|
||||
|
||||
Void::Testing::Test split_char_preserves_empty_tokens()
|
||||
{
|
||||
const auto parts = Void::String::split("a,,b", ',');
|
||||
Void::Testing::expect_eq(parts.size(), std::size_t{3});
|
||||
Void::Testing::expect(parts[1].empty());
|
||||
}
|
||||
|
||||
Void::Testing::Test split_char_no_delimiter_returns_whole_string()
|
||||
{
|
||||
const auto parts = Void::String::split("hello", ',');
|
||||
Void::Testing::expect_eq(parts.size(), std::size_t{1});
|
||||
Void::Testing::expect_eq(std::string{parts[0]}, std::string{"hello"});
|
||||
}
|
||||
|
||||
Void::Testing::Test split_string_delimiter_works()
|
||||
{
|
||||
const auto parts = Void::String::split("a::b::c", "::");
|
||||
Void::Testing::expect_eq(parts.size(), std::size_t{3});
|
||||
Void::Testing::expect_eq(std::string{parts[1]}, std::string{"b"});
|
||||
}
|
||||
|
||||
Void::Testing::Test split_empty_delimiter_returns_whole()
|
||||
{
|
||||
const auto parts = Void::String::split("abc", "");
|
||||
Void::Testing::expect_eq(parts.size(), std::size_t{1});
|
||||
}
|
||||
|
||||
// ── join ──────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test join_vector_of_string_view()
|
||||
{
|
||||
const std::vector<std::string_view> parts{"a", "b", "c"};
|
||||
Void::Testing::expect_eq(Void::String::join(parts, ", "),
|
||||
std::string{"a, b, c"});
|
||||
}
|
||||
|
||||
Void::Testing::Test join_single_element_no_separator()
|
||||
{
|
||||
const std::vector<std::string_view> parts{"only"};
|
||||
Void::Testing::expect_eq(Void::String::join(parts, "-"),
|
||||
std::string{"only"});
|
||||
}
|
||||
|
||||
Void::Testing::Test join_empty_range_returns_empty()
|
||||
{
|
||||
const std::vector<std::string_view> parts;
|
||||
Void::Testing::expect(Void::String::join(parts, ",").empty());
|
||||
}
|
||||
|
||||
// ── case ──────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test to_lower_converts_ascii()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::String::to_lower("Hello World"),
|
||||
std::string{"hello world"});
|
||||
}
|
||||
|
||||
Void::Testing::Test to_upper_converts_ascii()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::String::to_upper("Hello World"),
|
||||
std::string{"HELLO WORLD"});
|
||||
}
|
||||
|
||||
// ── replace_all ───────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test replace_all_replaces_all_occurrences()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::String::replace_all("aXbXc", "X", "--"),
|
||||
std::string{"a--b--c"});
|
||||
}
|
||||
|
||||
Void::Testing::Test replace_all_with_empty_from_returns_original()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::String::replace_all("abc", "", "x"),
|
||||
std::string{"abc"});
|
||||
}
|
||||
|
||||
Void::Testing::Test replace_all_no_match_returns_original()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::String::replace_all("abc", "z", "x"),
|
||||
std::string{"abc"});
|
||||
}
|
||||
|
||||
// ── pad ───────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test pad_right_pads_to_width()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::String::pad_right("hi", 5),
|
||||
std::string{"hi "});
|
||||
}
|
||||
|
||||
Void::Testing::Test pad_right_no_op_when_already_wide()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::String::pad_right("hello", 3),
|
||||
std::string{"hello"});
|
||||
}
|
||||
|
||||
Void::Testing::Test pad_left_pads_to_width()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::String::pad_left("hi", 5),
|
||||
std::string{" hi"});
|
||||
}
|
||||
|
||||
// ── misc ──────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test repeat_produces_correct_output()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::String::repeat("ab", 3),
|
||||
std::string{"ababab"});
|
||||
}
|
||||
|
||||
Void::Testing::Test repeat_zero_returns_empty()
|
||||
{
|
||||
Void::Testing::expect(Void::String::repeat("ab", 0).empty());
|
||||
}
|
||||
|
||||
Void::Testing::Test count_occurrences_finds_all()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::String::count_occurrences("abab", "ab"),
|
||||
std::size_t{2});
|
||||
}
|
||||
|
||||
Void::Testing::Test count_occurrences_no_match_returns_zero()
|
||||
{
|
||||
Void::Testing::expect_eq(Void::String::count_occurrences("abc", "x"),
|
||||
std::size_t{0});
|
||||
}
|
||||
@@ -1,30 +1,31 @@
|
||||
#include <Void/StopWatch/StopWatch.hpp>
|
||||
#include <Void/Time/Stopwatch.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <thread>
|
||||
|
||||
using namespace Void::StopWatch;
|
||||
using namespace Void::Time;
|
||||
using Duration = Void::Time::Stopwatch::Duration;
|
||||
|
||||
// ── StopWatch ─────────────────────────────────────────────────────────────────
|
||||
// ── Stopwatch ─────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test stopwatch_not_running_initially()
|
||||
{
|
||||
StopWatch sw;
|
||||
Stopwatch sw;
|
||||
Void::Testing::expect(!sw.is_running());
|
||||
Void::Testing::expect_eq(sw.elapsed(), Duration::zero());
|
||||
}
|
||||
|
||||
Void::Testing::Test stopwatch_start_sets_running()
|
||||
{
|
||||
StopWatch sw;
|
||||
Stopwatch sw;
|
||||
sw.start();
|
||||
Void::Testing::expect(sw.is_running());
|
||||
}
|
||||
|
||||
Void::Testing::Test stopwatch_elapsed_increases_while_running()
|
||||
{
|
||||
StopWatch sw;
|
||||
Stopwatch sw;
|
||||
sw.start();
|
||||
const auto first = sw.elapsed();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{5});
|
||||
@@ -34,7 +35,7 @@ Void::Testing::Test stopwatch_elapsed_increases_while_running()
|
||||
|
||||
Void::Testing::Test stopwatch_stop_returns_elapsed()
|
||||
{
|
||||
StopWatch sw;
|
||||
Stopwatch sw;
|
||||
sw.start();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{5});
|
||||
const Duration d = sw.stop();
|
||||
@@ -44,7 +45,7 @@ Void::Testing::Test stopwatch_stop_returns_elapsed()
|
||||
|
||||
Void::Testing::Test stopwatch_elapsed_ms()
|
||||
{
|
||||
StopWatch sw;
|
||||
Stopwatch sw;
|
||||
sw.start();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{5});
|
||||
sw.stop();
|
||||
@@ -53,7 +54,7 @@ Void::Testing::Test stopwatch_elapsed_ms()
|
||||
|
||||
Void::Testing::Test stopwatch_lap_count()
|
||||
{
|
||||
StopWatch sw;
|
||||
Stopwatch sw;
|
||||
sw.start();
|
||||
sw.lap();
|
||||
sw.lap();
|
||||
@@ -63,7 +64,7 @@ Void::Testing::Test stopwatch_lap_count()
|
||||
|
||||
Void::Testing::Test stopwatch_lap_durations_sum_to_elapsed()
|
||||
{
|
||||
StopWatch sw;
|
||||
Stopwatch sw;
|
||||
sw.start();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{2});
|
||||
sw.lap();
|
||||
@@ -80,7 +81,7 @@ Void::Testing::Test stopwatch_lap_durations_sum_to_elapsed()
|
||||
|
||||
Void::Testing::Test stopwatch_reset_clears_state()
|
||||
{
|
||||
StopWatch sw;
|
||||
Stopwatch sw;
|
||||
sw.start();
|
||||
sw.lap();
|
||||
sw.stop();
|
||||
@@ -92,7 +93,7 @@ Void::Testing::Test stopwatch_reset_clears_state()
|
||||
|
||||
Void::Testing::Test stopwatch_restart_clears_laps()
|
||||
{
|
||||
StopWatch sw;
|
||||
Stopwatch sw;
|
||||
sw.start();
|
||||
sw.lap();
|
||||
sw.stop();
|
||||
@@ -102,7 +103,7 @@ Void::Testing::Test stopwatch_restart_clears_laps()
|
||||
|
||||
Void::Testing::Test stopwatch_stopped_elapsed_does_not_grow()
|
||||
{
|
||||
StopWatch sw;
|
||||
Stopwatch sw;
|
||||
sw.start();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{5});
|
||||
sw.stop();
|
||||
@@ -11,36 +11,36 @@
|
||||
|
||||
Void::Testing::Test stopwatch_elapsed_is_non_negative()
|
||||
{
|
||||
Void::Time::Stopwatch sw;
|
||||
auto sw = Void::Time::Stopwatch::started();
|
||||
Void::Testing::expect(sw.elapsed().count() >= 0);
|
||||
}
|
||||
|
||||
Void::Testing::Test stopwatch_elapsed_as_milliseconds()
|
||||
{
|
||||
Void::Time::Stopwatch sw;
|
||||
auto sw = Void::Time::Stopwatch::started();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{5});
|
||||
const auto ms = sw.elapsed_as<std::chrono::milliseconds>().count();
|
||||
Void::Testing::expect(ms >= 4);
|
||||
Void::Testing::expect(ms < 500);
|
||||
}
|
||||
|
||||
Void::Testing::Test stopwatch_reset_restarts_from_zero()
|
||||
Void::Testing::Test stopwatch_restart_starts_from_zero()
|
||||
{
|
||||
Void::Time::Stopwatch sw;
|
||||
auto sw = Void::Time::Stopwatch::started();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{5});
|
||||
sw.reset();
|
||||
sw.start();
|
||||
const auto ns = sw.elapsed().count();
|
||||
Void::Testing::expect(ns < 5'000'000); // < 5ms since reset
|
||||
Void::Testing::expect(ns < 5'000'000); // < 5ms since restart
|
||||
}
|
||||
|
||||
Void::Testing::Test stopwatch_split_returns_elapsed_and_resets()
|
||||
Void::Testing::Test stopwatch_split_returns_elapsed_and_restarts()
|
||||
{
|
||||
Void::Time::Stopwatch sw;
|
||||
auto sw = Void::Time::Stopwatch::started();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{5});
|
||||
const auto d = sw.split();
|
||||
const auto after = sw.elapsed().count();
|
||||
Void::Testing::expect(d.count() >= 0);
|
||||
Void::Testing::expect(after < d.count()); // after reset < before reset
|
||||
Void::Testing::expect(after < d.count()); // after restart < before
|
||||
}
|
||||
|
||||
// ── format_duration ───────────────────────────────────────────────────────
|
||||
|
||||
Reference in new issue
Block a user