cjson-utils-tests.json 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. [
  2. {
  3. "comment": "1",
  4. "doc": { "foo": "bar"},
  5. "patch": [{ "op": "add", "path": "/baz", "value": "qux" }],
  6. "expected": {"baz": "qux", "foo": "bar"}
  7. },
  8. {
  9. "comment": "2",
  10. "doc": { "foo": [ "bar", "baz" ] },
  11. "patch": [{ "op": "add", "path": "/foo/1", "value": "qux" }],
  12. "expected": {"foo": [ "bar", "qux", "baz" ] }
  13. },
  14. {
  15. "comment": "3",
  16. "doc": {"baz": "qux","foo": "bar"},
  17. "patch": [{ "op": "remove", "path": "/baz" }],
  18. "expected": {"foo": "bar" }
  19. },
  20. {
  21. "comment": "4",
  22. "doc": { "foo": [ "bar", "qux", "baz" ] },
  23. "patch": [{ "op": "remove", "path": "/foo/1" }],
  24. "expected": {"foo": [ "bar", "baz" ] }
  25. },
  26. {
  27. "comment": "5",
  28. "doc": { "baz": "qux","foo": "bar"},
  29. "patch": [{ "op": "replace", "path": "/baz", "value": "boo" }],
  30. "expected": {"baz": "boo","foo": "bar"}
  31. },
  32. {
  33. "comment": "6",
  34. "doc": {"foo": {"bar": "baz","waldo": "fred"},"qux": {"corge": "grault"}},
  35. "patch": [{ "op": "move", "from": "/foo/waldo", "path": "/qux/thud" }],
  36. "expected": {"foo": {"bar": "baz"},"qux": {"corge": "grault","thud": "fred"}}
  37. },
  38. {
  39. "comment": "7",
  40. "doc": { "foo": [ "all", "grass", "cows", "eat" ] },
  41. "patch": [ { "op": "move", "from": "/foo/1", "path": "/foo/3" }],
  42. "expected": { "foo": [ "all", "cows", "eat", "grass" ] }
  43. },
  44. {
  45. "comment": "8",
  46. "doc": {"baz": "qux","foo": [ "a", 2, "c" ]},
  47. "patch": [{ "op": "test", "path": "/baz", "value": "qux" },{ "op": "test", "path": "/foo/1", "value": 2 }]
  48. },
  49. {
  50. "comment": "9",
  51. "doc": { "baz": "qux" },
  52. "patch": [ { "op": "test", "path": "/baz", "value": "bar" }],
  53. "error": "\"bar\" doesn't exist"
  54. },
  55. {
  56. "comment": "10",
  57. "doc": { "foo": "bar" },
  58. "patch": [{ "op": "add", "path": "/child", "value": { "grandchild": { } } }],
  59. "expected": {"foo": "bar","child": {"grandchild": {}}}
  60. },
  61. {
  62. "comment": "11",
  63. "doc": { "foo": "bar" },
  64. "patch": [{ "op": "add", "path": "/baz", "value": "qux", "xyz": 123 }],
  65. "expected": {"foo": "bar","baz": "qux"}
  66. },
  67. {
  68. "comment": "12",
  69. "doc": { "foo": "bar" },
  70. "patch": [{ "op": "add", "path": "/baz/bat", "value": "qux" }],
  71. "error": "Can't add to nonexistent object"
  72. },
  73. {
  74. "comment": "13",
  75. "doc": {"/": 9,"~1": 10},
  76. "patch": [{"op": "test", "path": "/~01", "value": 10}]
  77. },
  78. {
  79. "comment": "14",
  80. "doc": { "foo": ["bar"] },
  81. "patch": [ { "op": "add", "path": "/foo/-", "value": ["abc", "def"] }],
  82. "expected": {"foo": ["bar", ["abc", "def"]] }
  83. },
  84. {
  85. "comment": "15",
  86. "doc": {"foo": {"bar": 1}},
  87. "patch": [{"op": "add", "path": "/foo/bar/baz", "value": "5"}],
  88. "error": "attempting to add to subfield of non-object"
  89. }
  90. ]