Skip to content

Commit

Permalink
feat(std): add Option assertions to std.test
Browse files Browse the repository at this point in the history
  • Loading branch information
Etherian committed Aug 17, 2020
1 parent e150b9f commit 28e5053
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion std/test.glu
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let float = import! std.float
let int = import! std.int
let list @ { List, ? } = import! std.list
let { Foldable, foldl } = import! std.foldable
let { Option } = import! std.option
let { Option, ? } = import! std.option
let { Result } = import! std.result
let { Semigroup, (<>) } = import! std.semigroup
let { error } = import! std.prim
Expand Down Expand Up @@ -56,6 +56,16 @@ let assert_gte l r : [Show a] -> [Ord a] -> a -> a -> Eff [| writer : Test | r |
if l >= r then wrap ()
else tell (Cons ("Assertion failed: " <> show l <> " < " <> show r) Nil)

let assert_some opt : Option a -> Eff [| writer : Test | r |] () =
match opt with
| Some _ -> wrap ()
| None -> tell (Cons ("Assertion failed: expected Some, found None") Nil)

let assert_none opt : [Show a] -> Option a -> Eff [| writer : Test | r |] () =
match opt with
| Some x -> tell (Cons ("Assertion failed: expected None, found " <> show (Some x)) Nil)
| None -> wrap ()

let assert_ok res : [Show e] -> Result e a -> Eff [| writer : Test | r |] () =
match res with
| Ok _ -> wrap ()
Expand Down Expand Up @@ -108,6 +118,8 @@ rec let run_io test : TestEffIO r a -> IO () =
assert_gt,
assert_gte,

assert_some,
assert_none,
assert_ok,
assert_err,
assert_success,
Expand Down

0 comments on commit 28e5053

Please sign in to comment.