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] <javascript:>,
> 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] <javascript:>.
> 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].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/fb23650e-c3f4-4694-86e1-62cdc2b9e103%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.