54 lines
1.9 KiB
C++
54 lines
1.9 KiB
C++
|
#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");
|
||
|
}
|
||
|
}
|