Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mikemccabe/json-patch-tests
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: json-patch/json-patch-tests
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Jun 30, 2014

  1. typo

    Mike McCabe committed Jun 30, 2014
    Copy the full SHA
    8d9423a View commit details
  2. Add tests for patch validation - #11

    Mike McCabe committed Jun 30, 2014
    Copy the full SHA
    6fc98e3 View commit details
  3. Update language

    Mike McCabe committed Jun 30, 2014
    Copy the full SHA
    39068c6 View commit details

Commits on Jul 1, 2014

  1. Merge pull request #13 from json-patch/patch_validation

    Add tests for patch validation
    mnot committed Jul 1, 2014
    Copy the full SHA
    5dd935d View commit details

Commits on Jul 16, 2014

  1. Add test for repeated array removes. Resolves #14.

    Mike McCabe committed Jul 16, 2014
    Copy the full SHA
    3151673 View commit details
  2. Copy the full SHA
    4edfddb View commit details

Commits on Oct 7, 2014

  1. Copy the full SHA
    86ad182 View commit details

Commits on Jan 21, 2015

  1. Clarify what test file is what.

    Closes #16
    mikemccabe committed Jan 21, 2015
    Copy the full SHA
    b71d0be View commit details

Commits on Mar 27, 2015

  1. Copy the full SHA
    baa57f9 View commit details

Commits on Mar 29, 2015

  1. Merge pull request #17 from tomalec/changingNullValue

    Add tests for replacing, moving, coping, and removing `null` value
    mnot committed Mar 29, 2015
    Copy the full SHA
    14b0713 View commit details

Commits on Jun 21, 2015

  1. Add .editorconfig

    sonnyp committed Jun 21, 2015
    Copy the full SHA
    0947089 View commit details

Commits on Jun 22, 2015

  1. Merge pull request #19 from sonnyp/editorconfig

    Add .editorconfig
    mikemccabe committed Jun 22, 2015
    Copy the full SHA
    6ec6814 View commit details

Commits on Jun 23, 2015

  1. Copy the full SHA
    24fff54 View commit details
  2. Update tests.json

    sonnyp committed Jun 23, 2015
    Copy the full SHA
    7e39cd2 View commit details

Commits on Jul 15, 2015

  1. Merge pull request #21 from sonnyp/patch-2

    Add comment to push item to array test
    mnot committed Jul 15, 2015
    Copy the full SHA
    1327f8c View commit details

