ExMatch (exmatch v0.16.0)

Assertions for data equivalence.

usage

Usage

The library depends on ExUnit.AssertionError and therefore is meant to be used only in testing.

Notice

The examples below display ExMatchTest.AssertionError as they are used as doctests. When used in your tests the ExUnit.AssertionError would be used instead. Using plain IEx environment will use basic struct formatter different from ExUnit.CLIFormatter.

iex> ExMatch.match(%{a: 1, b: 2, c: 3}, %{c: 3, a: 2, b: {1, 0}})
** (ExMatchTest.AssertionError)
left:  %{a: 1, b: 2}
right: %{a: 2, b: {1, 0}}
iex> opts = ExMatch.options([{Decimal, [:match_integer]}])
iex> ExMatch.match([10, eleven, _], [Decimal.new("10"), 11, 12], opts)
iex> eleven == 11
true
iex> eleven = 11
iex> ExMatch.match(%Decimal{coef: ^eleven, exp: 1 - 1, sign: 1}, Decimal.add(1, eleven))
** (ExMatchTest.AssertionError)
left:  %Decimal{coef: ^eleven = 11}
right: %Decimal{coef: 12}
iex> ExMatch.match(%ExMatchTest.Dummy{
...>    a: %ExMatchTest.Dummy1{a: 1},
...>    b: ~U[2022-02-19 05:10:08.387165Z]
...>  }, %ExMatchTest.Dummy{
...>    a: %ExMatchTest.Dummy{a: 1},
...>    b: Timex.parse!("2022-02-19 14:55:08.387165+09:45", "{ISO:Extended}")
...>  })
** (ExMatchTest.AssertionError)
left:  %ExMatchTest.Dummy{a: %ExMatchTest.Dummy1{}}
right: %ExMatchTest.Dummy{a: %ExMatchTest.Dummy{}}
iex> url = URI.parse("https://elixir-lang.org/")
iex> ExMatch.match(%URI{url | path: path}, URI.parse("https://elixir-lang.org/cases.html"))
iex> path == "/cases.html"
true
iex> url = URI.parse("https://elixir-lang.org/")
iex> ExMatch.match(%URI{url | scheme: "http"}, URI.parse("http://localhost:3000"))
** (ExMatchTest.AssertionError)
left:  url = %URI{authority: "elixir-lang.org", host: "elixir-lang.org", path: "/", port: 443}
right: %URI{authority: "localhost:3000", host: "localhost", path: nil, port: 3000}

Link to this section Summary

Link to this section Functions

Link to this function

default_options()

Link to this function

gen_match(left, right, opts_expr, env)

Link to this macro

match(expr)

(macro)
Link to this macro

match(arg1, arg2)

(macro)

Raises if the values don't match and displays what exactly was different.

iex> ExMatch.match([1, a, 3], [1, 2, 3]) iex> 2 = a

iex> ExMatch.match([1, 2, a] == [1, 2, 3], ExMatch.options([])) iex> 3 = a

Link to this macro

match(left, right, opts)

(macro)
Link to this macro

options(item)

(macro)