clj-json-patch
clj-json-patch copied to clipboard
Improve vector diffing
This PR aims to primarily fix the following incorrect output reported by diff-vecs:
(let [obj1 {"foo" []}
obj2 {"foo" ["bar" "baz"]}
patches [{"op" "add" "path" "/foo/0" "value" "bar"}
{"op" "add" "path" "/foo/1" "value" "baz"}]]
(fact "Adding two Array Elements"
(diff obj1 obj2) => patches))
=>
FAIL JSON diff - Adding two Array Elements at (core_test.clj:33)
Expected:
[{"op" "add" "path" "/foo/0" "value" "bar"}
{"op" "add" "path" "/foo/1" "value" "baz"}]
Actual:
[{"op" "replace" "path" "/foo/0" "value" "bar"}
{"op" "add" "path" "/foo/1" "value" "baz"}]
Additionally, the diff-vecs implementation is slightly changed to improve performance for the likely common case of diff'ed vectors being the same or sharing common prefixes / suffixes.
If any changes to this PR are desired, please feel free to suggest them or just pick from this PR whatever changes you deem desirable.