spec_tests.json 3.9 KB

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