View Source Machete.MapMatcher (Machete v0.2.3)

Defines a matcher that matches maps

Link to this section Summary

Types

Describes the arguments that can be passed to this matcher

t()

Describes an instance of this matcher

Functions

Matches maps. Useful for cases where you wish to match against the general shape / size of a map, but cannot match against a literal map (or use the Machete.Superset / Machete.Subset matchers)

Link to this section Types

@type opts() :: [
  keys: Machete.Matchable.t(),
  values: Machete.Matchable.t(),
  size: non_neg_integer(),
  min: non_neg_integer(),
  max: non_neg_integer()
]

Describes the arguments that can be passed to this matcher

@opaque t()

Describes an instance of this matcher

Link to this section Functions

@spec map(opts()) :: t()

Matches maps. Useful for cases where you wish to match against the general shape / size of a map, but cannot match against a literal map (or use the Machete.Superset / Machete.Subset matchers)

Takes the following arguments:

  • keys: A matcher to use against all keys in the map
  • values: A matcher to use against all values in the map
  • size: Requires the matched map to be exactly the specified size
  • min: Requires the matched map to be greater than or equal to the specified size
  • max: Requires the matched map to be less than or equal to the specified size

Examples:

iex> assert %{a: 1} ~> map()
true

iex> assert %{a: 1} ~> map(keys: atom())
true

iex> assert %{a: 1} ~> map(values: integer())
true

iex> assert %{a: 1} ~> map(size: 1)
true

iex> assert %{a: 1} ~> map(min: 1)
true

iex> assert %{a: 1} ~> map(max: 2)
true