Machete.MapMatcher (Machete v0.3.11)
View SourceDefines a matcher that matches maps
Summary
Types
Describes the arguments that can be passed to this matcher
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)
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
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)
Takes the following arguments:
keys
: A matcher to use against all keys in the mapvalues
: A matcher to use against all values in the mapsize
: Requires the matched map to be exactly the specified sizemin
: Requires the matched map to be greater than or equal to the specified sizemax
: 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