-
Notifications
You must be signed in to change notification settings - Fork 1
/
should.gleam
50 lines (43 loc) · 1.15 KB
/
should.gleam
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import testbldr/pieces
import gleam/string
pub fn equal(a, b) -> pieces.TestOutcome {
case a == b {
True -> pieces.Pass
False -> pieces.Fail(bin_op_msg(a, "==", b))
}
}
pub fn not_equal(a, b) -> pieces.TestOutcome {
case a != b {
True -> pieces.Pass
False -> pieces.Fail(bin_op_msg(a, "!=", b))
}
}
pub fn be_true(a: Bool) -> pieces.TestOutcome {
case a {
True -> pieces.Pass
False -> pieces.Fail("\nExpected True, got False\n")
}
}
pub fn be_false(a: Bool) -> pieces.TestOutcome {
case a {
False -> pieces.Pass
True -> pieces.Fail("\nExpected False, got True\n")
}
}
pub fn be_ok(a: Result(a, b)) -> pieces.TestOutcome {
case a {
Ok(_) -> pieces.Pass
Error(_) ->
pieces.Fail("\nExpected Ok, Got Error: " <> string.inspect(a) <> "\n")
}
}
pub fn be_error(a: Result(a, b)) -> pieces.TestOutcome {
case a {
Ok(_) ->
pieces.Fail("\nExpected Error, Got Ok: " <> string.inspect(a) <> "\n")
Error(_) -> pieces.Pass
}
}
fn bin_op_msg(lhs: a, op: String, rhs: b) -> String {
"\nlhs: " <> string.inspect(lhs) <> "\nrhs: " <> string.inspect(rhs) <> "\nassertion lhs " <> op <> " rhs failed\n"
}