ExUnitAssertMatch v0.3.0 ExUnitAssertMatch View Source

Provedes functionality to assert that given data structure is as expected.

The usage is on README.

Link to this section Summary

Functions

Matches everything

Assert that given data match type specification

Matches any atom

Matches any binary. You can pass regex

Matches any float

Matches any integer

Matches any list

Matches a list that satisfies example specification

Matches if they are equal. This uses == to compare them

Matches any map

Matches a map that satisfies example specification

Matches if it satisfies example or equals to nil

Helper function to call nullable(atom())

Helper function to call nullable(binary())

Helper function to call nullable(float())

Helper function to call nullable(integer())

Helper function to call nullable(list())

Helper function to call nullable(list_of(example))

Helper function to call nullable(literal(example))

Helper function to call nullable(map())

Helper function to call nullable(map(example))

Link to this section Functions

Matches everything.

Link to this function assert(type, data, opts \\ []) View Source

Assert that given data match type specification.

alias ExUnitAssertMatch, as: Match

Match.assert Match.binary(), "Hello"
#=> pass

Match.assert Match.binary(), 123
#=> fail

This calls ExUnit assert macro internally.

Link to this function assert(type, data, opts, state) View Source

Matches any atom.

Matches any binary. You can pass regex.

  alias ExUnitAssertMatch, as: Match

  Match.assert Match.binary(), "foo"
  #=> pass

  Match.assert Match.binary(regex: ~r/bar/), "foo"
  #=> fail

Matches any float.

Matches any integer.

Matches any list.

Matches a list that satisfies example specification.

alias ExUnitAssertMatch, as: Match

Match.assert Match.list_of(Match.binary()), ["1", "2"]
#=> pass

Match.assert Match.list_of(Match.binary()), ["1", 2]
#=> fail

Matches if they are equal. This uses == to compare them.

Link to this function map(example, opts \\ []) View Source

Matches a map that satisfies example specification.

alias ExUnitAssertMatch, as: Match

Match.assert Match.map(%{name: Match.binary()}), %{name: "John"}
#=> pass

Match.assert Match.map(%{name: Match.binary()}), %{name: nil}
#=> fail

You can assert that the map and example have exact same keys.

Match.assert Match.map(%{name: Match.binary()}, exact_same_keys: true), %{name: "Bob", age: 28}
#=> fail

Matches if it satisfies example or equals to nil.

Helper function to call nullable(atom()).

Helper function to call nullable(binary()).

Helper function to call nullable(float()).

Helper function to call nullable(integer()).

Helper function to call nullable(list()).

Link to this function nullable_list_of(example) View Source

Helper function to call nullable(list_of(example)).

Link to this function nullable_literal(example) View Source

Helper function to call nullable(literal(example)).

Helper function to call nullable(map()).

Helper function to call nullable(map(example)).