|
|
|
@ -54,3 +54,103 @@ TEST_CASE("Configuration useValue test", "[config]")
|
|
|
|
|
CHECK(config.generateINIConfig(true) == expectedWhenValueProvided);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("Configuration section comments test")
|
|
|
|
|
{
|
|
|
|
|
llarp::Configuration config;
|
|
|
|
|
|
|
|
|
|
config.addSectionComment("foo", "test comment");
|
|
|
|
|
config.addSectionComment("foo", "test comment 2");
|
|
|
|
|
config.defineOption(std::make_unique<llarp::ConfigDefinition<int>>(
|
|
|
|
|
"foo", "bar", true, 1));
|
|
|
|
|
|
|
|
|
|
std::string output = config.generateINIConfig();
|
|
|
|
|
|
|
|
|
|
CHECK(output == R"raw(# test comment
|
|
|
|
|
# test comment 2
|
|
|
|
|
[foo]
|
|
|
|
|
bar=1
|
|
|
|
|
)raw");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("Configuration option comments test")
|
|
|
|
|
{
|
|
|
|
|
llarp::Configuration config;
|
|
|
|
|
|
|
|
|
|
config.addOptionComment("foo", "bar", "test comment 1");
|
|
|
|
|
config.addOptionComment("foo", "bar", "test comment 2");
|
|
|
|
|
config.defineOption(std::make_unique<llarp::ConfigDefinition<int>>(
|
|
|
|
|
"foo", "bar", true, 1));
|
|
|
|
|
|
|
|
|
|
std::string output = config.generateINIConfig();
|
|
|
|
|
|
|
|
|
|
CHECK(output == R"raw([foo]
|
|
|
|
|
# test comment 1
|
|
|
|
|
# test comment 2
|
|
|
|
|
bar=1
|
|
|
|
|
)raw");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("Configuration empty comments test")
|
|
|
|
|
{
|
|
|
|
|
llarp::Configuration config;
|
|
|
|
|
|
|
|
|
|
config.addSectionComment("foo", "section comment");
|
|
|
|
|
config.addSectionComment("foo", "");
|
|
|
|
|
|
|
|
|
|
config.addOptionComment("foo", "bar", "option comment");
|
|
|
|
|
config.addOptionComment("foo", "bar", "");
|
|
|
|
|
config.defineOption(std::make_unique<llarp::ConfigDefinition<int>>(
|
|
|
|
|
"foo", "bar", true, 1));
|
|
|
|
|
|
|
|
|
|
std::string output = config.generateINIConfig();
|
|
|
|
|
|
|
|
|
|
CHECK(output == R"raw(# section comment
|
|
|
|
|
#
|
|
|
|
|
[foo]
|
|
|
|
|
# option comment
|
|
|
|
|
#
|
|
|
|
|
bar=1
|
|
|
|
|
)raw");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("Configuration multi option comments")
|
|
|
|
|
{
|
|
|
|
|
llarp::Configuration config;
|
|
|
|
|
|
|
|
|
|
config.addSectionComment("foo", "foo section comment");
|
|
|
|
|
|
|
|
|
|
config.addOptionComment("foo", "bar", "foo bar option comment");
|
|
|
|
|
config.defineOption(std::make_unique<llarp::ConfigDefinition<int>>(
|
|
|
|
|
"foo", "bar", true, 1));
|
|
|
|
|
|
|
|
|
|
config.addOptionComment("foo", "baz", "foo baz option comment");
|
|
|
|
|
config.defineOption(std::make_unique<llarp::ConfigDefinition<int>>(
|
|
|
|
|
"foo", "baz", true, 1));
|
|
|
|
|
|
|
|
|
|
std::string output = config.generateINIConfig();
|
|
|
|
|
|
|
|
|
|
CHECK(output == R"raw(# foo section comment
|
|
|
|
|
[foo]
|
|
|
|
|
# foo bar option comment
|
|
|
|
|
bar=1
|
|
|
|
|
# foo baz option comment
|
|
|
|
|
baz=1
|
|
|
|
|
)raw");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("Configuration should print comments for missing keys")
|
|
|
|
|
{
|
|
|
|
|
// TODO: this currently fails: how to implement?
|
|
|
|
|
llarp::Configuration config;
|
|
|
|
|
|
|
|
|
|
config.addSectionComment("foo", "foo section comment");
|
|
|
|
|
config.addOptionComment("foo", "bar", "foo bar option comment");
|
|
|
|
|
|
|
|
|
|
std::string output = config.generateINIConfig();
|
|
|
|
|
|
|
|
|
|
CHECK(output == R"raw(# foo section comment
|
|
|
|
|
[foo]
|
|
|
|
|
# foo bar option comment
|
|
|
|
|
bar=
|
|
|
|
|
)raw");
|
|
|
|
|
}
|
|
|
|
|