From dc5cc04cde0e933bf3f6cfd114ddeffb28258164 Mon Sep 17 00:00:00 2001 From: Tait Weicht Date: Thu, 1 Jul 2021 15:56:19 -0700 Subject: [PATCH 1/2] Check that reprinting/reparsing preserves config --- tests/config/config.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/config/config.cpp b/tests/config/config.cpp index 91f51b2d5e..5f5ba3db0f 100644 --- a/tests/config/config.cpp +++ b/tests/config/config.cpp @@ -20,8 +20,23 @@ TEST_CASE("Test config", "[config]"){ // test config class template { - + MyConfig config; + + // make sure printing/parsing do not alter config + std::stringstream ss1, ss2; + config.Write(ss1); + config.Read(ss1); + config.Write(ss2); + std::string l1, l2; + while ( ss1 && ss2 ) { + std::getline(ss1, l1); + std::getline(ss2, l2); + // Check every line is the same between the "files" + REQUIRE(l1 == l2); + } + + config.Read("assets/test.cfg"); std::cout << "Random seed = " << config.RANDOM_SEED() << std::endl; From 4d776e11881f19ee12f95f118087dd90f93a658f Mon Sep 17 00:00:00 2001 From: Tait Weicht Date: Thu, 1 Jul 2021 16:13:03 -0700 Subject: [PATCH 2/2] Test config parameter newline handling --- tests/config/assets/config_setup.hpp | 1 + tests/config/config.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/tests/config/assets/config_setup.hpp b/tests/config/assets/config_setup.hpp index 1420c5df2f..17d4e3a6f8 100644 --- a/tests/config/assets/config_setup.hpp +++ b/tests/config/assets/config_setup.hpp @@ -34,6 +34,7 @@ EMP_BUILD_CONFIG( MyConfig, VALUE(TEST_STRING, std::string, "default", "This is a string!"), CONST(TEST_CONST, int, 91, "This is an unchanging const!"), VALUE(TEST_STRING_SPACE, std::string, "abc def ghi", "This is a string with spaces."), + VALUE(TEST_STRING_WHITESPACE, std::string, "What about...\n\t...whitespace in values?", "This is a string with newlines and tabs."), //VALUE(MUTATION_RATE, float, 0.025, "This is my mutation rate.", MUT_RATE), VALUE(MUTATION_RATE, float, 0.025, "This is my mutation rate."), ) diff --git a/tests/config/config.cpp b/tests/config/config.cpp index 5f5ba3db0f..c83a36031d 100644 --- a/tests/config/config.cpp +++ b/tests/config/config.cpp @@ -50,6 +50,8 @@ TEST_CASE("Test config", "[config]"){ REQUIRE(config.RANDOM_SEED() == 123); + REQUIRE(config.TEST_STRING_WHITESPACE() == "What about...\n\t...whitespace in values?"); + } }