dream_test/matchers/collection

Collection matchers for dream_test.

These matchers work with List(a) values and are re-exported through dream_test/matchers.

Use them to assert collection properties like length, emptiness, and membership.

Example

[1, 2, 3]
|> should
|> have_length(3)
|> or_fail_with("expected list length 3")

Values

pub fn be_empty(
  value_or_result value_or_result: types.MatchResult(List(a)),
) -> types.MatchResult(List(a))

Assert that a list is empty.

Use this when you want to assert there are no values while preserving the list for further checks.

Example

[]
|> should
|> be_empty()
|> or_fail_with("expected empty list")

Parameters

  • value_or_result: the MatchResult(List(a)) produced by should (or a previous matcher)

Returns

A MatchResult(List(a)):

  • On success, preserves the list for further chaining.
  • On failure, the chain becomes failed and later matchers are skipped.
pub fn contain(
  value_or_result value_or_result: types.MatchResult(List(a)),
  expected_item expected_item: a,
) -> types.MatchResult(List(a))

Assert that a list contains a specific item.

Use this when you want to assert membership while preserving the original list for further checks.

Example

[1, 2, 3]
|> should
|> contain(2)
|> or_fail_with("expected list to contain 2")

Parameters

  • value_or_result: the MatchResult(List(a)) produced by should (or a previous matcher)
  • expected_item: the item that must be present in the list

Returns

A MatchResult(List(a)):

  • On success, preserves the list for further chaining.
  • On failure, the chain becomes failed and later matchers are skipped.
pub fn have_length(
  value_or_result value_or_result: types.MatchResult(List(a)),
  expected_length expected_length: Int,
) -> types.MatchResult(List(a))

Assert that a list has a specific length.

Use this when you need to assert exact list length while preserving the list for further checks.

Example

[1, 2, 3]
|> should
|> have_length(3)
|> or_fail_with("expected list length 3")

Parameters

  • value_or_result: the MatchResult(List(a)) produced by should (or a previous matcher)
  • expected_length: the exact length the list must have

Returns

A MatchResult(List(a)):

  • On success, preserves the list for further chaining.
  • On failure, the chain becomes failed and later matchers are skipped.
pub fn not_contain(
  value_or_result value_or_result: types.MatchResult(List(a)),
  unexpected_item unexpected_item: a,
) -> types.MatchResult(List(a))

Assert that a list does not contain a specific item.

Use this when you want to assert absence while preserving the original list for further checks.

Example

["a", "b", "c"]
|> should
|> not_contain("d")
|> or_fail_with("expected list to not contain \"d\"")

Parameters

  • value_or_result: the MatchResult(List(a)) produced by should (or a previous matcher)
  • unexpected_item: the item that must not be present in the list

Returns

A MatchResult(List(a)):

  • On success, preserves the list for further chaining.
  • On failure, the chain becomes failed and later matchers are skipped.
Search Document