View Source Machete.ListMatcher (Machete v0.2.3)

Defines a matcher that matches lists

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 lists. Useful for cases where you wish to match against the general shape / size of a list, but cannot match against a literal list

Link to this section Types

@type opts() :: [
  elements: Machete.Matchable.t(),
  length: 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 list(opts()) :: t()

Matches lists. Useful for cases where you wish to match against the general shape / size of a list, but cannot match against a literal list

Takes the following arguments:

  • elements: A matcher to use against all elements in the list
  • length: Requires the matched list to be exactly the specified length
  • min: Requires the matched list to be greater than or equal to the specified length
  • max: Requires the matched list to be less than or equal to the specified length

Examples:

iex> assert [1] ~> list(elements: integer())
true

iex> assert [1] ~> list(length: 1)
true

iex> assert [1] ~> list(min: 1)
true

iex> assert [1] ~> list(max: 2)
true