Implement a simple config file parser
This commit is contained in:
parent
405b68b824
commit
167b8bee8d
20 changed files with 601 additions and 0 deletions
41
Tests/SimpleConf/Conversions.cpp
Normal file
41
Tests/SimpleConf/Conversions.cpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <Garbage/SimpleConf.hpp>
|
||||
|
||||
TEST_CASE("Check if type conversions work correctly")
|
||||
{
|
||||
using Required = Garbage::SimpleConf::Required;
|
||||
|
||||
std::filesystem::path path("TestConfigs/BasicConversions.conf");
|
||||
|
||||
Garbage::SimpleConf config(path);
|
||||
|
||||
SECTION("Basic stuff that should be correct")
|
||||
{
|
||||
REQUIRE(config.Get<std::string, Required>("an int") == "123456");
|
||||
REQUIRE(config.Get<std::string, Required>("a float") == "3.5");
|
||||
REQUIRE(config.Get<std::string, Required>("a long (8B)") == "121212121212121212");
|
||||
REQUIRE(config.Get<std::string, Required>("a double") == "0.0000128");
|
||||
|
||||
REQUIRE(config.Get<std::int32_t>("an int") == 123456);
|
||||
REQUIRE(config.Get<float>("a float") == 3.5f);
|
||||
REQUIRE(config.Get<std::int64_t>("a long (8B)") == 121212121212121212);
|
||||
REQUIRE(config.Get<double>("a double") == 0.0000128);
|
||||
}
|
||||
|
||||
SECTION("Stuff that should fail to parse")
|
||||
{
|
||||
REQUIRE(config.Get<std::string, Required>("an incorrect char") == "256");
|
||||
REQUIRE(config.Get<std::string, Required>("unsigned") == "-34");
|
||||
REQUIRE(config.Get<std::string, Required>("signed, but large") == "3000000000");
|
||||
REQUIRE(config.Get<std::string, Required>("mangled float") == "3.f4");
|
||||
REQUIRE(config.Get<std::string, Required>("mangled float 2") == "2.4f");
|
||||
|
||||
using ConversionError = Garbage::SimpleConfImplementation::ConversionError;
|
||||
|
||||
REQUIRE_THROWS_AS(config.Get<std::uint8_t>("an incorrect char"), ConversionError);
|
||||
REQUIRE_THROWS_AS(config.Get<std::uint32_t>("unsigned"), ConversionError);
|
||||
REQUIRE_THROWS_AS(config.Get<std::int32_t>("signed, but large"), ConversionError);
|
||||
REQUIRE_THROWS_AS(config.Get<float>("mangled float"), ConversionError);
|
||||
REQUIRE_THROWS_AS(config.Get<float>("mangled float 2"), ConversionError);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue