Skip to content

Commit c9a582c

Browse files
committed
Merge pull request #5 from json-patch/master
Pull latest
2 parents 7ae2a9f + 8f36b44 commit c9a582c

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

tests.json

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@
171171
"expected": ["foo", ["bar", "baz"]],
172172
"comment": "value in array replace not flattened" },
173173

174+
{ "comment": "replace whole document",
175+
"doc": {"foo": "bar"},
176+
"patch": [{"op": "replace", "path": "", "value": {"baz": "qux"}}],
177+
"expected": {"baz": "qux"} },
178+
174179
{ "comment": "spurious patch properties",
175180
"doc": {"foo": 1},
176181
"patch": [{"op": "test", "path": "/foo", "value": 1, "spurious": 1}],
@@ -196,8 +201,6 @@
196201
"patch": [{"op": "test", "path": "/foo", "value": [1, 2]}],
197202
"error": "test op should fail" },
198203

199-
{ "comment": "json-pointer tests" },
200-
201204
{ "comment": "Whole document",
202205
"doc": { "foo": 1 },
203206
"patch": [{"op": "test", "path": "", "value": {"foo": 1}}],
@@ -263,5 +266,38 @@
263266
"patch": [ { "op": "add", "path": "/2/1/-", "value": { "foo": [ "bar", "baz" ] } } ],
264267
"expected": [ 1, 2, [ 3, [ 4, 5, { "foo": [ "bar", "baz" ] } ] ] ]},
265268

266-
{ "comment": "tests complete" }
269+
{ "comment": "test remove with bad number should fail",
270+
"doc": {"foo": 1, "baz": [{"qux": "hello"}]},
271+
"patch": [{"op": "remove", "path": "/baz/1e0/qux"}],
272+
"error": "remove op shouldn't remove from array with bad number" },
273+
274+
{ "comment": "test remove on array",
275+
"doc": [1, 2, 3, 4],
276+
"patch": [{"op": "remove", "path": "/0"}],
277+
"expected": [2, 3, 4] },
278+
279+
{ "comment": "test remove with bad index should fail",
280+
"doc": [1, 2, 3, 4],
281+
"patch": [{"op": "remove", "path": "/1e0"}],
282+
"error": "remove op shouldn't remove from array with bad number" },
283+
284+
{ "comment": "test replace with bad number should fail",
285+
"doc": [""],
286+
"patch": [{"op": "replace", "path": "/1e0", "value": false}],
287+
"error": "replace op shouldn't replace in array with bad number" },
288+
289+
{ "comment": "test copy with bad number should fail",
290+
"doc": {"baz": [1,2,3], "bar": 1},
291+
"patch": [{"op": "copy", "from": "/baz/1e0", "path": "/boo"}],
292+
"error": "copy op shouldn't work with bad number" },
293+
294+
{ "comment": "test move with bad number should fail",
295+
"doc": {"foo": 1, "baz": [1,2,3,4]},
296+
"patch": [{"op": "move", "from": "/baz/1e0", "path": "/foo"}],
297+
"error": "move op shouldn't work with bad number" },
298+
299+
{ "comment": "test add with bad number should fail",
300+
"doc": ["foo", "sil"],
301+
"patch": [{"op": "add", "path": "/1e0", "value": "bar"}],
302+
"error": "add op shouldn't add to array with bad number" }
267303
]

0 commit comments

Comments
 (0)