/
Test.hs
50 lines (36 loc) · 883 Bytes
/
Test.hs
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 Text.Parsec (parse)
import FunFun.Parser
import FunFun.Pretty
import FunFun.Interpreter
test1 =
test "x+x"
test2 =
test "if x + y then z + w elif q+w then e+r else t+y"
test3 =
test "x (y+z) (w q w) (r ty)"
test4 =
test "let x = x, y = x, z x y= x + y in x + y + z"
test5 =
test "do x ; y ; z done"
test6 =
test "(x + (y + z)) + w"
test7 =
test "lambda x y : x + y"
test8 =
test "x + 13 + 15.05"
test9 =
testInterp "(lambda x: if x then 1 else 0) 13"
test10 =
testInterp "lambda x y: 13"
test11 =
testInterp "let x = 1, y = 2 in y"
testInterp src =
case parse parser "" src of
Left err -> print err
Right ast -> do
putStrLn . prettyprint $ ast
print (eval [] ast)
test src =
case parse parser "" src of
Left err -> print err
Right ast -> putStr . prettyprint $ ast