Skip to content

Commit 870c086

Browse files
committed
Removed non existing code path and added test
1 parent 5dd9c39 commit 870c086

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

lib/jsonpatch.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ defmodule Jsonpatch do
200200
cond do
201201
is_list(val) -> Stream.with_index(val) |> Enum.map(fn {v, k} -> {k, v} end)
202202
is_map(val) -> Map.to_list(val)
203-
true -> []
204203
end
205204
end
206205

test/jsonpatch_test.exs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ defmodule JsonpatchTest do
118118
patch = Jsonpatch.diff(source, target)
119119
assert [%Replace{path: "/a", value: %{"foo" => :bar}}] = patch
120120
end
121+
122+
test "Create diff when source has a scalar value where in the destination is a list" do
123+
source = %{"a" => 150}
124+
destination = %{"a" => [1, 5, 0]}
125+
126+
patch = Jsonpatch.diff(source, destination)
127+
assert [%Replace{path: "/a", value: [1, 5, 0]}] = patch
128+
end
121129
end
122130

123131
# ===== APPLY =====

0 commit comments

Comments
 (0)