Skip to content

Commit 40487bd

Browse files
committed
Added test for diffing lists
1 parent 870c086 commit 40487bd

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

test/jsonpatch_test.exs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,19 @@ defmodule JsonpatchTest do
126126
patch = Jsonpatch.diff(source, destination)
127127
assert [%Replace{path: "/a", value: [1, 5, 0]}] = patch
128128
end
129+
130+
test "Create diff for lists" do
131+
source = [1, "pizza", %{"name" => "Alice"}, [4, 2]]
132+
target = [1, "hamburger", %{"name" => "Alice", "age" => 55}]
133+
134+
patch = Jsonpatch.diff(source, target)
135+
136+
assert [
137+
%Jsonpatch.Operation.Remove{path: "/3"},
138+
%Jsonpatch.Operation.Add{path: "/2/age", value: 55},
139+
%Jsonpatch.Operation.Replace{path: "/1", value: "hamburger"}
140+
] = patch
141+
end
129142
end
130143

131144
# ===== APPLY =====

0 commit comments

Comments
 (0)