Skip to content

Commit

Permalink
-cleared containers before populating them with new values;
Browse files Browse the repository at this point in the history
-set version to 3.2.0;
  • Loading branch information
kamchatka-volcano committed Oct 4, 2024
1 parent 8a668e8 commit 0a2c039
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.18)
project(figcone VERSION 3.1.0)
project(figcone VERSION 3.2.0)
include(external/seal_lake)

SealLake_IsInstallEnabled(INSTALL_FIGCONE_TREE)
Expand Down
2 changes: 1 addition & 1 deletion include/figcone/detail/dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ class Dict : public INode {
{
hasValue_ = true;
position_ = node.position();
dictMap_ = {};
if (!node.isItem())
throw ConfigError{"Dictionary '" + name_ + "': config node can't be a list.", node.position()};
if constexpr (sfun::is_optional_v<TMap>)
dictMap_.emplace();
maybeOptValue(dictMap_).clear();

for (const auto& paramName : node.asItem().paramNames()) {
const auto& paramValue = node.asItem().param(paramName);
Expand Down
1 change: 1 addition & 0 deletions include/figcone/detail/nodelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class NodeList : public detail::INode {
{
hasValue_ = true;
position_ = nodeList.position();
nodeList_ = {};
if (!nodeList.isList())
throw ConfigError{"Node list '" + name_ + "': config node must be a list.", nodeList.position()};
if constexpr (sfun::is_optional<TCfgList>::value)
Expand Down
1 change: 1 addition & 0 deletions include/figcone/detail/paramlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ParamList : public IParam {
{
position_ = paramList.position();
hasValue_ = true;
paramListValue_ = {};
if constexpr (sfun::is_optional_v<TParamList>)
paramListValue_.emplace();

Expand Down
17 changes: 17 additions & 0 deletions tests/test_paramlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,4 +406,21 @@ TEST(TestParamList, DefaultValue)
EXPECT_EQ(cfg.testIntList.at(2), 3);
}

TEST(TestParamList, OverwriteDefaultValue)
{
///testStrList = []
///
auto tree = figcone::makeTreeRoot();
tree->asItem().addParamList("testStrList", std::vector<std::string>{}, {1, 1});
tree->asItem().addParamList("testIntList", std::vector<std::string>{"42", "43"}, {1, 1});
auto parser = TreeProvider{std::move(tree)};
auto cfgReader = figcone::ConfigReader{figcone::NameFormat::CamelCase};
auto cfg = cfgReader.read<CfgStr>("", parser);

ASSERT_EQ(cfg.testStrList.size(), 0);
ASSERT_EQ(cfg.testIntList.size(), 2);
EXPECT_EQ(cfg.testIntList.at(0), 42);
EXPECT_EQ(cfg.testIntList.at(1), 43);
}

} //namespace test_paramlist
17 changes: 17 additions & 0 deletions tests_static_refl/test_paramlist_cpp20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,21 @@ TEST(StaticReflTestParamList, DefaultValue)
EXPECT_EQ(cfg.testIntList.at(2), 3);
}

TEST(TestParamList, OverwriteDefaultValue)
{
///testStrList = []
///
auto tree = figcone::makeTreeRoot();
tree->asItem().addParamList("testStrList", std::vector<std::string>{}, {1, 1});
tree->asItem().addParamList("testIntList", std::vector<std::string>{"42", "43"}, {1, 1});
auto parser = TreeProvider{std::move(tree)};
auto cfgReader = figcone::ConfigReader{figcone::NameFormat::CamelCase};
auto cfg = cfgReader.read<CfgStr>("", parser);

ASSERT_EQ(cfg.testStrList.size(), 0);
ASSERT_EQ(cfg.testIntList.size(), 2);
EXPECT_EQ(cfg.testIntList.at(0), 42);
EXPECT_EQ(cfg.testIntList.at(1), 43);
}

} //namespace test_paramlist

0 comments on commit 0a2c039

Please sign in to comment.