test_match v1.2.2 RecursiveMatch

Recursive matching

Link to this section Summary

Link to this section Functions

Link to this macro assert_match(left, right, options \\ [strict: true]) (macro)
assert_match(term(), term(), list() | nil) :: boolean()

Matches given value with pattern

Returns true or raises ExUnit.AssertionError

Parameters

  • pattern: Expected pattern (use :_ instead of _)

  • tested: Tested value

  • options: Options

    • strict: when true compare using ===, when false compare using ==, default true

    • ignore_order, when true - ignore order of items in lists, default false

    • message: Custom message on fail

Example

The assertion

assert_match %{a: 1}, %{a: 1, b: 2}

will match,

assert_match %{a: 1, b: 2}, %{a: 1}

will fail with the message:

match (assert_match) failed
left:  %{a: 1, b: 2},
right: %{a: 1}
Link to this function match_r(pattern, tested, options \\ [strict: true])
match_r(term(), term(), list() | nil) :: boolean()

Matches given value with pattern

Returns true or false

Parameters

  • pattern: Expected pattern (use :_ instead of _)

  • tested: Tested value

  • options: Options

    • strict, when true compare using ===, when false compare using ==, default true

    • ignore_order, when true - ignore order of items in lists, default false

Example

iex> import RecursiveMatch
RecursiveMatch
iex> match_r %{a: 1}, %{a: 1, b: 2}
true
iex> match_r %{a: 1, b: 2}, %{a: 1}
false
Link to this macro refute_match(left, right, options \\ [strict: true]) (macro)
refute_match(term(), term(), list() | nil) :: boolean()

Matches given value with pattern

Returns true or raises ExUnit.AssertionError

Parameters

  • pattern: Expected pattern (use :_ instead of _)

  • tested: Tested value

  • options: Options

    • strict: when true compare using ===, when false compare using ==, default true

    • ignore_order, when true - ignore order of items in lists, default false

    • message: Custom message on fail

Example

The assertion

assert_match %{a: 1}, %{a: 1, b: 2}

will match,

assert_match %{a: 1, b: 2}, %{a: 1}

will fail with the message:

match (refute_match) succeeded, but should have failed