Skip to content

Commit

Permalink
feat: Add Option assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernat Jufré authored and lpil committed Apr 1, 2024
1 parent 8b66cd0 commit 78d3d82
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v1.1.0

- Added `Option` assertions: `should.be_some` and `should.be_none`

## v1.0.2 - 2023-12-19

- Added Gleam v0.33.0 version requirement.
Expand Down
15 changes: 15 additions & 0 deletions src/gleeunit/should.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//// documentation](https://rebar3.org/docs/testing/eunit/).

import gleam/string
import gleam/option.{type Option, None, Some}

@external(erlang, "gleeunit_ffi", "should_equal")
pub fn equal(a: t, b: t) -> Nil {
Expand Down Expand Up @@ -50,6 +51,20 @@ pub fn be_error(a: Result(a, e)) -> e {
}
}

pub fn be_some(a: Option(a)) -> a {
case a {
Some(value) -> value
_ -> panic as string.concat(["\n", string.inspect(a), "\nshould be some"])
}
}

pub fn be_none(a: Option(a)) -> Nil {
case a {
None -> Nil
_ -> panic as string.concat(["\n", string.inspect(a), "\nshould be none"])
}
}

pub fn be_true(actual: Bool) -> Nil {
actual
|> equal(True)
Expand Down

0 comments on commit 78d3d82

Please sign in to comment.