This:

x = :foo; assert %{} = x
produces:

match (=) failed code: assert %{} = :foo left: %{} right: :foo ^^^^
stacktrace: foo_test.exs:11: (test)
(emphasis mine)

This:

x = :foo; assert is_map(x)
gives:

Expected truthy, got false code: assert is_map(x) arguments: # 1 :foo
^^^^
I personally find the former error message a bit nicer, but maybe it is
I'm just used to seeing left/right of diffs and that's what I expect the
vast majority of time, anything else gives a small pause.

In any case, my recommendation is to always do `assert actual ==
expected` and `assert expected = actual`, never `assert expected ==
actual`. And yeah, I think you're making a good point about matching on
map is definitely a possible foot gun, but I personally don't think it
should be enforced by the tooling.

On October 22, 2021, "niemier.pl" <[email protected]> wrote:
> Follow up of https://github.com/elixir-lang/elixir/issues/11331
>
> The goal is to warn on `assert %{} = value` that user meant `assert
> %{} == value` and inform user that if they want to check whether the
> returned value is really map, then they should use `assert
> is_map(value)` instead.
>
> PR with sample implementation - https://github.com/elixir-
> lang/elixir/pull/11333
>  --
>  You received this message because you are subscribed to the Google
> Groups "elixir-lang-core" group.
>  To unsubscribe from this group and stop receiving emails from it,
> send an email to [email protected]
> <mailto:[email protected]>.
>  To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-core/44b23c21-5f6c-4cc1-
> 82e5-543b02a343f8n%40googlegroups.com
> <https://groups.google.com/d/msgid/elixir-lang-core/44b23c21-5f6c-
> 4cc1-82e5-
> 543b02a343f8n%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/9b372467ac0f8aa755fbef331aa63b2e2bbf1492%40hey.com.

Reply via email to