diff --git a/CMakeLists.txt b/CMakeLists.txt index 405e641..3b4826a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,7 +98,7 @@ include_directories(include SYSTEM thirdparty/picojson-1.3.0 thirdparty/nlohmann-json-3.1.2 thirdparty/yaml-cpp-0.7.0/include - ) +) if(valijson_BUILD_TESTS) if(NOT valijson_EXCLUDE_BOOST) diff --git a/include/valijson/adapters/yaml_cpp_adapter.hpp b/include/valijson/adapters/yaml_cpp_adapter.hpp index ffcd0d1..76f7e7d 100644 --- a/include/valijson/adapters/yaml_cpp_adapter.hpp +++ b/include/valijson/adapters/yaml_cpp_adapter.hpp @@ -115,7 +115,7 @@ class YamlCppArray } /// Reference to the contained value - const YAML::Node &m_value; + const YAML::Node m_value; }; /** @@ -203,7 +203,7 @@ class YamlCppObject } /// Reference to the contained object - const YAML::Node &m_value; + const YAML::Node m_value; }; /** @@ -222,7 +222,8 @@ class YamlCppFrozenValue : public FrozenValue * * @param source the YamlCpp value to be copied */ - explicit YamlCppFrozenValue(YAML::Node source) : m_value(std::move(source)) + explicit YamlCppFrozenValue(YAML::Node source) + : m_value(YAML::Clone(source)) { } @@ -444,7 +445,7 @@ class YamlCppValue } /// Reference to the contained YamlCpp value. - const YAML::Node &m_value; + const YAML::Node m_value; }; /** @@ -689,4 +690,4 @@ YamlCppObject::find(const std::string &propertyName) const } } // namespace adapters -} // namespace valijson \ No newline at end of file +} // namespace valijson diff --git a/tests/test_yaml_cpp_adapter.cpp b/tests/test_yaml_cpp_adapter.cpp index 21de2e7..e0ec3c3 100644 --- a/tests/test_yaml_cpp_adapter.cpp +++ b/tests/test_yaml_cpp_adapter.cpp @@ -74,7 +74,9 @@ TEST_F(TestYamlCppAdapter, BasicObjectIteration) unsigned int expectedValue = 0; for (const valijson::adapters::YamlCppAdapter::ObjectMember member : adapter.getObject()) { - ASSERT_TRUE(member.second.isNumber()); + ASSERT_TRUE(member.second.isString()); + ASSERT_FALSE(member.second.isNumber()); + ASSERT_TRUE(member.second.maybeDouble()); EXPECT_EQ(std::to_string(expectedValue), member.first); EXPECT_EQ(double(expectedValue), member.second.getDouble()); expectedValue++;