Skip to content

Commit be40059

Browse files
bors[bot]Etherian
andauthored
Merge #871
871: feat(std): add Option assertions to std.test r=Marwes a=Etherian Adds `assert_some` and `assert_none`. I guess I forgot them when adding `assert_ok` and `assert_err`. Co-authored-by: Etherian <[email protected]>
2 parents e150b9f + 28e5053 commit be40059

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

std/test.glu

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let float = import! std.float
77
let int = import! std.int
88
let list @ { List, ? } = import! std.list
99
let { Foldable, foldl } = import! std.foldable
10-
let { Option } = import! std.option
10+
let { Option, ? } = import! std.option
1111
let { Result } = import! std.result
1212
let { Semigroup, (<>) } = import! std.semigroup
1313
let { error } = import! std.prim
@@ -56,6 +56,16 @@ let assert_gte l r : [Show a] -> [Ord a] -> a -> a -> Eff [| writer : Test | r |
5656
if l >= r then wrap ()
5757
else tell (Cons ("Assertion failed: " <> show l <> " < " <> show r) Nil)
5858

59+
let assert_some opt : Option a -> Eff [| writer : Test | r |] () =
60+
match opt with
61+
| Some _ -> wrap ()
62+
| None -> tell (Cons ("Assertion failed: expected Some, found None") Nil)
63+
64+
let assert_none opt : [Show a] -> Option a -> Eff [| writer : Test | r |] () =
65+
match opt with
66+
| Some x -> tell (Cons ("Assertion failed: expected None, found " <> show (Some x)) Nil)
67+
| None -> wrap ()
68+
5969
let assert_ok res : [Show e] -> Result e a -> Eff [| writer : Test | r |] () =
6070
match res with
6171
| Ok _ -> wrap ()
@@ -108,6 +118,8 @@ rec let run_io test : TestEffIO r a -> IO () =
108118
assert_gt,
109119
assert_gte,
110120

121+
assert_some,
122+
assert_none,
111123
assert_ok,
112124
assert_err,
113125
assert_success,

0 commit comments

Comments
 (0)