Commits on Aug 16, 2015

  1. Test array size when adding to array

    In [Section 4.1](https://tools.ietf.org/html/rfc6902#section-4.1) it states:
    
    > The specified index MUST NOT be greater than the number of elements in the array.
    grncdr committed Aug 16, 2015
    Copy the full SHA
    6c1c39d View commit details

Commits on Aug 19, 2015

  1. Merge pull request #24 from grncdr/patch-1

    Test array size when adding to array
    bruth committed Aug 19, 2015
    Copy the full SHA
    c91f7e8 View commit details

Commits on Mar 26, 2016

  1. Copy the full SHA
    84d3c86 View commit details

Commits on May 18, 2016

  1. Test for trailing slash when not the root element

    The existing test covers the trailing slash at only the root node.
    morganatwishpond committed May 18, 2016
    Copy the full SHA
    2986c5a View commit details
  2. Merge pull request #28 from morganatwishpond/master

    Test for trailing slash when not the root element
    bruth committed May 18, 2016
    Copy the full SHA
    3ad2ba8 View commit details
  3. npm module

    sonnyp committed May 18, 2016
    Copy the full SHA
    a6f9cfa View commit details

Commits on May 24, 2016

  1. Merge pull request #25 from JSON8/node.js

    npm package
    bruth committed May 24, 2016
    Copy the full SHA
    269f54b View commit details

Commits on Feb 15, 2017

  1. Merge pull request #27 from darrenjs/master

    test numeric tokens with leading zeros are rejected
    mnot authored Feb 15, 2017
    Copy the full SHA
    aa68c84 View commit details

Commits on Mar 22, 2017

  1. Copy the full SHA
    6e51de2 View commit details
  2. Merge pull request #33 from norpan/patch-2

    Removing nonexistent field or index should fail
    bruth authored Mar 22, 2017
    Copy the full SHA
    716417e View commit details

Commits on May 1, 2017

  1. Add tests for replacing the root document (#30)

    * Add tests for replacing the root document
    * Use add operation since deleting root document is undefined
    nicksnyder authored and bruth committed May 1, 2017
    Copy the full SHA
    5405313 View commit details
  2. tests.json: Remove trailing whitespace

    FSMaxB authored and bruth committed May 1, 2017
    Copy the full SHA
    01348ad View commit details
  3. tests.json: Test case sensitivity

    FSMaxB authored and bruth committed May 1, 2017
    Copy the full SHA
    0dd0fbc View commit details

Commits on Nov 18, 2017

  1. Copy the full SHA
    c2fae3a View commit details

Commits on Nov 20, 2017

  1. Merge pull request #37 from FormAPI/missing_parent_key

    Added a test case to check "replace" op with a missing parent key
    tenderlove authored Nov 20, 2017
    Copy the full SHA
    99264bb View commit details

Commits on Sep 4, 2018

  1. Fix « Empty-string element » test

    vincedev authored and bruth committed Sep 4, 2018
    Copy the full SHA
    1586cdf View commit details
  2. Copy the full SHA
    ecf01e7 View commit details
  3. Copy the full SHA
    53283fc View commit details
  4. Copy the full SHA
    855f2a4 View commit details
  5. Copy the full SHA
    8bae8ed View commit details
  6. Fix anonymous test

    vincedev authored and bruth committed Sep 4, 2018
    Copy the full SHA
    09dee56 View commit details

Commits on Sep 19, 2018

  1. test absent 'from' location for copy and move

    rfc6902: The "from" location MUST exist for the operation to be successful.
    mr-mixas committed Sep 19, 2018
    Copy the full SHA
    66817e7 View commit details
  2. Merge pull request #39 from mr-mixas/test-absent-from-location-for-co…

    …py-and-move-ops
    
    test absent 'from' location for copy and move
    mnot authored Sep 19, 2018
    Copy the full SHA
    9ecd703 View commit details

Commits on Sep 22, 2018

  1. tests for absent and invalid paths

    * Operation objects MUST have exactly one "path" member. (RFC 6902)
    
    * A JSON Pointer is a Unicode string containing a sequence of zero
      or more reference tokens, each prefixed by a '/' character. (RFC 6901)
    mr-mixas committed Sep 22, 2018
    Copy the full SHA
    9cd84e0 View commit details

Commits on Dec 2, 2018

  1. Merge pull request #40 from mr-mixas/erroneous-path-parameter

    tests for absent and invalid paths
    mnot authored Dec 2, 2018
    Copy the full SHA
    f42d357 View commit details

Commits on May 4, 2020

  1. Add test for deep nonexistent path

    Related PR - fixing an unhandled exception in a Ruby implementation of JSON patch:
    tenderlove/hana#15
    odlp committed May 4, 2020
    Copy the full SHA
    260f59d View commit details
  2. Merge pull request #43 from odlp/test-deep-nonexistent-path

    Add test for deep nonexistent path
    tenderlove authored May 4, 2020
    Copy the full SHA
    ea3af85 View commit details

Commits on Aug 22, 2024

  1. Test change after copy

    cyangle committed Aug 22, 2024
    Copy the full SHA
    127f190 View commit details
  2. Update tests.json

    Refactor test case name
    cyangle authored Aug 22, 2024
    Copy the full SHA
    98e13a6 View commit details

Commits on Feb 21, 2025

  1. Merge pull request #46 from cyangle/change_after_copy

    Test change after copy
    tenderlove authored Feb 21, 2025
    Copy the full SHA
    2a928f9 View commit details
Showing with 264 additions and 13 deletions.
  1. +10 −0 .editorconfig
  2. +2 −0 .gitignore
  3. +2 −0 .npmignore
  4. +28 −4 README.md
  5. +15 −0 package.json
  6. +4 −3 spec_tests.json
  7. +203 −6 tests.json
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# EditorConfig is awesome: http://EditorConfig.org

root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true
indent_style = space
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*~
\#*
!.editorconfig
!.gitignore
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.editorconfig
.gitignore
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
JSON Patch Tests
================

These are test cases for implementations of the [IETF JSON Patch
draft](http://tools.ietf.org/html/draft-ietf-appsawg-json-patch).
These are test cases for implementations of [IETF JSON Patch (RFC6902)](http://tools.ietf.org/html/rfc6902).

Some implementations can be found at [jsonpatch.com](http://jsonpatch.com).


Test Format
@@ -21,7 +22,30 @@ test record is an object with the following members:
All fields except 'doc' and 'patch' are optional. Test records consisting only
of a comment are also OK.

These tests are not complete, or even correct - help welcome!

Files
-----

- tests.json: the main test file
- spec_tests.json: tests from the RFC6902 spec


Writing Tests
-------------

All tests should have a descriptive comment. Tests should be as
simple as possible - just what's required to test a specific piece of
behavior. If you want to test interacting behaviors, create tests for
each behavior as well as the interaction.

If an 'error' member is specified, the error text should describe the
error the implementation should raise - *not* what's being tested.
Implementation error strings will vary, but the suggested error should
be easily matched to the implementation error string. Try to avoid
creating error tests that might pass because an incorrect error was
reported.

Please feel free to contribute!


Credits
@@ -35,7 +59,7 @@ extended by [Mike McCabe](https://github.com/mikemccabe).
License
-------

Copyright 2012 The Authors
Copyright 2014 The Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "json-patch-test-suite",
"version": "1.1.0",
"description": "JSON Patch RFC 6902 test suite",
"repository": "github:json-patch/json-patch-tests",
"homepage": "https://github.com/json-patch/json-patch-tests",
"bugs": "https://github.com/json-patch/json-patch-tests/issues",
"keywords": [
"JSON",
"Patch",
"test",
"suite"
],
"license": "Apache-2.0"
}
7 changes: 4 additions & 3 deletions spec_tests.json
Original file line number Diff line number Diff line change
@@ -174,14 +174,14 @@
},

{
"comment": "A.12. Adding to a Non-existant Target",
"comment": "A.12. Adding to a Non-existent Target",
"doc": {
"foo": "bar"
},
"patch": [
{ "op": "add", "path": "/baz/bat", "value": "qux" }
],
"error": "add to a non-existant target"
"error": "add to a non-existent target"
},

{
@@ -192,7 +192,8 @@
"patch": [
{ "op": "add", "path": "/baz", "value": "qux", "op": "remove" }
],
"error": "operation has two 'op' members"
"error": "operation has two 'op' members",
"disabled": true
},

{
209 changes: 203 additions & 6 deletions tests.json
Original file line number Diff line number Diff line change
@@ -55,11 +55,31 @@
"expected": "bar",
"disabled": true },

{ "comment": "replace object document with array document?",
"doc": {},
"patch": [{"op": "add", "path": "", "value": []}],
"expected": [] },

{ "comment": "replace array document with object document?",
"doc": [],
"patch": [{"op": "add", "path": "", "value": {}}],
"expected": {} },

{ "comment": "append to root array document?",
"doc": [],
"patch": [{"op": "add", "path": "/-", "value": "hi"}],
"expected": ["hi"] },

{ "comment": "Add, / target",
"doc": {},
"patch": [ {"op": "add", "path": "/", "value":1 } ],
"expected": {"":1} },

{ "comment": "Add, /foo/ deep target (trailing slash)",
"doc": {"foo": {}},
"patch": [ {"op": "add", "path": "/foo/", "value":1 } ],
"expected": {"foo":{"": 1}} },

{ "comment": "Add composite value at top level",
"doc": {"foo": 1},
"patch": [{"op": "add", "path": "/bar", "value": [1, 2]}],
@@ -107,10 +127,16 @@
"patch": [{"op": "add", "path": "/0", "value": "bar"}],
"expected": ["bar", "foo", "sil"] },

{ "doc": ["foo", "sil"],
{ "comment": "push item to array via last index + 1",
"doc": ["foo", "sil"],
"patch": [{"op":"add", "path": "/2", "value": "bar"}],
"expected": ["foo", "sil", "bar"] },

{ "comment": "add item to array at index > length should fail",
"doc": ["foo", "sil"],
"patch": [{"op":"add", "path": "/3", "value": "bar"}],
"error": "index is greater than number of items in array" },

{ "comment": "test against implementation-specific numeric parsing",
"doc": {"1e0": "foo"},
"patch": [{"op": "test", "path": "/1e0", "value": "foo"}],
@@ -176,25 +202,59 @@
"patch": [{"op": "replace", "path": "", "value": {"baz": "qux"}}],
"expected": {"baz": "qux"} },

{ "comment": "test replace with missing parent key should fail",
"doc": {"bar": "baz"},
"patch": [{"op": "replace", "path": "/foo/bar", "value": false}],
"error": "replace op should fail with missing parent key" },

{ "comment": "spurious patch properties",
"doc": {"foo": 1},
"patch": [{"op": "test", "path": "/foo", "value": 1, "spurious": 1}],
"expected": {"foo": 1} },

{ "doc": {"foo": null},
"patch": [{"op": "test", "path": "/foo", "value": null}],
"comment": "null value should still be valid obj property" },
"expected": {"foo": null},
"comment": "null value should be valid obj property" },

{ "doc": {"foo": null},
"patch": [{"op": "replace", "path": "/foo", "value": "truthy"}],
"expected": {"foo": "truthy"},
"comment": "null value should be valid obj property to be replaced with something truthy" },

{ "doc": {"foo": null},
"patch": [{"op": "move", "from": "/foo", "path": "/bar"}],
"expected": {"bar": null},
"comment": "null value should be valid obj property to be moved" },

{ "doc": {"foo": null},
"patch": [{"op": "copy", "from": "/foo", "path": "/bar"}],
"expected": {"foo": null, "bar": null},
"comment": "null value should be valid obj property to be copied" },

{ "doc": {"foo": null},
"patch": [{"op": "remove", "path": "/foo"}],
"expected": {},
"comment": "null value should be valid obj property to be removed" },

{ "doc": {"foo": "bar"},
"patch": [{"op": "replace", "path": "/foo", "value": null}],
"expected": {"foo": null},
"comment": "null value should still be valid obj property replace other value" },

{ "doc": {"foo": {"foo": 1, "bar": 2}},
"patch": [{"op": "test", "path": "/foo", "value": {"bar": 2, "foo": 1}}],
"expected": {"foo": {"foo": 1, "bar": 2}},
"comment": "test should pass despite rearrangement" },

{ "doc": {"foo": [{"foo": 1, "bar": 2}]},
"patch": [{"op": "test", "path": "/foo", "value": [{"bar": 2, "foo": 1}]}],
"expected": {"foo": [{"foo": 1, "bar": 2}]},
"comment": "test should pass despite (nested) rearrangement" },

{ "doc": {"foo": {"bar": [1, 2, 5, 4]}},
"patch": [{"op": "test", "path": "/foo", "value": {"bar": [1, 2, 5, 4]}}],
"expected": {"foo": {"bar": [1, 2, 5, 4]}},
"comment": "test should pass - no error" },

{ "doc": {"foo": {"bar": [1, 2, 5, 4]}},
@@ -208,7 +268,8 @@

{ "comment": "Empty-string element",
"doc": { "": 1 },
"patch": [{"op": "test", "path": "/", "value": 1}] },
"patch": [{"op": "test", "path": "/", "value": 1}],
"expected": { "": 1 } },

{ "doc": {
"foo": ["bar", "baz"],
@@ -232,8 +293,23 @@
{"op": "test", "path": "/i\\j", "value": 5},
{"op": "test", "path": "/k\"l", "value": 6},
{"op": "test", "path": "/ ", "value": 7},
{"op": "test", "path": "/m~0n", "value": 8}] },

{"op": "test", "path": "/m~0n", "value": 8}],
"expected": {
"": 0,
" ": 7,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"foo": [
"bar",
"baz"
],
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
"m~n": 8
}
},
{ "comment": "Move to same location has no effect",
"doc": {"foo": 1},
"patch": [{"op": "move", "from": "/foo", "path": "/foo"}],
@@ -276,6 +352,12 @@
"patch": [{"op": "remove", "path": "/0"}],
"expected": [2, 3, 4] },

{ "comment": "test repeated removes",
"doc": [1, 2, 3, 4],
"patch": [{ "op": "remove", "path": "/1" },
{ "op": "remove", "path": "/2" }],
"expected": [1, 3] },

{ "comment": "test remove with bad index should fail",
"doc": [1, 2, 3, 4],
"patch": [{"op": "remove", "path": "/1e0"}],
@@ -299,5 +381,120 @@
{ "comment": "test add with bad number should fail",
"doc": ["foo", "sil"],
"patch": [{"op": "add", "path": "/1e0", "value": "bar"}],
"error": "add op shouldn't add to array with bad number" }
"error": "add op shouldn't add to array with bad number" },

{ "comment": "missing 'path' parameter",
"doc": {},
"patch": [ { "op": "add", "value": "bar" } ],
"error": "missing 'path' parameter" },

{ "comment": "'path' parameter with null value",
"doc": {},
"patch": [ { "op": "add", "path": null, "value": "bar" } ],
"error": "null is not valid value for 'path'" },

{ "comment": "invalid JSON Pointer token",
"doc": {},
"patch": [ { "op": "add", "path": "foo", "value": "bar" } ],
"error": "JSON Pointer should start with a slash" },

{ "comment": "missing 'value' parameter to add",
"doc": [ 1 ],
"patch": [ { "op": "add", "path": "/-" } ],
"error": "missing 'value' parameter" },

{ "comment": "missing 'value' parameter to replace",
"doc": [ 1 ],
"patch": [ { "op": "replace", "path": "/0" } ],
"error": "missing 'value' parameter" },

{ "comment": "missing 'value' parameter to test",
"doc": [ null ],
"patch": [ { "op": "test", "path": "/0" } ],
"error": "missing 'value' parameter" },

{ "comment": "missing value parameter to test - where undef is falsy",
"doc": [ false ],
"patch": [ { "op": "test", "path": "/0" } ],
"error": "missing 'value' parameter" },

{ "comment": "missing from parameter to copy",
"doc": [ 1 ],
"patch": [ { "op": "copy", "path": "/-" } ],
"error": "missing 'from' parameter" },

{ "comment": "missing from location to copy",
"doc": { "foo": 1 },
"patch": [ { "op": "copy", "from": "/bar", "path": "/foo" } ],
"error": "missing 'from' location" },

{ "comment": "missing from parameter to move",
"doc": { "foo": 1 },
"patch": [ { "op": "move", "path": "" } ],
"error": "missing 'from' parameter" },

{ "comment": "missing from location to move",
"doc": { "foo": 1 },
"patch": [ { "op": "move", "from": "/bar", "path": "/foo" } ],
"error": "missing 'from' location" },

{ "comment": "duplicate ops",
"doc": { "foo": "bar" },
"patch": [ { "op": "add", "path": "/baz", "value": "qux",
"op": "move", "from":"/foo" } ],
"error": "patch has two 'op' members",
"disabled": true },

{ "comment": "unrecognized op should fail",
"doc": {"foo": 1},
"patch": [{"op": "spam", "path": "/foo", "value": 1}],
"error": "Unrecognized op 'spam'" },

{ "comment": "test with bad array number that has leading zeros",
"doc": ["foo", "bar"],
"patch": [{"op": "test", "path": "/00", "value": "foo"}],
"error": "test op should reject the array value, it has leading zeros" },

{ "comment": "test with bad array number that has leading zeros",
"doc": ["foo", "bar"],
"patch": [{"op": "test", "path": "/01", "value": "bar"}],
"error": "test op should reject the array value, it has leading zeros" },

{ "comment": "Removing nonexistent field",
"doc": {"foo" : "bar"},
"patch": [{"op": "remove", "path": "/baz"}],
"error": "removing a nonexistent field should fail" },

{ "comment": "Removing deep nonexistent path",
"doc": {"foo" : "bar"},
"patch": [{"op": "remove", "path": "/missing1/missing2"}],
"error": "removing a nonexistent field should fail" },

{ "comment": "Removing nonexistent index",
"doc": ["foo", "bar"],
"patch": [{"op": "remove", "path": "/2"}],
"error": "removing a nonexistent index should fail" },

{ "comment": "Patch with different capitalisation than doc",
"doc": {"foo":"bar"},
"patch": [{"op": "add", "path": "/FOO", "value": "BAR"}],
"expected": {"foo": "bar", "FOO": "BAR"} },

{ "comment": "test copy object then change destination",
"doc": {"foo": {"bar": {"baz": [{"boo": "net"}]}}},
"patch": [
{"op": "copy", "from": "/foo", "path": "/bak"},
{"op": "replace", "path": "/bak/bar/baz/0/boo", "value": "qux"}
],
"expected": {"foo": {"bar": {"baz": [{"boo": "net"}]}}, "bak": {"bar": {"baz": [{"boo":"qux"}]}}} },

{ "comment": "test copy object then change source",
"doc": {"foo": {"bar": {"baz": [{"boo": "net"}]}}},
"patch": [
{"op": "copy", "from": "/foo", "path": "/bak"},
{"op": "replace", "path": "/foo/bar/baz/0/boo", "value": "qux"}
],
"expected": {"foo": {"bar": {"baz": [{"boo": "qux"}]}}, "bak": {"bar": {"baz": [{"boo":"net"}]}}}
}

]