Implement a simple config file parser
This commit is contained in:
parent
405b68b824
commit
167b8bee8d
20 changed files with 601 additions and 0 deletions
25
Tests/SimpleConf/Optionality.cpp
Normal file
25
Tests/SimpleConf/Optionality.cpp
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue