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,53 @@
#include <catch2/catch_test_macros.hpp>
#include <Garbage/SimpleConf.hpp>
TEST_CASE("Check behavior when whitespace is involved")
{
SECTION("Simple multi-line config")
{
using Required = Garbage::SimpleConf::Required;
std::string rawConfig =
" key with whitespace = and value too \n"
"another=one\n"
" and yet = another";
Garbage::SimpleConf config(std::move(rawConfig));
REQUIRE(config.Get<std::string, Required>("key with whitespace") == "and value too");
REQUIRE(config.Get<std::string, Required>("another") == "one");
REQUIRE(config.Get<std::string, Required>("and yet") == "another");
}
SECTION("Deal with CRLF correctly")
{
using Required = Garbage::SimpleConf::Required;
std::string rawConfig =
" simple key=simple value \r\n"
" another = one\r\n"
" and one = more\r\n";
Garbage::SimpleConf config(std::move(rawConfig));
REQUIRE(config.Get<std::string, Required>("simple key") == "simple value");
REQUIRE(config.Get<std::string, Required>("another") == "one");
REQUIRE(config.Get<std::string, Required>("and one") == "more");
}
SECTION("Weirder whitespace shenanigans")
{
using Required = Garbage::SimpleConf::Required;
std::string rawConfig =
"let's+start_simple=with some\tbasics\n"
"\t\tnow we get \tsome=\t \tweirder\tstuff\r\n"
"\t\tinsa+nity\twith\t\t=\t white \t space \t\t";
Garbage::SimpleConf config(std::move(rawConfig));
REQUIRE(config.Get<std::string, Required>("let's+start_simple") == "with some\tbasics");
REQUIRE(config.Get<std::string, Required>("now we get \tsome") == "weirder\tstuff");
REQUIRE(config.Get<std::string, Required>("insa+nity\twith") == "white \t space");
}
}