-
Notifications
You must be signed in to change notification settings - Fork 31
/
UnparserTests.elm
91 lines (85 loc) · 2.29 KB
/
UnparserTests.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
module UnparserTests exposing (..)
import Helpers.Matchers exposing (..)
import String
import FastParser
import LangUnparser
testParseUnparseMatch littleStr =
case FastParser.parseE littleStr of
Err s ->
"can't parse: " ++ toString s ++ "\n" ++ littleStr
Ok parsed ->
let unparsed =
LangUnparser.unparse parsed
in
expectEqual unparsed littleStr
littlePrograms =
[ "5"
, "55"
, " 55"
, " 55{0-5.6}"
, "true"
, " true"
, "false"
, " false"
, "'string'"
, " 'string'"
, "\"doubled-quoted string\""
, "\"dq string \\\\ with \\\"escapes\\\"\""
, "'sq string \\\\ with \\'escapes\\''"
, "variable"
, " variable"
, "(\\_ 'exp')"
, " (\\ x 'exp' )"
, "(\\( a b) 'exp')"
, " (\\[a b] 'exp' )"
, "(func arg1 arg2)"
, " (func arg1 arg2 )"
, " ( (func arg1 ) arg2 arg3 )"
, "(pi)"
, " (pi )"
, "(sqrt 5.5)"
, " (sqrt 5.5 )"
, "(+ 1 2 )"
, " (+ 3 4 )"
, "[]"
, " [ ]"
, "[ a ]"
, "[ a b c ]"
, " [ a b ]"
, "[ a b | [] ]"
, "[ a b | c ]"
, "[ a b | [ c ] ]"
, "[||]"
, " [| |]"
, "[| 1 2 3 |]"
, " [| 1 2 |]"
, "[| 1 2 6..8 |]"
, " [| 1 2 6 .. 8 |]"
, "(if (= a b) 'body1' 'body2')"
, " (if (= a b ) 'body1' 'body2' )"
, "(case (+ 4 5) (1 'body1') ([h|tail] 'body2') (true 'body3') (var 'body4'))"
, " (case (+ 4 5)\n (1 'body1')\n ([ h | tail ]\n 'body2') ( true\n 'body3')\n (var 'body4')\n )"
, "(typecase x (Int (+ x 1)) ([Int String] (length x)) (_ 0))"
, " (typecase [x y] ([Int Int] (+ x y)) (_ 0))"
, "(let pair@[a b] exp 'body')"
, " (letrec pair @ [ a b ] exp\n'body'\n )"
, "(typ x Num) e"
, " (typ [a b c] [Num String Null | Bool]) e"
, "(typ f (-> Num a (List a))) e"
, "(typ f (-> (Dict String (List Num)) Bool)) e"
, "(typ f (union Num String Rgba)) e"
, "((gt 6 7) : Bool)"
, "(def Rgba [Num Num Num Num])"
, "(def [Rgba KVPair] [[Num Num Num Num] [String String]])"
, "(def x 6) x"
, "(def [a b | t] exp) 'body'"
, " (defrec a exp ) 'body'"
, " ; Comment\n\n'exp'"
, "# unannotated-numbers: n?\n'exp'"
, " # unannotated-numbers: n?\n\n 'exp'"
]
unparserTests : () -> List (() -> String)
unparserTests () =
List.map
(\code -> \() -> testParseUnparseMatch code)
littlePrograms