Skip to content

Commit

Permalink
Explicitly sort in places where mismatch lists are generated from maps
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrudel committed Oct 24, 2024
1 parent 672a101 commit 384f236
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/machete/matchers/indifferent_access_matcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ defmodule Machete.IndifferentAccessMatcher do
def mismatches(%@for{} = a, b) do
mapped_b =
b
|> Enum.sort()
|> Enum.map(fn {k, v} ->
cond do
is_atom(k) and Map.has_key?(a.map, to_string(k)) -> {to_string(k), v}
Expand Down
4 changes: 3 additions & 1 deletion lib/machete/matchers/literal_map_matcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ defmodule Machete.LiteralMapMatcher do
end

defp mismatched_values(a, b) do
Enum.flat_map(b, fn
b
|> Enum.sort()
|> Enum.flat_map(fn
{k, v} when is_map_key(a, k) -> Enum.map(v ~>> a[k], &%{&1 | path: [k | &1.path]})
_ -> []
end)
Expand Down

0 comments on commit 384f236

Please sign in to comment.