Skip to content

Commit 5dd935d

Browse files
committed
Merge pull request #13 from json-patch/patch_validation
Add tests for patch validation
2 parents 39068c6 + 6fc98e3 commit 5dd935d

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

tests.json

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,5 +299,47 @@
299299
{ "comment": "test add with bad number should fail",
300300
"doc": ["foo", "sil"],
301301
"patch": [{"op": "add", "path": "/1e0", "value": "bar"}],
302-
"error": "add op shouldn't add to array with bad number" }
302+
"error": "add op shouldn't add to array with bad number" },
303+
304+
{ "comment": "missing 'value' parameter to add",
305+
"doc": [ 1 ],
306+
"patch": [ { "op": "add", "path": "/-" } ],
307+
"error": "missing 'value' parameter" },
308+
309+
{ "comment": "missing 'value' parameter to replace",
310+
"doc": [ 1 ],
311+
"patch": [ { "op": "replace", "path": "/0" } ],
312+
"error": "missing 'value' parameter" },
313+
314+
{ "comment": "missing 'value' parameter to test",
315+
"doc": [ null ],
316+
"patch": [ { "op": "test", "path": "/0" } ],
317+
"error": "missing 'value' parameter" },
318+
319+
{ "comment": "missing value parameter to test - where undef is falsy",
320+
"doc": [ false ],
321+
"patch": [ { "op": "test", "path": "/0" } ],
322+
"error": "missing 'value' parameter" },
323+
324+
{ "comment": "missing from parameter to copy",
325+
"doc": [ 1 ],
326+
"patch": [ { "op": "copy", "path": "/-" } ],
327+
"error": "missing 'from' parameter" },
328+
329+
{ "comment": "missing from parameter to move",
330+
"doc": { "foo": 1 },
331+
"patch": [ { "op": "move", "path": "" } ],
332+
"error": "missing 'from' parameter" },
333+
334+
{ "comment": "duplicate ops",
335+
"doc": { "foo": "bar" },
336+
"patch": [ { "op": "add", "path": "/baz", "value": "qux",
337+
"op": "move", "from":"/foo" } ],
338+
"error": "patch has two 'op' members",
339+
"disabled": true },
340+
341+
{ "comment": "unrecognized op should fail",
342+
"doc": {"foo": 1},
343+
"patch": [{"op": "spam", "path": "/foo", "value": 1}],
344+
"error": "Unrecognized op 'spam'" }
303345
]

0 commit comments

Comments
 (0)