Garbage/Tests/SimpleConf/Optionality.cpp

26 lines
877 B
C++
Raw Normal View History

2025-06-09 01:41:33 +02:00
#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);
}
}