Lines Matching defs:patch

20 TEST_CASE("JSON patch")
48 CHECK_NOTHROW(doc1.patch(patch1));
57 CHECK(doc1.patch(patch1) == doc1_ans);
63 CHECK_THROWS_WITH_AS(doc2.patch(patch1), "[json.exception.out_of_range.403] key 'a' not found", json::out_of_range&);
70 CHECK_THROWS_WITH_AS(doc3.patch(patch2), "[json.exception.out_of_range.403] (/a) key 'b' not found", json::out_of_range&);
72 CHECK_THROWS_WITH_AS(doc3.patch(patch2), "[json.exception.out_of_range.403] key 'b' not found", json::out_of_range&);
81 json patch = {{{"op", "remove"}, {"path", "/1"}}};
82 CHECK(doc.patch(patch) == json({1, 3, 4}));
93 json patch = R"(
108 CHECK(doc.patch(patch) == expected);
111 CHECK(doc.patch(json::diff(doc, expected)) == expected);
122 json patch = R"(
134 CHECK(doc.patch(patch) == expected);
137 CHECK(doc.patch(json::diff(doc, expected)) == expected);
151 json patch = R"(
163 CHECK(doc.patch(patch) == expected);
166 CHECK(doc.patch(json::diff(doc, expected)) == expected);
177 json patch = R"(
189 CHECK(doc.patch(patch) == expected);
192 CHECK(doc.patch(json::diff(doc, expected)) == expected);
206 json patch = R"(
220 CHECK(doc.patch(patch) == expected);
223 CHECK(doc.patch(json::diff(doc, expected)) == expected);
242 json patch = R"(
262 CHECK(doc.patch(patch) == expected);
265 CHECK(doc.patch(json::diff(doc, expected)) == expected);
276 json patch = R"(
288 CHECK(doc.patch(patch) == expected);
291 CHECK(doc.patch(json::diff(doc, expected)) == expected);
305 json patch = R"(
313 CHECK_NOTHROW(doc.patch(patch));
315 CHECK(doc.patch(patch) == doc);
326 json patch = R"(
333 CHECK_THROWS_AS(doc.patch(patch), json::other_error&);
335 CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] (/0) unsuccessful: " + patch[0].dump());
337 CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump());
349 json patch = R"(
367 CHECK(doc.patch(patch) == expected);
370 CHECK(doc.patch(json::diff(doc, expected)) == expected);
381 json patch = R"(
395 CHECK(doc.patch(patch) == expected);
398 CHECK(doc.patch(json::diff(doc, expected)) == expected);
409 json patch = R"(
421 CHECK_THROWS_WITH_AS(doc.patch(patch), "[json.exception.out_of_range.403] key 'baz' not found", json::out_of_range&);
438 json patch = R"(
452 CHECK(doc.patch(patch) == expected);
455 CHECK(doc.patch(json::diff(doc, expected)) == expected);
469 json patch = R"(
476 CHECK_THROWS_AS(doc.patch(patch), json::other_error&);
478 CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] (/0) unsuccessful: " + patch[0].dump());
480 CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump());
492 json patch = R"(
504 CHECK(doc.patch(patch) == expected);
507 CHECK(doc.patch(json::diff(doc, expected)) == expected);
525 json patch = R"(
535 CHECK(doc.patch(patch) == expected);
538 CHECK(doc.patch(json::diff(doc, expected)) == expected);
551 json patch = R"(
561 CHECK(doc.patch(patch) == expected);
564 CHECK(doc.patch(json::diff(doc, expected)) == expected);
584 json patch = R"(
605 CHECK(doc.patch(patch) == expected);
608 CHECK(doc.patch(json::diff(doc, expected)) == expected);
614 json patch = {{{"op", "replace"}, {"path", ""}, {"value", 1}}};
615 CHECK(j.patch(patch) == json(1));
621 // a JSON patch
631 // apply the patch
632 json target = source.patch(p1);
669 json patch = {{"op", "add"}, {"path", ""}, {"value", 1}};
670 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.104] parse error: JSON patch must be an array of objects", json::parse_error&);
676 json patch = {"op", "add", "path", "", "value", 1};
678 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.104] parse error: (/0) JSON patch must be an array of objects", json::parse_error&);
680 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.104] parse error: JSON patch must be an array of objects", json::parse_error&);
687 json patch = {{{"foo", "bar"}}};
689 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation must have member 'op'", json::parse_error&);
691 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation must have member 'op'", json::parse_error&);
698 json patch = {{{"op", 1}}};
700 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation must have string member 'op'", json::parse_error&);
702 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation must have string member 'op'", json::parse_error&);
709 json patch = {{{"op", "foo"}, {"path", ""}}};
711 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation value 'foo' is invalid", json::parse_error&);
713 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation value 'foo' is invalid", json::parse_error&);
723 json patch = {{{"op", "add"}}};
725 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'add' must have member 'path'", json::parse_error&);
727 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'add' must have member 'path'", json::parse_error&);
734 json patch = {{{"op", "add"}, {"path", 1}}};
736 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'add' must have string member 'path'", json::parse_error&);
738 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'add' must have string member 'path'", json::parse_error&);
745 json patch = {{{"op", "add"}, {"path", ""}}};
747 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'add' must have member 'value'", json::parse_error&);
749 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'add' must have member 'value'", json::parse_error&);
756 json patch = {{{"op", "add"}, {"path", "/4"}, {"value", 4}}};
757 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.401] array index 4 is out of range", json::out_of_range&);
766 json patch = {{{"op", "remove"}}};
768 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'remove' must have member 'path'", json::parse_error&);
770 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'remove' must have member 'path'", json::parse_error&);
777 json patch = {{{"op", "remove"}, {"path", 1}}};
779 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'remove' must have string member 'path'", json::parse_error&);
781 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'remove' must have string member 'path'", json::parse_error&);
788 json patch = {{{"op", "remove"}, {"path", "/17"}}};
789 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.401] array index 17 is out of range", json::out_of_range&);
795 json patch = {{{"op", "remove"}, {"path", "/baz"}}};
796 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.403] key 'baz' not found", json::out_of_range&);
802 json patch = {{{"op", "remove"}, {"path", ""}}};
803 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.405] JSON pointer has no parent", json::out_of_range&);
812 json patch = {{{"op", "replace"}}};
814 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have member 'path'", json::parse_error&);
816 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'replace' must have member 'path'", json::parse_error&);
823 json patch = {{{"op", "replace"}, {"path", 1}}};
825 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have string member 'path'", json::parse_error&);
827 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'replace' must have string member 'path'", json::parse_error&);
834 json patch = {{{"op", "replace"}, {"path", ""}}};
836 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have member 'value'", json::parse_error&);
838 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'replace' must have member 'value'", json::parse_error&);
845 json patch = {{{"op", "replace"}, {"path", "/17"}, {"value", 19}}};
846 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.401] array index 17 is out of range", json::out_of_range&);
852 json patch = {{{"op", "replace"}, {"path", "/baz"}, {"value", 3}}};
853 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.403] key 'baz' not found", json::out_of_range&);
862 json patch = {{{"op", "move"}}};
864 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'move' must have member 'path'", json::parse_error&);
866 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'move' must have member 'path'", json::parse_error&);
873 json patch = {{{"op", "move"}, {"path", 1}}};
875 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'move' must have string member 'path'", json::parse_error&);
877 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'move' must have string member 'path'", json::parse_error&);
884 json patch = {{{"op", "move"}, {"path", ""}}};
885 CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
887 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'move' must have member 'from'", json::parse_error&);
889 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'move' must have member 'from'", json::parse_error&);
896 json patch = {{{"op", "move"}, {"path", ""}, {"from", 1}}};
897 CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
899 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'move' must have string member 'from'", json::parse_error&);
901 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'move' must have string member 'from'", json::parse_error&);
908 json patch = {{{"op", "move"}, {"path", "/0"}, {"from", "/5"}}};
909 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.401] array index 5 is out of range", json::out_of_range&);
915 json patch = {{{"op", "move"}, {"path", "/baz"}, {"from", "/baz"}}};
916 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.403] key 'baz' not found", json::out_of_range&);
925 json patch = {{{"op", "copy"}}};
927 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have member 'path'", json::parse_error&);
929 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'copy' must have member 'path'", json::parse_error&);
936 json patch = {{{"op", "copy"}, {"path", 1}}};
938 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have string member 'path'", json::parse_error&);
940 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'copy' must have string member 'path'", json::parse_error&);
947 json patch = {{{"op", "copy"}, {"path", ""}}};
949 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have member 'from'", json::parse_error&);
951 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'copy' must have member 'from'", json::parse_error&);
958 json patch = {{{"op", "copy"}, {"path", ""}, {"from", 1}}};
960 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have string member 'from'", json::parse_error&);
962 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'copy' must have string member 'from'", json::parse_error&);
969 json patch = {{{"op", "copy"}, {"path", "/0"}, {"from", "/5"}}};
970 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.401] array index 5 is out of range", json::out_of_range&);
976 json patch = {{{"op", "copy"}, {"path", "/fob"}, {"from", "/baz"}}};
977 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.403] key 'baz' not found", json::out_of_range&);
986 json patch = {{{"op", "test"}}};
988 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'test' must have member 'path'", json::parse_error&);
990 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'test' must have member 'path'", json::parse_error&);
997 json patch = {{{"op", "test"}, {"path", 1}}};
999 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'test' must have string member 'path'", json::parse_error&);
1001 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'test' must have string member 'path'", json::parse_error&);
1008 json patch = {{{"op", "test"}, {"path", ""}}};
1010 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'test' must have member 'value'", json::parse_error&);
1012 CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'test' must have member 'value'", json::parse_error&);
1030 // The patch
1031 json patch = R"(
1048 CHECK(doc.patch(patch) == result);
1051 CHECK(doc.patch(json::diff(doc, result)) == result);
1068 // The patch
1069 json patch = R"(
1087 CHECK(doc.patch(patch) == result);
1090 CHECK(doc.patch(json::diff(doc, result)) == result);
1095 // The patch
1096 json patch = R"(
1108 CHECK(doc.patch(patch) == result);
1111 CHECK(doc.patch(json::diff(doc, result)) == result);
1116 // The patch
1117 json patch = R"(
1134 CHECK(doc.patch(patch) == result);
1137 CHECK(doc.patch(json::diff(doc, result)) == result);
1142 // The patch
1143 json patch = R"(
1163 CHECK(doc.patch(patch) == result);
1166 CHECK(doc.patch(json::diff(doc, result)) == result);
1171 // The patch
1172 json patch = R"(
1189 CHECK(doc.patch(patch) == result);
1192 CHECK(doc.patch(json::diff(doc, result)) == result);
1197 // The patch
1198 json patch = R"(
1205 CHECK_THROWS_AS(doc.patch(patch), json::other_error&);
1207 CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] (/0) unsuccessful: " + patch[0].dump());
1209 CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump());
1219 CHECK(R"( {} )"_json.patch(
1223 CHECK(R"( {"foo": [1, 3]} )"_json.patch(
1227 CHECK(R"( {"foo": [{}]} )"_json.patch(
1234 CHECK(R"( {"foo": "bar"} )"_json.patch(
1238 CHECK(R"( {"foo": [1, 2, 3]} )"_json.patch(
1242 CHECK(R"( {"foo": [{"bar": "baz"}]} )"_json.patch(
1249 CHECK(R"( {"foo": "bar"} )"_json.patch(
1253 CHECK(R"( {"foo": [1, 2, 3]} )"_json.patch(
1257 CHECK(R"( {"foo": [{"bar": "baz"}]} )"_json.patch(
1264 CHECK(R"( {"foo": [1, 2, 3]} )"_json.patch(
1271 CHECK(R"( {"foo": [1, 2, 3]} )"_json.patch(
1278 CHECK_NOTHROW(R"( {"foo": "bar"} )"_json.patch(
1283 SECTION("Tests from github.com/json-patch/json-patch-tests")
1287 TEST_DATA_DIRECTORY "/json-patch-tests/spec_tests.json",
1288 TEST_DATA_DIRECTORY "/json-patch-tests/tests.json"
1306 const auto& patch = test["patch"];
1312 CHECK(doc.patch(patch) == expected);
1316 CHECK_THROWS(doc.patch(patch));