Fix incorrect JSON patch unit test
This commit is contained in:
parent
6eb5329ec3
commit
4f8f3105bc
@ -32,7 +32,7 @@ TEST_CASE("JSON patch")
|
|||||||
|
|
||||||
SECTION("4.1 add")
|
SECTION("4.1 add")
|
||||||
{
|
{
|
||||||
json patch = R"([{ "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] }])"_json;
|
json patch1 = R"([{ "op": "add", "path": "/a/b", "value": [ "foo", "bar" ] }])"_json;
|
||||||
|
|
||||||
// However, the object itself or an array containing it does need
|
// However, the object itself or an array containing it does need
|
||||||
// to exist, and it remains an error for that not to be the case.
|
// to exist, and it remains an error for that not to be the case.
|
||||||
@ -42,24 +42,22 @@ TEST_CASE("JSON patch")
|
|||||||
|
|
||||||
// is not an error, because "a" exists, and "b" will be added to
|
// is not an error, because "a" exists, and "b" will be added to
|
||||||
// its value.
|
// its value.
|
||||||
CHECK_NOTHROW(doc1.patch(patch));
|
CHECK_NOTHROW(doc1.patch(patch1));
|
||||||
auto doc1_ans = R"(
|
auto doc1_ans = R"(
|
||||||
{
|
{
|
||||||
"a": {
|
"a": {
|
||||||
"foo": 1,
|
"foo": 1,
|
||||||
"b": {
|
"b": [ "foo", "bar" ]
|
||||||
"c": [ "foo", "bar" ]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)"_json;
|
)"_json;
|
||||||
CHECK(doc1.patch(patch) == doc1_ans);
|
CHECK(doc1.patch(patch1) == doc1_ans);
|
||||||
|
|
||||||
// It is an error in this document:
|
// It is an error in this document:
|
||||||
json doc2 = R"({ "q": { "bar": 2 } })"_json;
|
json doc2 = R"({ "q": { "bar": 2 } })"_json;
|
||||||
|
|
||||||
// because "a" does not exist.
|
// because "a" does not exist.
|
||||||
CHECK_THROWS_WITH_AS(doc2.patch(patch), "[json.exception.out_of_range.403] key 'a' not found", json::out_of_range&);
|
CHECK_THROWS_WITH_AS(doc2.patch(patch1), "[json.exception.out_of_range.403] key 'a' not found", json::out_of_range&);
|
||||||
|
|
||||||
json doc3 = R"({ "a": {} })"_json;
|
json doc3 = R"({ "a": {} })"_json;
|
||||||
json patch2 = R"([{ "op": "add", "path": "/a/b/c", "value": 1 }])"_json;
|
json patch2 = R"([{ "op": "add", "path": "/a/b/c", "value": 1 }])"_json;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user