Implement a simple config file parser

This commit is contained in:
TennesseeTrash 2025-06-09 01:41:33 +02:00
parent 405b68b824
commit 167b8bee8d
20 changed files with 601 additions and 0 deletions

View file

@ -0,0 +1,25 @@
#include <catch2/catch_test_macros.hpp>
#include <Garbage/SimpleConf.hpp>
TEST_CASE("Check handling of optional values")
{
std::filesystem::path path("TestConfigs/Optionality.conf");
Garbage::SimpleConf config(path);
SECTION("GetOptional behaviour")
{
REQUIRE(!config.GetOptional<std::string>("non-existent key"));
REQUIRE(*config.GetOptional<std::string>("existing key") == "existing value");
}
SECTION("Get behaviour")
{
using Required = Garbage::SimpleConf::Required;
using LookupError = Garbage::SimpleConfImplementation::LookupError;
REQUIRE(config.Get<std::string>("non-existent key", "a default") == "a default");
REQUIRE(config.Get<std::string>("existing key") == "existing value");
REQUIRE_THROWS_AS((config.Get<std::string, Required>("non-existent key")), LookupError);
}
}