0 | module Test.Async.Spec.TestResult
2 | import Derive.Prelude
4 | import Text.Show.Diff
6 | %language ElabReflection
14 | diffRemoved : String
18 | diffValue : ValueDiff
20 | %runElab derive "TestResult.Diff" [Show,Eq]
23 | data TestResult : Type where
24 | Failure : Maybe Diff -> String -> TestResult
25 | Success : TestResult
27 | %runElab derive "TestResult" [Show,Eq]
30 | 0 Test : Type -> Type
31 | Test e = Async e [] TestResult
34 | dummy = pure Success
37 | data TestTree : Type -> Type where
38 | Node : (name : String) -> List (TestTree e) -> TestTree e
39 | Leaf : (desc : String) -> Test e -> TestTree e
42 | data Pre : Type where
45 | Desc : String -> Pre
48 | FromString Pre where fromString = Desc
65 | at : String -> Test e -> Post e
70 | (!:) : String -> Test e -> Post e
74 | data Verb = Should | Can | Must
77 | Interpolation Verb where
78 | interpolate Should = "should"
79 | interpolate Can = "can"
80 | interpolate Must = "must"
83 | leaf : Verb -> Post e -> TestTree e
84 | leaf v (At d t) = Leaf "\{v} \{d}" t
87 | record FlatSpecInstr e where
93 | export infixr 5 `should`
,`at`
,`must`
,`can`
,!:
95 | public export %inline
96 | should : (pre : Pre) -> (post : Post e) -> FlatSpecInstr e
99 | public export %inline
100 | must : (pre : Pre) -> (post : Post e) -> FlatSpecInstr e
103 | public export %inline
104 | can : (pre : Pre) -> (post : Post e) -> FlatSpecInstr e
108 | data ValidInstrs : (is : List (FlatSpecInstr e)) -> Type where
114 | -> {0 t : List (FlatSpecInstr e)}
115 | -> ValidInstrs (FSI v (Desc s) p :: t)
120 | -> (is : List (FlatSpecInstr e))
121 | -> {auto 0 prf : ValidInstrs is}
123 | flatSpec ttl (FSI v (Desc s) p :: t) @{IsValidInstrs} =
124 | Node ttl (go [<] s [< leaf v p] t)
128 | SnocList (TestTree e)
130 | -> SnocList (TestTree e)
131 | -> List (FlatSpecInstr e)
132 | -> List (TestTree e)
133 | go sx s sy [] = sx <>> [Node s $
sy <>> []]
134 | go sx s sy (FSI v It p :: xs) = go sx s (sy :< leaf v p) xs
135 | go sx s sy (FSI v They p :: xs) = go sx s (sy :< leaf v p) xs
136 | go sx s sy (FSI v (Desc n) p :: xs) =
137 | go (sx :< Node s (sy <>> [])) n [< leaf v p] xs
143 | spec1 : List (FlatSpecInstr e)
145 | [ "an empty list" `should` "have length 0" `at` dummy
146 | , it `should` "return Nothing on pop" `at` dummy
147 | , it `should` "return a value on pop after pushing to it" !: dummy
148 | , "a non-empty list" `should` "have length > 0" `at` dummy
149 | , it `should` "return a Just on pop" `at` dummy