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>
100 lines
3.1 KiB
C++
100 lines
3.1 KiB
C++
#include <Void/Data/Ini.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <string>
|
|
|
|
static constexpr const char* SAMPLE = R"(
|
|
; comment
|
|
[database]
|
|
host = localhost
|
|
port = 5432
|
|
name = "my db"
|
|
|
|
[server]
|
|
# another comment
|
|
host = 0.0.0.0
|
|
port = 8080
|
|
)";
|
|
|
|
// ── parse ─────────────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test ini_parse_sections()
|
|
{
|
|
auto f = Void::Ini::IniFile::from_string(SAMPLE);
|
|
Void::Testing::expect(f.has_section("database"));
|
|
Void::Testing::expect(f.has_section("server"));
|
|
}
|
|
|
|
Void::Testing::Test ini_parse_values()
|
|
{
|
|
auto f = Void::Ini::IniFile::from_string(SAMPLE);
|
|
const auto host = f.get("database", "host");
|
|
Void::Testing::expect(host.has_value());
|
|
Void::Testing::expect_eq(*host, std::string{"localhost"});
|
|
}
|
|
|
|
Void::Testing::Test ini_parse_quoted_value()
|
|
{
|
|
auto f = Void::Ini::IniFile::from_string(SAMPLE);
|
|
const auto name = f.get("database", "name");
|
|
Void::Testing::expect(name.has_value());
|
|
Void::Testing::expect_eq(*name, std::string{"my db"});
|
|
}
|
|
|
|
Void::Testing::Test ini_missing_key_returns_nullopt()
|
|
{
|
|
auto f = Void::Ini::IniFile::from_string(SAMPLE);
|
|
Void::Testing::expect(!f.get("database", "password").has_value());
|
|
}
|
|
|
|
Void::Testing::Test ini_missing_section_returns_nullopt()
|
|
{
|
|
auto f = Void::Ini::IniFile::from_string(SAMPLE);
|
|
Void::Testing::expect(!f.get("auth", "token").has_value());
|
|
}
|
|
|
|
Void::Testing::Test ini_get_or_fallback()
|
|
{
|
|
auto f = Void::Ini::IniFile::from_string(SAMPLE);
|
|
Void::Testing::expect_eq(f.get_or("database", "timeout", "30"), std::string{"30"});
|
|
}
|
|
|
|
Void::Testing::Test ini_has_key()
|
|
{
|
|
auto f = Void::Ini::IniFile::from_string(SAMPLE);
|
|
Void::Testing::expect(f.has_key("server", "port"));
|
|
Void::Testing::expect(!f.has_key("server", "ssl"));
|
|
}
|
|
|
|
// ── set / serialize ───────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test ini_set_and_get()
|
|
{
|
|
Void::Ini::IniFile f;
|
|
f.set("app", "version", "1.0");
|
|
const auto v = f.get("app", "version");
|
|
Void::Testing::expect(v.has_value());
|
|
Void::Testing::expect_eq(*v, std::string{"1.0"});
|
|
}
|
|
|
|
Void::Testing::Test ini_serialize_round_trip()
|
|
{
|
|
Void::Ini::IniFile f;
|
|
f.set("section", "key", "value");
|
|
const auto serialized = f.serialize();
|
|
auto f2 = Void::Ini::IniFile::from_string(serialized);
|
|
const auto v = f2.get("section", "key");
|
|
Void::Testing::expect(v.has_value());
|
|
Void::Testing::expect_eq(*v, std::string{"value"});
|
|
}
|
|
|
|
// ── error handling ────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test ini_unclosed_section_is_error()
|
|
{
|
|
Void::Ini::IniFile f;
|
|
const auto err = Void::Ini::IniFile::parse(f, "[unclosed");
|
|
Void::Testing::expect(err.has_value());
|
|
}
|