dream_test/matchers/comparison

Comparison matchers for dream_test.

These matchers compare numeric values. They’re re-exported through dream_test/assertions/should.

Integer Matchers

import dream_test/assertions/should.{
  should, be_greater_than, be_less_than, be_at_least,
  be_at_most, be_between, be_in_range, or_fail_with,
}

count
|> should()
|> be_greater_than(0)
|> or_fail_with("Count should be positive")

score
|> should()
|> be_in_range(0, 100)
|> or_fail_with("Score should be 0-100")

Float Matchers

average
|> should()
|> be_greater_than_float(0.0)
|> or_fail_with("Average should be positive")

Values

pub fn be_at_least(
  value_or_result: types.MatchResult(Int),
  minimum: Int,
) -> types.MatchResult(Int)

Assert that an integer is at least a minimum value (>=).

Example

user.age
|> should()
|> be_at_least(18)
|> or_fail_with("User must be at least 18")
pub fn be_at_most(
  value_or_result: types.MatchResult(Int),
  maximum: Int,
) -> types.MatchResult(Int)

Assert that an integer is at most a maximum value (<=).

Example

password.length
|> should()
|> be_at_most(128)
|> or_fail_with("Password must be at most 128 characters")
pub fn be_between(
  value_or_result: types.MatchResult(Int),
  min: Int,
  max: Int,
) -> types.MatchResult(Int)

Assert that an integer is between two values (exclusive).

The value must be strictly greater than min and strictly less than max.

Example

port
|> should()
|> be_between(1024, 65535)
|> or_fail_with("Port must be between 1024 and 65535")
pub fn be_greater_than(
  value_or_result: types.MatchResult(Int),
  threshold: Int,
) -> types.MatchResult(Int)

Assert that an integer is greater than a threshold.

Example

count_items()
|> should()
|> be_greater_than(0)
|> or_fail_with("Should have at least one item")
pub fn be_greater_than_float(
  value_or_result: types.MatchResult(Float),
  threshold: Float,
) -> types.MatchResult(Float)

Assert that a float is greater than a threshold.

Example

average
|> should()
|> be_greater_than_float(0.0)
|> or_fail_with("Average should be positive")
pub fn be_in_range(
  value_or_result: types.MatchResult(Int),
  min: Int,
  max: Int,
) -> types.MatchResult(Int)

Assert that an integer is within a range (inclusive).

The value must be >= min and <= max.

Example

score
|> should()
|> be_in_range(0, 100)
|> or_fail_with("Score must be 0-100")
pub fn be_less_than(
  value_or_result: types.MatchResult(Int),
  threshold: Int,
) -> types.MatchResult(Int)

Assert that an integer is less than a threshold.

Example

response_time_ms
|> should()
|> be_less_than(100)
|> or_fail_with("Response should be under 100ms")
pub fn be_less_than_float(
  value_or_result: types.MatchResult(Float),
  threshold: Float,
) -> types.MatchResult(Float)

Assert that a float is less than a threshold.

Example

error_rate
|> should()
|> be_less_than_float(0.01)
|> or_fail_with("Error rate should be under 1%")
Search Document