Add option iter
[tiger.ml.git] / compiler / src / lib / tiger / tiger_test_cases.ml
CommitLineData
5da420a8 1module Error = Tiger_error
d3bdde4b 2module Test = Tiger_test
f752b2c7 3
d3bdde4b
SK
4let micro =
5 let open Tiger_parser in
38ffcb1f
SK
6 [ (let code = "nil" in Test.case code ~code ~out_lexing:(Some [NIL]))
7 ; (let code = "5" in Test.case code ~code ~out_lexing:(Some [INT 5]))
8 ; (let code = "-5" in Test.case code ~code ~out_lexing:(Some [MINUS; INT 5]))
5da420a8
SK
9 ; ( let code = "f()" in
10 Test.case
11 code
12 ~code
38ffcb1f
SK
13 ~out_lexing:(Some [ID "f"; LPAREN; RPAREN])
14 (* TODO: Be more specific *)
15 ~is_error_expected_semant:(Some Error.is_unknown_id)
155073e2
SK
16 )
17 ; ( let code = "abc.i" in
18 Test.case
19 code
20 ~code
38ffcb1f
SK
21 ~out_lexing:(Some [ID "abc"; DOT; ID "i"])
22 (* TODO: Be more specific *)
23 ~is_error_expected_semant:(Some Error.is_unknown_id)
155073e2
SK
24 )
25 ; ( let code = "abc[0]" in
26 Test.case
27 code
28 ~code
38ffcb1f
SK
29 ~out_lexing:(Some [ID "abc"; LBRACK; INT 0; RBRACK])
30 (* TODO: Be more specific *)
31 ~is_error_expected_semant:(Some Error.is_unknown_id)
155073e2
SK
32 )
33 ; ( let code = "abc[0] := foo()" in
34 Test.case
35 code
36 ~code
37 ~out_lexing:
38ffcb1f
SK
38 (Some [ID "abc"; LBRACK; INT 0; RBRACK; ASSIGN; ID "foo"; LPAREN; RPAREN])
39 (* TODO: Be more specific *)
40 ~is_error_expected_semant:(Some Error.is_unknown_id)
155073e2
SK
41 )
42 ; ( let code = "abc [5] of nil" in
43 Test.case
44 code
45 ~code
38ffcb1f
SK
46 ~out_lexing:(Some [ID "abc"; LBRACK; INT 5; RBRACK; OF; NIL])
47 (* TODO: Be more specific *)
48 ~is_error_expected_semant:(Some Error.is_unknown_type)
5da420a8 49 )
5da420a8
SK
50 ; ( let code = "f(\"a\", 3, foo)" in
51 Test.case
52 code
53 ~code
54 ~out_lexing:
38ffcb1f
SK
55 (Some [ID "f"; LPAREN; STRING "a"; COMMA; INT 3; COMMA; ID "foo"; RPAREN])
56 ~is_error_expected_semant:(Some Error.is_unknown_id)
5da420a8 57 )
cbb4ffb6 58 ; ( Test.case
3be8511c 59 "Type aliases"
cbb4ffb6
SK
60 ~code:
61 "let \
62 type a = int \
63 type b = a \
64 type c = b \
65 var i : a := 2 \
66 var j : c := 3 \
67 in \
68 i := j \
69 end \
70 "
3be8511c
SK
71 )
72 ; ( let code =
4f2aaee3
SK
73 "let \
74 type a = {x:int, y:int} \
75 type b = {x:int, y:int} /* new type generated */ \
76 var foo : a := a {x = 1, y = 2} \
77 var bar : b := b {x = 1, y = 2} \
78 in \
79 foo = bar /* incompatible types */ \
80 end \
3be8511c
SK
81 "
82 in
83 Test.case
6d83a054 84 "Incompatible records"
3be8511c 85 ~code
38ffcb1f
SK
86 (* TODO: Be more specific *)
87 ~is_error_expected_semant:(Some Error.is_wrong_type)
3be8511c 88 )
d5517328
SK
89 ; ( Test.case
90 "Recursive type def: int list"
91 ~code:"\
92 let \n\
93 type intlist = {hd: int, tl: intlist} \n\
94 var lst : intlist := intlist {hd=0, tl = nil} \n\
95 in \n\
96 lst \n\
97 end"
98 )
e6e82c08
SK
99 ; ( Test.case
100 "Cycle in type dec"
101 ~code:"\
102 let \n\
103 type a = b \n\
104 type b = a \n\
105 in \n\
106 end \
107 "
108 ~is_error_expected_semant:(Some Error.is_cycle_in_type_dec)
109 )
110 ; ( Test.case
111 "Cycle in type dec"
112 ~code:"\
113 let \n\
114 type a = b \n\
115 type b = c \n\
116 type c = a \n\
117 var x : a := 1 \n\
118 in \n\
119 end \
120 "
121 ~is_error_expected_semant:(Some Error.is_cycle_in_type_dec)
122 )
35dccbd3
SK
123 ; ( Test.case
124 "Break outside loop"
125 ~code:
126 "break"
127 ~is_error_expected_semant:(Some Error.is_break_outside_loop)
128 )
129 ; ( Test.case
130 "Break within for loop"
131 ~code:"for i := 0 to 5 do (print(\"x\"); break)"
132 )
133 ; ( Test.case
134 "Break after for loop"
135 ~code:"(for i := 0 to 5 do (print(\"x\"); break); break)"
136 ~is_error_expected_semant:(Some Error.is_break_outside_loop)
137 )
138 ; ( Test.case
139 "Break within while loop"
140 ~code:"while 1 do (print(\"x\"); break)"
141 )
142 ; ( Test.case
143 "Break after while loop"
144 ~code:"(while 1 do (print(\"x\"); break); break)"
145 ~is_error_expected_semant:(Some Error.is_break_outside_loop)
146 )
f752b2c7 147 ]
543d3420 148
38ffcb1f
SK
149let book ~dir =
150 Tiger_test_cases_book.read ~from_dir:dir
151
152let all ~dir =
153 (book ~dir) @ micro
This page took 0.055389 seconds and 4 git commands to generate.