Skip to content

Commit 7ae2a9f

Browse files
committed
Merge pull request #4 from json-patch/master
get the latest.
2 parents 5b6bc0d + 7e591b6 commit 7ae2a9f

File tree

2 files changed

+80
-26
lines changed

2 files changed

+80
-26
lines changed

spec_tests.json

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
[
2+
{
3+
"comment": "4.1. add with missing object",
4+
"doc": { "q": { "bar": 2 } },
5+
"patch": [ {"op": "add", "path": "/a/b", "value": 1} ],
6+
"error":
7+
"path /a does not exist -- missing objects are not created recursively"
8+
},
9+
210
{
311
"comment": "A.1. Adding an Object Member",
412
"doc": {
@@ -14,7 +22,7 @@
1422
},
1523

1624
{
17-
"comment": "A.2. Adding an Array Element",
25+
"comment": "A.2. Adding an Array Element",
1826
"doc": {
1927
"foo": [ "bar", "baz" ]
2028
},
@@ -58,7 +66,7 @@
5866
"doc": {
5967
"baz": "qux",
6068
"foo": "bar"
61-
},
69+
},
6270
"patch": [
6371
{ "op": "replace", "path": "/baz", "value": "boo" }
6472
],
@@ -78,10 +86,10 @@
7886
"qux": {
7987
"corge": "grault"
8088
}
81-
},
89+
},
8290
"patch": [
8391
{ "op": "move", "from": "/foo/waldo", "path": "/qux/thud" }
84-
],
92+
],
8593
"expected": {
8694
"foo": {
8795
"bar": "baz"
@@ -97,10 +105,10 @@
97105
"comment": "A.7. Moving an Array Element",
98106
"doc": {
99107
"foo": [ "all", "grass", "cows", "eat" ]
100-
},
108+
},
101109
"patch": [
102110
{ "op": "move", "from": "/foo/1", "path": "/foo/3" }
103-
],
111+
],
104112
"expected": {
105113
"foo": [ "all", "cows", "eat", "grass" ]
106114
}
@@ -131,7 +139,7 @@
131139
"patch": [
132140
{ "op": "test", "path": "/baz", "value": "bar" }
133141
],
134-
"error": "string not equivalent"
142+
"error": "string not equivalent"
135143
},
136144

137145
{
@@ -150,21 +158,21 @@
150158
}
151159
}
152160
},
153-
161+
154162
{
155163
"comment": "A.11. Ignoring Unrecognized Elements",
156164
"doc": {
157165
"foo":"bar"
158-
},
166+
},
159167
"patch": [
160168
{ "op": "add", "path": "/baz", "value": "qux", "xyz": 123 }
161169
],
162170
"expected": {
163-
"foo":"bar",
171+
"foo":"bar",
164172
"baz":"qux"
165173
}
166174
},
167-
175+
168176
{
169177
"comment": "A.12. Adding to a Non-existant Target",
170178
"doc": {
@@ -175,9 +183,9 @@
175183
],
176184
"error": "add to a non-existant target"
177185
},
178-
186+
179187
{
180-
"comment": "Invalid JSON Patch Document",
188+
"comment": "A.13 Invalid JSON Patch Document",
181189
"doc": {
182190
"foo": "bar"
183191
},
@@ -186,18 +194,39 @@
186194
],
187195
"error": "operation has two 'op' members"
188196
},
189-
190-
{
191-
"comment": "~ Escape Ordering",
197+
198+
{
199+
"comment": "A.14. ~ Escape Ordering",
192200
"doc": {
193201
"/": 9,
194-
"~1": 10
202+
"~1": 10
195203
},
196-
"patch": [{"op": "test", "path": "/~01", "value":"10"}],
204+
"patch": [{"op": "test", "path": "/~01", "value": 10}],
197205
"expected": {
198206
"/": 9,
199-
"~1": 10
207+
"~1": 10
208+
}
209+
},
210+
211+
{
212+
"comment": "A.15. Comparing Strings and Numbers",
213+
"doc": {
214+
"/": 9,
215+
"~1": 10
216+
},
217+
"patch": [{"op": "test", "path": "/~01", "value": "10"}],
218+
"error": "number is not equal to string"
219+
},
220+
221+
{
222+
"comment": "A.16. Adding an Array Value",
223+
"doc": {
224+
"foo": ["bar"]
225+
},
226+
"patch": [{ "op": "add", "path": "/foo/-", "value": ["abc", "def"] }],
227+
"expected": {
228+
"foo": ["bar", ["abc", "def"]]
200229
}
201230
}
202-
203-
]
231+
232+
]

