-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_case.gleam
49 lines (42 loc) 路 1.09 KB
/
test_case.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
import gleam/dynamic.{type DecodeError, type Dynamic} as dyn
import startest/test_failure.{type TestFailure}
pub type TestBody =
fn() -> Nil
/// A test case.
pub type Test {
Test(name: String, body: TestBody, skipped: Bool)
}
/// The outcome of a `Test` that has been run.
pub type TestOutcome {
Passed
Failed(TestFailure)
Skipped
}
/// A `Test` that has been executed and has a `TestOutcome`.
pub type ExecutedTest {
ExecutedTest(test_case: Test, outcome: TestOutcome)
}
@target(erlang)
pub fn decode_test(value: Dynamic) -> Result(Test, List(DecodeError)) {
value
|> dyn.decode3(
Test,
dyn.element(1, dyn.string),
dyn.element(2, decode_test_body),
dyn.element(3, dyn.bool),
)
}
@target(javascript)
pub fn decode_test(value: Dynamic) -> Result(Test, List(DecodeError)) {
value
|> dyn.decode3(
Test,
dyn.field("name", dyn.string),
dyn.field("body", decode_test_body),
dyn.field("skipped", dyn.bool),
)
}
fn decode_test_body(value: Dynamic) -> Result(TestBody, List(DecodeError)) {
let function: TestBody = dyn.unsafe_coerce(value)
Ok(function)
}