---
cases:
  - note: jsonpatch/set-success basic-remove
    query: data.main.result.foo = x
    modules:
      - |
        package main

        doc := {"foo": {"a", "b", "c"}}

        patch := [{"op": "remove", "path": "foo/b"}]

        result := r if r = json.patch(doc, patch)
    want_result:
      - x:
          - a
          - c
    sort_bindings: true
  - note: jsonpatch/set-success basic-add
    query: data.main.result.foo = x
    modules:
      - |
        package main

        doc := {"foo": {"a", "b", "c"}}

        patch := [{"op": "add", "path": "foo/d", "value": "d"}]

        result := r if r = json.patch(doc, patch)
    want_result:
      - x:
          - a
          - b
          - c
          - d
    sort_bindings: true
  - note: jsonpatch/set-failure add-with-mismatched-key-value
    query: data.main.result.foo = x
    modules:
      - |
        package main

        doc := {"foo": {"a", "b", "c"}}

        patch := [{"op": "add", "path": "foo/d", "value": "e"}]

        result := r if r = json.patch(doc, patch)
    want_result: []
  - note: jsonpatch/set-success basic-move
    query: data.main.result.foo = x; data.main.result.bar = z
    modules:
      - |
        package main

        doc := {"foo": {"a", "b"}, "bar": {"c", "d"}}

        patch := [{"op": "move", "from": "foo/a", "path": "bar/a"}]

        result := r if r = json.patch(doc, patch)
    want_result:
      - x:
          - b
        z:
          - a
          - c
          - d
    sort_bindings: true
  - note: jsonpatch/set-success add-to-nested-array
    query: data.main.result = x
    modules:
      - |
        package main

        doc := {[1]}

        patch := [{"op": "add", "path": [[1], 1], "value": 2}]

        result := r if r = json.patch(doc, patch)
    want_result:
      - x:
          - - 1
            - 2
