zachallaun / mneme

Snapshot testing for Elixir
https://hex.pm/packages/mneme
95 stars 5 forks source link

when a map has a struct or map as key, don't simplify it. #96

Closed tcoopman closed 3 weeks ago

tcoopman commented 3 weeks ago

If a map has a key that is a struct or a map you can't remove the contents, because it's not the same key anymore. If you write something like this:

auto_assert %{%MyStruct{a: 1} => true}

mneme will propose %{%MyStruct{} => true} which is not the same.

And then you get output like:

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  -  auto_assert %{%DomainModelling.BlockId{} => true} <- %{
  -                %DomainModelling.BlockId{page: 0, block: 0} => true
  -              }
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  +  auto_assert %{%DomainModelling.BlockId{} => true} <-
  +                %{
  +                  %DomainModelling.BlockId{page: 0, block: 0} => true
  +                }
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
zachallaun commented 3 weeks ago

Thanks for the report! The pattern generator already tracks whether it's in a map-key context, so this should be an easy fix.