Hey The `assert` macro handles MatchError as well as true/false.
> Ideally, in the assertion results, it would highlight the failing key/values as well. This would be a nice addition to ExUnit. I would rather see this than any addition to =~ Cheers, Louis On Wed, 18 Oct 2017 at 13:43 <jere...@companykitchen.com> 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, jer...@companykitchen.com, 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 elixir-lang-co...@googlegroups.com. >> >> >> 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 elixir-lang-core+unsubscr...@googlegroups.com. > 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 elixir-lang-core+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CABu8xFC3%3DQRH_t8_J6LFWe07WCGHd7WxzhVpJ6um2fxB89vB9A%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.