Skip to content

Commit 9c77960

Browse files
committed
Consider macros and module attributes on the left side of ++ on ExUnit.Diff
Closes #10520
1 parent a20f413 commit 9c77960

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

lib/ex_unit/lib/ex_unit/diff.ex

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,14 @@ defmodule ExUnit.Diff do
7070
diff_quoted(number, right, env)
7171
end
7272

73-
defp diff_quoted({:++, _, _} = left, right, env) when is_list(right) do
74-
diff_maybe_improper_list(left, right, env)
73+
defp diff_quoted({:++, meta, [prefix, suffix]}, right, env) when is_list(right) do
74+
case prefix do
75+
{_, [expanded: expanded] ++ _, _} ->
76+
diff_maybe_improper_list({:++, meta, [expanded, suffix]}, right, env)
77+
78+
_ ->
79+
diff_maybe_improper_list({:++, meta, [prefix, suffix]}, right, env)
80+
end
7581
end
7682

7783
defp diff_quoted({:{}, _, left}, right, env) when is_tuple(right) do

lib/ex_unit/test/ex_unit/diff_test.exs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,18 +345,23 @@ defmodule ExUnit.DiffTest do
345345

346346
refute_diff([:a, :b] ++ [:c] = [:a, :b], "[:a, :b] ++ [-:c-]", "[:a, :b]")
347347
refute_diff([:a, :c] ++ [:b] = [:a, :b], "[:a, -:c-] ++ [:b]", "[:a, :b]")
348-
349348
refute_diff([:a] ++ [:b] ++ [:c] = [:a, :b], "[:a] ++ [:b] ++ [-:c-]", "[:a, :b]")
350349

351350
assert_diff([:a] ++ :b = [:a | :b], [])
352351
assert_diff([:a] ++ x = [:a, :b], x: [:b])
353352

354353
refute_diff([:a, :b] ++ :c = [:a, :b, :c], "[:a, :b] ++ -:c-", "[:a, :b, +:c+]")
355354
refute_diff([:a] ++ [:b] ++ :c = [:a, :b, :c], "[:a] ++ [:b] ++ -:c-", "[:a, :b, +:c+]")
356-
357355
refute_diff([:a] ++ [:b] = :a, "-[:a] ++ [:b]-", "+:a+")
358356
end
359357

358+
@a [:a]
359+
test "concat lists with module attributes" do
360+
assert_diff(@a ++ [:b] = [:a, :b], [])
361+
refute_diff(@a ++ [:b] = [:a], "[:a] ++ [-:b-]", "[:a]")
362+
refute_diff(@a ++ [:b] = [:b], "[-:a-] ++ [:b]", "[:b]")
363+
end
364+
360365
test "mixed lists" do
361366
refute_diff([:a | :b] = [:a, :b], "[:a | -:b-]", "[:a, +:b+]")
362367
refute_diff([:a, :b] = [:a | :b], "[:a, -:b-]", "[:a | +:b+]")

0 commit comments

Comments
 (0)