From 14e7789847d9ecae169eed619c47a5b0f2049024 Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Wed, 25 Mar 2020 16:50:52 -0600 Subject: [PATCH] Add padding to config file generated output --- llarp/config/definition.cpp | 6 ++++-- test/config/test_llarp_config_output.cpp | 21 +++++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/llarp/config/definition.cpp b/llarp/config/definition.cpp index 359c8310d..a9e1dbd4e 100644 --- a/llarp/config/definition.cpp +++ b/llarp/config/definition.cpp @@ -136,7 +136,7 @@ Configuration::generateINIConfig(bool useValues) visitSections([&](const std::string& section, const DefinitionMap&) { if (sectionsVisited > 0) - oss << "\n"; + oss << "\n\n"; // TODO: this will create empty objects as a side effect of map's operator[] // TODO: this also won't handle sections which have no definition @@ -148,6 +148,7 @@ Configuration::generateINIConfig(bool useValues) oss << "[" << section << "]\n"; visitDefinitions(section, [&](const std::string& name, const ConfigDefinition_ptr& def) { + oss << "\n"; // TODO: as above, this will create empty objects // TODO: as above (but more important): this won't handle definitions with no entries @@ -164,9 +165,10 @@ Configuration::generateINIConfig(bool useValues) else { if (not def->required) - oss << "# "; + oss << "#"; oss << name << "=" << def->defaultValueAsString() << "\n"; } + }); sectionsVisited++; diff --git a/test/config/test_llarp_config_output.cpp b/test/config/test_llarp_config_output.cpp index 3e69988f7..e590bade6 100644 --- a/test/config/test_llarp_config_output.cpp +++ b/test/config/test_llarp_config_output.cpp @@ -23,13 +23,20 @@ TEST_CASE("Configuration simple generate test", "[config]") std::string output = config.generateINIConfig(); CHECK(output == R"raw([foo] + bar=1 -# baz=2 + +#baz=2 + quux=hello + [argle] + bar=3 -# baz=4 + +#baz=4 + quux=the quick brown fox )raw"); } @@ -41,14 +48,14 @@ TEST_CASE("Configuration useValue test", "[config]") config.defineOption(std::make_unique>( "foo", "bar", true, 1)); - constexpr auto expected = "[foo]\nbar=1\n"; + constexpr auto expected = "[foo]\n\nbar=1\n"; CHECK(config.generateINIConfig(false) == expected); CHECK(config.generateINIConfig(true) == expected); config.addConfigValue("foo", "bar", "2"); - constexpr auto expectedWhenValueProvided = "[foo]\nbar=2\n"; + constexpr auto expectedWhenValueProvided = "[foo]\n\nbar=2\n"; CHECK(config.generateINIConfig(false) == expected); CHECK(config.generateINIConfig(true) == expectedWhenValueProvided); @@ -68,6 +75,7 @@ TEST_CASE("Configuration section comments test") CHECK(output == R"raw(# test comment # test comment 2 [foo] + bar=1 )raw"); } @@ -84,6 +92,7 @@ TEST_CASE("Configuration option comments test") std::string output = config.generateINIConfig(); CHECK(output == R"raw([foo] + # test comment 1 # test comment 2 bar=1 @@ -107,6 +116,7 @@ TEST_CASE("Configuration empty comments test") CHECK(output == R"raw(# section comment # [foo] + # option comment # bar=1 @@ -131,8 +141,10 @@ TEST_CASE("Configuration multi option comments") CHECK(output == R"raw(# foo section comment [foo] + # foo bar option comment bar=1 + # foo baz option comment baz=1 )raw"); @@ -150,6 +162,7 @@ TEST_CASE("Configuration should print comments for missing keys") CHECK(output == R"raw(# foo section comment [foo] + # foo bar option comment bar= )raw");