dream_test/matchers/option

Option matchers for dream_test.

These matchers work with Option(a) values and support chaining. They’re re-exported through dream_test/assertions/should.

Chaining

The be_some matcher extracts the inner value, allowing you to chain additional matchers:

import dream_test/assertions/should.{should, be_some, equal, or_fail_with}

// Check that it's Some, then check the inner value
find_user(id)
|> should()
|> be_some()
|> equal(expected_user)
|> or_fail_with("Should find the expected user")

Values

pub fn be_none(
  value_or_result: types.MatchResult(option.Option(a)),
) -> types.MatchResult(Nil)

Assert that an Option is None.

Example

find_deleted_user(id)
|> should()
|> be_none()
|> or_fail_with("Deleted user should not exist")
pub fn be_some(
  value_or_result: types.MatchResult(option.Option(a)),
) -> types.MatchResult(a)

Assert that an Option is Some and extract its value.

If the assertion passes, the inner value is passed to subsequent matchers.

Example

find_user(id)
|> should()
|> be_some()
|> or_fail_with("User should exist")

Chaining

Some(42)
|> should()
|> be_some()
|> equal(42)
|> or_fail_with("Should be Some(42)")
Search Document