Merge branch 'develop' into feature/undo-number-roundtrip
This commit is contained in:
commit
04a80a8f60
6 changed files with 168 additions and 59 deletions
|
@ -10371,7 +10371,7 @@ TEST_CASE("README", "[hide]")
|
|||
// create object from string literal
|
||||
json j = "{ \"happy\": true, \"pi\": 3.141 }"_json;
|
||||
|
||||
// or even nicer (thanks http://isocpp.org/blog/2015/01/json-for-modern-cpp)
|
||||
// or even nicer with a raw string literal
|
||||
auto j2 = R"(
|
||||
{
|
||||
"happy": true,
|
||||
|
@ -10499,7 +10499,7 @@ TEST_CASE("README", "[hide]")
|
|||
}
|
||||
|
||||
{
|
||||
/// strings
|
||||
// strings
|
||||
std::string s1 = "Hello, world!";
|
||||
json js = s1;
|
||||
std::string s2 = js;
|
||||
|
@ -10522,6 +10522,40 @@ TEST_CASE("README", "[hide]")
|
|||
|
||||
// etc.
|
||||
}
|
||||
|
||||
{
|
||||
// a JSON value
|
||||
json j_original = R"({
|
||||
"baz": ["one", "two", "three"],
|
||||
"foo": "bar"
|
||||
})"_json;
|
||||
|
||||
// access members with a JSON pointer (RFC 6901)
|
||||
j_original["/baz/2"_json_pointer];
|
||||
// "two"
|
||||
|
||||
// a JSON patch (RFC 6902)
|
||||
json j_patch = R"([
|
||||
{ "op": "replace", "path": "/baz", "value": "boo" },
|
||||
{ "op": "add", "path": "/hello", "value": ["world"] },
|
||||
{ "op": "remove", "path": "/foo"}
|
||||
])"_json;
|
||||
|
||||
// apply the patch
|
||||
json j_result = j_original.patch(j_patch);
|
||||
// {
|
||||
// "baz": "boo",
|
||||
// "hello": ["world"]
|
||||
// }
|
||||
|
||||
// calculate a JSON patch from two JSON values
|
||||
json::diff(j_result, j_original);
|
||||
// [
|
||||
// { "op":" replace", "path": "/baz", "value": ["one", "two", "three"] },
|
||||
// { "op":"remove","path":"/hello" },
|
||||
// { "op":"add","path":"/foo","value":"bar" }
|
||||
// ]
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("algorithms")
|
||||
|
@ -14075,6 +14109,15 @@ TEST_CASE("regression tests")
|
|||
|
||||
CHECK(data == json({{"key", "value"}, {"key2", "value2"}, {"key3", "value3"}}));
|
||||
}
|
||||
|
||||
SECTION("issue #269 - diff generates incorrect patch when removing multiple array elements")
|
||||
{
|
||||
json doc = R"( { "arr1": [1, 2, 3, 4] } )"_json;
|
||||
json expected = R"( { "arr1": [1, 2] } )"_json;
|
||||
|
||||
// check roundtrip
|
||||
CHECK(doc.patch(json::diff(doc, expected)) == expected);
|
||||
}
|
||||
}
|
||||
|
||||
// special test case to check if memory is leaked if constructor throws
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue