replace and copy

This commit is contained in:
Niels 2016-04-20 15:41:33 +02:00
parent 70fc5835cb
commit fa03cf0c63
3 changed files with 108 additions and 0 deletions

View file

@ -12421,6 +12421,34 @@ TEST_CASE("JSON patch")
CHECK(doc.apply_patch(patch) == expected);
}
SECTION("example A.5 - Replacing a Value")
{
// An example target JSON document:
json doc = R"(
{
"baz": "qux",
"foo": "bar"
}
)"_json;
// A JSON Patch document:
json patch = R"(
[
{ "op": "replace", "path": "/baz", "value": "boo" }
]
)"_json;
json expected = R"(
{
"baz": "boo",
"foo": "bar"
}
)"_json;
// check if patched value is as expected
CHECK(doc.apply_patch(patch) == expected);
}
SECTION("example A.8 - Testing a Value: Success")
{
// An example target JSON document:
@ -12615,6 +12643,48 @@ TEST_CASE("JSON patch")
CHECK(doc.apply_patch(patch) == expected);
}
}
SECTION("own examples")
{
SECTION("copy")
{
// An example target JSON document:
json doc = R"(
{
"foo": {
"bar": "baz",
"waldo": "fred"
},
"qux": {
"corge": "grault"
}
}
)"_json;
// A JSON Patch document:
json patch = R"(
[
{ "op": "copy", "from": "/foo/waldo", "path": "/qux/thud" }
]
)"_json;
json expected = R"(
{
"foo": {
"bar": "baz",
"waldo": "fred"
},
"qux": {
"corge": "grault",
"thud": "fred"
}
}
)"_json;
// check if patched value is as expected
CHECK(doc.apply_patch(patch) == expected);
}
}
}
TEST_CASE("regression tests")