Fix tests

This commit is contained in:
Eelco Dolstra 2020-08-24 10:37:10 +02:00
parent 25ecfffdc3
commit 88d5c9ec58
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE

View file

@ -33,7 +33,7 @@ namespace nix {
const auto iter = settings.find("name-of-the-setting"); const auto iter = settings.find("name-of-the-setting");
ASSERT_NE(iter, settings.end()); ASSERT_NE(iter, settings.end());
ASSERT_EQ(iter->second.value, ""); ASSERT_EQ(iter->second.value, "");
ASSERT_EQ(iter->second.description, "description"); ASSERT_EQ(iter->second.description, "description\n");
} }
TEST(Config, getDefinedOverridenSettingNotSet) { TEST(Config, getDefinedOverridenSettingNotSet) {
@ -59,7 +59,7 @@ namespace nix {
const auto iter = settings.find("name-of-the-setting"); const auto iter = settings.find("name-of-the-setting");
ASSERT_NE(iter, settings.end()); ASSERT_NE(iter, settings.end());
ASSERT_EQ(iter->second.value, "value"); ASSERT_EQ(iter->second.value, "value");
ASSERT_EQ(iter->second.description, "description"); ASSERT_EQ(iter->second.description, "description\n");
} }
TEST(Config, getDefinedSettingSet2) { TEST(Config, getDefinedSettingSet2) {
@ -73,7 +73,7 @@ namespace nix {
const auto e = settings.find("name-of-the-setting"); const auto e = settings.find("name-of-the-setting");
ASSERT_NE(e, settings.end()); ASSERT_NE(e, settings.end());
ASSERT_EQ(e->second.value, "value"); ASSERT_EQ(e->second.value, "value");
ASSERT_EQ(e->second.description, "description"); ASSERT_EQ(e->second.description, "description\n");
} }
TEST(Config, addSetting) { TEST(Config, addSetting) {
@ -152,29 +152,16 @@ namespace nix {
} }
TEST(Config, toJSONOnEmptyConfig) { TEST(Config, toJSONOnEmptyConfig) {
std::stringstream out; ASSERT_EQ(Config().toJSON().dump(), "{}");
{ // Scoped to force the destructor of JSONObject to write the final `}`
JSONObject obj(out);
Config config;
config.toJSON(obj);
}
ASSERT_EQ(out.str(), "{}");
} }
TEST(Config, toJSONOnNonEmptyConfig) { TEST(Config, toJSONOnNonEmptyConfig) {
std::stringstream out; Config config;
{ // Scoped to force the destructor of JSONObject to write the final `}` std::map<std::string, Config::SettingInfo> settings;
JSONObject obj(out); Setting<std::string> setting{&config, "", "name-of-the-setting", "description"};
setting.assign("value");
Config config; ASSERT_EQ(config.toJSON().dump(), R"#({"name-of-the-setting":{"aliases":[],"description":"description\n","value":"value"}})#");
std::map<std::string, Config::SettingInfo> settings;
Setting<std::string> setting{&config, "", "name-of-the-setting", "description"};
setting.assign("value");
config.toJSON(obj);
}
ASSERT_EQ(out.str(), R"#({"name-of-the-setting":{"description":"description","value":"value"}})#");
} }
TEST(Config, setSettingAlias) { TEST(Config, setSettingAlias) {