Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear containers before populating them with values #23

Merged
merged 1 commit into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -101,7 +101,7 @@ if (FIGCONE_USE_ALL OR FIGCONE_USE_JSON OR FIGCONE_USE_YAML OR FIGCONE_USE_TOML
figcone::figcone_formats
)
SealLake_AddDependencies(
figcone_formats 1.1.0
figcone_formats 1.2.0
)
endif ()

Expand Down
6 changes: 3 additions & 3 deletions formats/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project(figcone_formats VERSION 1.1.0)
project(figcone_formats VERSION 1.2.0)

option(FIGCONE_USE_ALL "Enable all supported config formats" ON)
option(FIGCONE_USE_JSON "Enable JSON config format" OFF)
Expand Down Expand Up @@ -64,9 +64,9 @@ endif()

if(FIGCONE_USE_ALL OR FIGCONE_USE_XML)
SealLake_Import(
figcone_xml 1.1.0
figcone_xml 1.2.0
GIT_REPOSITORY https://github.com/kamchatka-volcano/figcone_xml.git
GIT_TAG v1.1.0
GIT_TAG v1.2.0
)
SealLake_Copy(
WILDCARDS ${figcone_xml_SOURCE_DIR}/include/figcone_xml/*
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_ = TMap{};
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_ = TCfgList{};
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_ = TParamList{};
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
Loading