started fixing #323

This commit is contained in:
Niels 2016-10-08 14:27:28 +02:00
parent a0ef5a194c
commit 2fa8ea0f74
5 changed files with 101 additions and 15 deletions

View file

@ -109,8 +109,13 @@ TEST_CASE("JSON pointers")
CHECK(j[json::json_pointer("/m~0n")] == j["m~n"]);
// unescaped access
CHECK_THROWS_AS(j[json::json_pointer("/a/b")], std::out_of_range);
CHECK_THROWS_WITH(j[json::json_pointer("/a/b")], "unresolved reference token 'b'");
// access to nonexisting values yield object creation
CHECK_NOTHROW(j[json::json_pointer("/a/b")] = 42);
CHECK(j["a"]["b"] == json(42));
CHECK_NOTHROW(j[json::json_pointer("/a/c/1")] = 42);
CHECK(j["a"]["c"] == json({nullptr, 42}));
CHECK_NOTHROW(j[json::json_pointer("/a/d/-")] = 42);
CHECK(j["a"]["d"] == json::array({42}));
// "/a/b" works for JSON {"a": {"b": 42}}
CHECK(json({{"a", {{"b", 42}}}})[json::json_pointer("/a/b")] == json(42));

View file

@ -482,4 +482,11 @@ TEST_CASE("regression tests")
CHECK_NOTHROW(j << f);
}
}
SECTION("issue #323 - add nested object capabilities to pointers")
{
json j;
j["/this/that"_json_pointer] = 27;
CHECK(j == json({{"this", {{"that", 27}}}}));
}
}