Fix forwarding bug and float support for config (#1243)

This commit is contained in:
Sergey Kuznetsov
2024-03-07 14:39:25 +00:00
committed by GitHub
parent d47f3b71bd
commit 74455f5b99
4 changed files with 31 additions and 21 deletions

View File

@@ -53,7 +53,9 @@ constexpr static auto JSONData = R"JSON(
"test": {
"str": "hello",
"int": 9042,
"bool": true
"bool": true,
"double": 3.14,
"float": 42.0
}
},
"top": 420
@@ -107,6 +109,10 @@ TEST_F(ConfigTest, Access)
ASSERT_EQ(cfg.valueOr<string>("section.test.str", "fallback"), "hello");
ASSERT_EQ(cfg.valueOr<string>("section.test.nonexistent", "fallback"), "fallback");
ASSERT_EQ(cfg.valueOr("section.test.bool", false), true);
ASSERT_EQ(cfg.valueOr("section.test.double", 0.42), 3.14);
ASSERT_EQ(cfg.valueOr<float>("section.test.double", 0.42f), 3.14f);
ASSERT_EQ(cfg.valueOr("section.test.float", 0.42f), 42.0f);
ASSERT_EQ(cfg.valueOr<double>("section.test.float", 0.42), 42.0);
ASSERT_ANY_THROW((void)cfg.valueOr("section.test.bool", 1234)); // wrong type requested
}