Add async/resilience/reflection primitives + FSM v2 rewrite
A round of new universal capabilities (all generic — templated/reflection based, no app coupling), verified by the test suite (1103 passing): Data reflection: - Reflect.hpp now (de)serializes chrono::duration, chrono::time_point, std::variant (tagged), std::array, and non-string-keyed std::map; Meta.hpp gains is_time_point_v et al. Async: - EventBus gains Mode::Async (worker-thread dispatch + flush()). - ThreadPool gains a bounded queue, try_submit(), and rejection stats. New modules / containers: - Resilience: TokenBucket, KeyedRateLimiter<Key>, CircuitBreaker, ResourceMonitor. - Containers: BufferPool<T> (size-class buffer reuse) and Cache<K,V> (per-entry TTL, LRU/LFU/FIFO eviction, hit/miss stats). - System: process/CPU/memory metrics (Metrics.hpp) and a streaming Process API. Plus FSM v2 (typed Success/Failure, sub-machines, parallel regions, history states, deferred events), Configuration/Logging reflection helpers, and the accompanying test suites. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
43b5a81504
commit
80293ee56f
93 files changed
+8500
-3312
No files matched your search
@@ -0,0 +1,92 @@
|
||||
#include <Void/Data/Json.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Suite.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
{
|
||||
using Void::Testing::Test;
|
||||
|
||||
const char* kDoc = R"({
|
||||
"name": "root",
|
||||
"nested": { "a": { "b": [10, 20, 30] } },
|
||||
"weird/key": 7,
|
||||
"flag": true
|
||||
})";
|
||||
|
||||
struct JsonQuery : Void::Testing::Suite<JsonQuery> {
|
||||
// ── JSON Pointer (at) ─────────────────────────────────────
|
||||
Test pointer_walks_objects_and_arrays()
|
||||
{
|
||||
auto doc = Void::Json::parse(kDoc);
|
||||
Void::Testing::expect(doc.has_value());
|
||||
const auto* v = doc->at("/nested/a/b/1");
|
||||
Void::Testing::expect(v != nullptr);
|
||||
Void::Testing::expect_eq(v->as_number(), 20.0);
|
||||
}
|
||||
|
||||
Test empty_pointer_is_whole_document()
|
||||
{
|
||||
auto doc = Void::Json::parse(kDoc);
|
||||
const auto* v = doc->at("");
|
||||
Void::Testing::expect(v == &*doc);
|
||||
}
|
||||
|
||||
Test missing_path_returns_null()
|
||||
{
|
||||
auto doc = Void::Json::parse(kDoc);
|
||||
Void::Testing::expect(doc->at("/nested/missing") == nullptr);
|
||||
Void::Testing::expect(doc->at("/nested/a/b/9") == nullptr);
|
||||
Void::Testing::expect(doc->at("/flag/x") == nullptr);
|
||||
}
|
||||
|
||||
Test escaped_token()
|
||||
{
|
||||
auto doc = Void::Json::parse(kDoc);
|
||||
const auto* v = doc->at("/weird~1key"); // ~1 -> '/'
|
||||
Void::Testing::expect(v != nullptr);
|
||||
Void::Testing::expect_eq(v->as_number(), 7.0);
|
||||
}
|
||||
|
||||
// ── SAX streaming parse ───────────────────────────────────
|
||||
Test sax_fires_events_in_order()
|
||||
{
|
||||
std::vector<std::string> events;
|
||||
Void::Json::SaxHandler h;
|
||||
h.on_object_begin = [&] { events.push_back("{"); };
|
||||
h.on_object_end = [&] { events.push_back("}"); };
|
||||
h.on_array_begin = [&] { events.push_back("["); };
|
||||
h.on_array_end = [&] { events.push_back("]"); };
|
||||
h.on_key = [&](std::string_view k) {
|
||||
events.push_back("key:" + std::string{k});
|
||||
};
|
||||
h.on_number = [&](double d) {
|
||||
events.push_back("num:" + std::to_string((int)d));
|
||||
};
|
||||
h.on_bool = [&](bool b) {
|
||||
events.push_back(b ? "true" : "false");
|
||||
};
|
||||
h.on_string = [&](std::string_view s) {
|
||||
events.push_back("str:" + std::string{s});
|
||||
};
|
||||
|
||||
auto err =
|
||||
Void::Json::parse_sax(R"({"a":[1,2],"b":"x","c":true})", h);
|
||||
Void::Testing::expect(!err.has_value());
|
||||
|
||||
const std::vector<std::string> expected{
|
||||
"{", "key:a", "[", "num:1", "num:2", "]",
|
||||
"key:b", "str:x", "key:c", "true", "}"};
|
||||
Void::Testing::expect(events == expected);
|
||||
}
|
||||
|
||||
Test sax_reports_malformed_input()
|
||||
{
|
||||
Void::Json::SaxHandler h;
|
||||
auto err = Void::Json::parse_sax(R"({"a": })", h);
|
||||
Void::Testing::expect(err.has_value());
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
Reference in new issue
Block a user