Skip to content

Commit 094b64c

Browse files
marcelottoJosé Valim
authored andcommitted
Fix MatchError in ExUnit when comparing maps with nil or boolean keys (#5957)
Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
1 parent 1ca103d commit 094b64c

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/ex_unit/lib/ex_unit/diff.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,10 @@ defmodule ExUnit.Diff do
436436
inspect(key) <> " => "
437437
end
438438

439+
defp format_key(key, true) when is_nil(key) or is_boolean(key) do
440+
inspect(key) <> ": "
441+
end
442+
439443
defp format_key(key, true) do
440444
":" <> result = inspect(key)
441445
result <> ": "

lib/ex_unit/test/ex_unit/diff_test.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ defmodule ExUnit.DiffTest do
289289

290290
assert script(%{"foo-bar": 1}, %{}) == [{:eq, "%{"}, [[del: "\"foo-bar\": 1"]], {:eq, "}"}]
291291
assert script(%{}, %{}) == [eq: "%{}"]
292+
293+
assert script(%{nil: 42}, %{}) == [{:eq, "%{"}, [[del: "nil: 42"]], {:eq, "}"}]
294+
assert script(%{true: 42}, %{}) == [{:eq, "%{"}, [[del: "true: 42"]], {:eq, "}"}]
295+
assert script(%{false: 42}, %{}) == [{:eq, "%{"}, [[del: "false: 42"]], {:eq, "}"}]
292296
end
293297

294298
test "structs" do

0 commit comments

Comments
 (0)