test_match v1.1.0 RecursiveMatch behaviour

Recursive matching

Link to this section Summary

Callbacks

Matches given value with pattern

Matches given value with pattern

Link to this section Types

Link to this type opts()
opts() :: list() | nil

Link to this section Functions

Link to this function match_r(pattern, tested, options \\ [strict: true])
match_r(any(), any(), opts()) :: boolean()

Matches given value with pattern

Returns true or false

Parameters

  • pattern: Expected pattern

  • tested: Tested value

  • opts:

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

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 section Callbacks

Link to this callback assert_match(any, any, opts)
assert_match(any(), any(), opts()) :: boolean()

Matches given value with pattern

Returns true or raises ExUnit.AssertionError

Parameters

  • pattern: Expected pattern

  • tested: Tested value

  • opts:

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

    • 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 callback refute_match(any, any, opts)
refute_match(any(), any(), opts()) :: boolean()

Matches given value with pattern

Returns true or raises ExUnit.AssertionError

Parameters

  • pattern: Expected pattern

  • tested: Tested value

  • opts:

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

    • 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