Skip to content

Commit 04c9049

Browse files
committed
add spec_tests from to-be-published draft 07.
1 parent 22fcd93 commit 04c9049

File tree

1 file changed

+189
-0
lines changed

1 file changed

+189
-0
lines changed

spec_tests.json

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
[
2+
{
3+
"comment": "A.1. Adding an Object Member",
4+
"doc": {
5+
"foo": "bar"
6+
},
7+
"patch": [
8+
{ "op": "add", "path": "/baz", "value": "qux" }
9+
],
10+
"expected": {
11+
"baz": "qux",
12+
"foo": "bar"
13+
}
14+
},
15+
16+
{
17+
"comment": "A.2. Adding an Array Element",
18+
"doc": {
19+
"foo": [ "bar", "baz" ]
20+
},
21+
"patch": [
22+
{ "op": "add", "path": "/foo/1", "value": "qux" }
23+
],
24+
"expected": {
25+
"foo": [ "bar", "qux", "baz" ]
26+
}
27+
},
28+
29+
{
30+
"comment": "A.3. Removing an Object Member",
31+
"doc": {
32+
"baz": "qux",
33+
"foo": "bar"
34+
},
35+
"patch": [
36+
{ "op": "remove", "path": "/baz" }
37+
],
38+
"expected": {
39+
"foo": "bar"
40+
}
41+
},
42+
43+
{
44+
"comment": "A.4. Removing an Array Element",
45+
"doc": {
46+
"foo": [ "bar", "qux", "baz" ]
47+
},
48+
"patch": [
49+
{ "op": "remove", "path": "/foo/1" }
50+
],
51+
"expected": {
52+
"foo": [ "bar", "baz" ]
53+
}
54+
},
55+
56+
{
57+
"comment": "A.5. Replacing a Value",
58+
"doc": {
59+
"baz": "qux",
60+
"foo": "bar"
61+
},
62+
"patch": [
63+
{ "op": "replace", "path": "/baz", "value": "boo" }
64+
],
65+
"expected": {
66+
"baz": "boo",
67+
"foo": "bar"
68+
}
69+
},
70+
71+
{
72+
"comment": "A.6. Moving a Value",
73+
"doc": {
74+
"foo": {
75+
"bar": "baz",
76+
"waldo": "fred"
77+
},
78+
"qux": {
79+
"corge": "grault"
80+
}
81+
},
82+
"patch": [
83+
{ "op": "move", "from": "/foo/waldo", "path": "/qux/thud" }
84+
],
85+
"expected": {
86+
"foo": {
87+
"bar": "baz"
88+
},
89+
"qux": {
90+
"corge": "grault",
91+
"thud": "fred"
92+
}
93+
}
94+
},
95+
96+
{
97+
"comment": "A.7. Moving an Array Element",
98+
"doc": {
99+
"foo": [ "all", "grass", "cows", "eat" ]
100+
},
101+
"patch": [
102+
{ "op": "move", "from": "/foo/1", "path": "/foo/3" }
103+
],
104+
"expected": {
105+
"foo": [ "all", "cows", "eat", "grass" ]
106+
}
107+
108+
},
109+
110+
{
111+
"comment": "A.8. Testing a Value: Success",
112+
"doc": {
113+
"baz": "qux",
114+
"foo": [ "a", 2, "c" ]
115+
},
116+
"patch": [
117+
{ "op": "test", "path": "/baz", "value": "qux" },
118+
{ "op": "test", "path": "/foo/1", "value": 2 }
119+
],
120+
"expected": {
121+
"baz": "qux",
122+
"foo": [ "a", 2, "c" ]
123+
}
124+
},
125+
126+
{
127+
"comment": "A.9. Testing a Value: Error",
128+
"doc": {
129+
"baz": "qux"
130+
},
131+
"patch": [
132+
{ "op": "test", "path": "/baz", "value": "bar" }
133+
],
134+
"error": "string not equivalent"
135+
},
136+
137+
{
138+
"comment": "A.10. Adding a nested Member Object",
139+
"doc": {
140+
"foo": "bar"
141+
},
142+
"patch": [
143+
{ "op": "add", "path": "/child", "value": { "grandchild": { } } }
144+
],
145+
"expected": {
146+
"foo": "bar",
147+
"child": {
148+
"grandchild": {
149+
}
150+
}
151+
}
152+
},
153+
154+
{
155+
"comment": "A.11. Ignoring Unrecognized Elements",
156+
"doc": {
157+
"foo":"bar"
158+
},
159+
"patch": [
160+
{ "op": "add", "path": "/baz", "value": "qux", "xyz": 123 }
161+
],
162+
"expected": {
163+
"foo":"bar",
164+
"baz":"qux"
165+
}
166+
},
167+
168+
{
169+
"comment": "A.12. Adding to a Non-existant Target",
170+
"doc": {
171+
"foo": "bar"
172+
},
173+
"patch": [
174+
{ "op": "add", "path": "/baz/bat", "value": "qux" }
175+
],
176+
"error": "add to a non-existant target"
177+
},
178+
179+
{
180+
"comment": "Invalid JSON Patch Document",
181+
"doc": {
182+
"foo": "bar"
183+
},
184+
"patch": [
185+
{ "op": "add", "path": "/baz", "value": "qux", "op": "remove" }
186+
],
187+
"error": "operation has two 'op' members"
188+
}
189+
]

0 commit comments

Comments
 (0)