tests.json

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,19 @@
108108
"expected": ["bar", "foo", "sil"] },
109109

110110
{ "doc": ["foo", "sil"],
111-
"patch": [{"op":" add", "path": "/2", "value": "bar"}],
111+
"patch": [{"op":"add", "path": "/2", "value": "bar"}],
112112
"expected": ["foo", "sil", "bar"] },
113113

114+
{ "comment": "test against implementation-specific numeric parsing",
115+
"doc": {"1e0": "foo"},
116+
"patch": [{"op": "test", "path": "/1e0", "value": "foo"}],
117+
"expected": {"1e0": "foo"} },
118+
119+
{ "comment": "test with bad number should fail",
120+
"doc": ["foo", "bar"],
121+
"patch": [{"op": "test", "path": "/1e0", "value": "bar"}],
122+
"error": "test op shouldn't get array element 1" },
123+
114124
{ "doc": ["foo", "sil"],
115125
"patch": [{"op": "add", "path": "/bar", "value": 42}],
116126
"error": "Object operation on array target" },
@@ -223,20 +233,35 @@
223233

224234
{ "comment": "Move to same location has no effect",
225235
"doc": {"foo": 1},
226-
"patch": [{"op": "move", "path": "/foo", "to": "/foo"}],
236+
"patch": [{"op": "move", "from": "/foo", "path": "/foo"}],
227237
"expected": {"foo": 1} },
228238

229239
{ "doc": {"foo": 1, "baz": [{"qux": "hello"}]},
230-
"patch": [{"op": "move", "path": "/foo", "to": "/bar"}],
240+
"patch": [{"op": "move", "from": "/foo", "path": "/bar"}],
231241
"expected": {"baz": [{"qux": "hello"}], "bar": 1} },
232242

233243
{ "doc": {"baz": [{"qux": "hello"}], "bar": 1},
234-
"patch": [{"op": "move", "path": "/baz/0/qux", "to": "/baz/1"}],
244+
"patch": [{"op": "move", "from": "/baz/0/qux", "path": "/baz/1"}],
235245
"expected": {"baz": [{}, "hello"], "bar": 1} },
236246

237247
{ "doc": {"baz": [{"qux": "hello"}], "bar": 1},
238-
"patch": [{"op": "copy", "path": "/baz/0", "to": "/boo"}],
248+
"patch": [{"op": "copy", "from": "/baz/0", "path": "/boo"}],
239249
"expected": {"baz":[{"qux":"hello"}],"bar":1,"boo":{"qux":"hello"}} },
240250

251+
{ "comment": "replacing the root of the document is possible with add",
252+
"doc": {"foo": "bar"},
253+
"patch": [{"op": "add", "path": "", "value": {"baz": "qux"}}],
254+
"expected": {"baz":"qux"}},
255+
256+
{ "comment": "Adding to \"/-\" adds to the end of the array",
257+
"doc": [ 1, 2 ],
258+
"patch": [ { "op": "add", "path": "/-", "value": { "foo": [ "bar", "baz" ] } } ],
259+
"expected": [ 1, 2, { "foo": [ "bar", "baz" ] } ]},
260+
261+
{ "comment": "Adding to \"/-\" adds to the end of the array, even n levels down",
262+
"doc": [ 1, 2, [ 3, [ 4, 5 ] ] ],
263+
"patch": [ { "op": "add", "path": "/2/1/-", "value": { "foo": [ "bar", "baz" ] } } ],
264+
"expected": [ 1, 2, [ 3, [ 4, 5, { "foo": [ "bar", "baz" ] } ] ] ]},
265+
241266
{ "comment": "tests complete" }
242267
]

0 commit comments

Comments
 (0)