-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathExampleTests.elm
48 lines (40 loc) · 1.44 KB
/
ExampleTests.elm
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
module ExampleTests exposing (..)
import String
import ExamplesGenerated as Examples
import Syntax
import FastParser exposing (parseE)
import Eval
import EvalUpdate
import LangUnparser
testEvalsWithoutErrors name code =
case parseE code of
Err s ->
"can't parse " ++ name ++ ": " ++ toString s ++ "\n" ++ code
Ok exp ->
-- Elm will crash first if Eval fails.
case EvalUpdate.run Syntax.Little exp of
Ok (val, widgets) -> "ok"
Err s -> "evaluation error running " ++ name ++ ":\n" ++ s
testReparsedUnparsedEvalsWithoutErrors name code =
case parseE code of
Err s ->
"can't parse " ++ name ++ ": " ++ toString s ++ "\n" ++ code
Ok parsed ->
let unparsed = LangUnparser.unparse parsed in
case parseE unparsed of
Err s ->
"can't re-parse unparsed " ++ name ++ ": " ++ toString s ++ "\n" ++ unparsed
Ok reparsedExp ->
-- Elm will crash first if Eval fails.
case EvalUpdate.run Syntax.Little reparsedExp of
Ok (val, widgets) -> "ok"
Err s -> "evaluation error running unparsed/reparsed " ++ name ++ ":\n" ++ s
testExample name code =
[ (\() -> testEvalsWithoutErrors name code)
, (\() -> testReparsedUnparsedEvalsWithoutErrors name code)
]
exampleTests : () -> List (() -> List (() -> String))
exampleTests () =
List.map
(\(name, (code, thunk)) -> \() -> testExample name code)
Examples.list