Skip to content

Commit

Permalink
Fix to override with set
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Feb 21, 2017
1 parent d8b8885 commit a6afe0a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/jsoncons/json_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ class json_object<KeyT,Json,true> : public Json_object_<KeyT,Json>
{
string_view_type s(name.data(),name.size());
auto it = std::find_if(this->members_.begin(),this->members_.end(),
[s](const value_type& a){return a.key().compare(s);});
[s](const value_type& a){return a.key().compare(s) == 0;});

if (it == this->members_.end())
{
Expand All @@ -1294,7 +1294,7 @@ class json_object<KeyT,Json,true> : public Json_object_<KeyT,Json>
{
string_view_type s(name.data(),name.size());
auto it = std::find_if(this->members_.begin(),this->members_.end(),
[s](const value_type& a){return a.key().compare(s);});
[s](const value_type& a){return a.key().compare(s) == 0;});

if (it == this->members_.end())
{
Expand Down
13 changes: 13 additions & 0 deletions test_suite/src/json_object_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -845,5 +845,18 @@ BOOST_AUTO_TEST_CASE(test_value_not_found_and_defaults)
[](const std::exception& ex ) { return ex.what() == std::string("first_aid_certification not found"); });
}

BOOST_AUTO_TEST_CASE(test_set_override)
{
json obj;
obj["first_name"] = "Jane";
obj["height"] = 0.9;

obj["first_name"] = "Joe";
obj["height"] = "0.3";

BOOST_CHECK(obj["first_name"] == "Joe");
BOOST_CHECK_CLOSE(obj["height"].as<double>(),0.3,0.00000000001);
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit a6afe0a

Please sign in to comment.