#include #include #include #include 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()); }