dream_test/matchers/string

String matchers for dream_test.

These matchers work with strings. They’re re-exported through dream_test/assertions/should.

Usage

import dream_test/assertions/should.{
  should, start_with, end_with, contain_string, or_fail_with,
}

greeting
|> should()
|> start_with("Hello")
|> or_fail_with("Greeting should start with Hello")

filename
|> should()
|> end_with(".gleam")
|> or_fail_with("Should be a Gleam file")

log_message
|> should()
|> contain_string("error")
|> or_fail_with("Log should mention error")

Values

pub fn contain_string(
  value_or_result: types.MatchResult(String),
  substring: String,
) -> types.MatchResult(String)

Assert that a string contains a substring.

Example

log_message
|> should()
|> contain_string("error")
|> or_fail_with("Log should mention error")
pub fn end_with(
  value_or_result: types.MatchResult(String),
  suffix: String,
) -> types.MatchResult(String)

Assert that a string ends with a suffix.

Example

filename
|> should()
|> end_with(".gleam")
|> or_fail_with("File should be a Gleam file")
pub fn start_with(
  value_or_result: types.MatchResult(String),
  prefix: String,
) -> types.MatchResult(String)

Assert that a string starts with a prefix.

Example

greeting
|> should()
|> start_with("Hello")
|> or_fail_with("Greeting should start with Hello")
Search Document