What would you all think of changing the assert output when the argument to 
assert is match?(map, map) so that it shows the difference similar to if we 
did an ==, except the extra fields in the right-hand map would be omitted?  
This is what we currently see when using "assert match?(%{field1: "foo", 
field2: "bar"}, data)":
  1) test map1 (MapPropsalTest)
     test/map_propsal_test.exs:10
     match (match?) failed
     code:  assert match?(%{field1: "foo", field2: "bar", field3: 
"not-there"}, map)
     right: %{
              field1: "foo",
              field2: "bar",
              inserted_at: ~N[2017-10-19 02:10:25.254692]
            }
     stacktrace:
       test/map_propsal_test.exs:12: (test)

How I think it should read instead when the args to match? are both maps :
  2) test map2 (MapPropsalTest)
     test/map_propsal_test.exs:15
     match (match?) failed
     code:  assert match?(%{field1: "foo", field2: "bar", field3: 
"not-there"}, map)
     left:  %{field1: "foo", field2: "bar", <red>field3: "not-there"</red>}
     right: %{field1: "foo", field2: "bar"}
     stacktrace:
       test/map_propsal_test.exs:17: (test)

I'd be happy to do the work.

On Wednesday, October 18, 2017 at 8:53:09 AM UTC-5, José Valim wrote:
>
> Use match?/2:
>
> assert match?(%{field1: "foo", field2: "bar"}, data)
>
>
> The operator =~ was designed to focus exclusively on strings and we don't 
> plan to relax those constraints.
>
>
> *José Valimwww.plataformatec.com.br 
> <http://www.plataformatec.com.br/>Founder and Director of R&D*
>
> On Wed, Oct 18, 2017 at 2:43 PM, <[email protected] <javascript:>> 
> wrote:
>
>> Yes, but that throws a MatchError exception if not satisfied, not a 
>> true/false.  Ideally, in the assertion results, it would highlight the 
>> failing key/values as well.  Primarily for testing, but also a quick way to 
>> test for the presence of multiple key/values in larger maps.
>>
>> On Wednesday, October 18, 2017 at 12:14:00 AM UTC-5, Andrew Timberlake 
>> wrote:
>>>
>>> You can do that with pattern matching,
>>>
>>> assert %{field1: "foo", field2: "bar"} = data
>>>
>>> On 18 Oct 2017, 05:01 +0200, [email protected], wrote:
>>>
>>> I think it would be useful if =~ supported maps.  =~ would return true 
>>> if the key/values in the right hand map were also contained in the 
>>> left-hand map.  I think this would be especially useful for testing, as you 
>>> could check that the result matched a subset of the map, rather than the 
>>> whole map. 
>>>
>>> e.g.
>>> data = Repo.insert!(src)
>>> # data = %Data{id: 25, field1: "foo", field2: "bar", inserted_at: 
>>> ~N[2017-01-01], updated_at: ~N[2017-01-01]}
>>> assert data =~ %{field1: "foo", field2: "bar"}  # true
>>>
>>> --
>>> 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/7eaabb77-6c7a-4fcb-a74a-fc303f5ace26%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/elixir-lang-core/7eaabb77-6c7a-4fcb-a74a-fc303f5ace26%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>> -- 
>> 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] <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/elixir-lang-core/fb23650e-c3f4-4694-86e1-62cdc2b9e103%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/elixir-lang-core/fb23650e-c3f4-4694-86e1-62cdc2b9e103%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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/708c63d3-4dd8-41d3-a5fd-2b304f7ccba4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to