Disambiguate variant label
[tiger.ml.git] / compiler / src / lib / tiger / tiger_test_cases.ml
1 module Error = Tiger_error
2 module Test = Tiger_test
3
4 let micro =
5 let open Tiger_parser in
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]))
9 ; ( let code = "f()" in
10 Test.case
11 code
12 ~code
13 ~out_lexing:(Some [ID "f"; LPAREN; RPAREN])
14 (* TODO: Be more specific *)
15 ~is_error_expected_semant:(Some Error.is_unknown_id)
16 )
17 ; ( let code = "abc.i" in
18 Test.case
19 code
20 ~code
21 ~out_lexing:(Some [ID "abc"; DOT; ID "i"])
22 (* TODO: Be more specific *)
23 ~is_error_expected_semant:(Some Error.is_unknown_id)
24 )
25 ; ( let code = "abc[0]" in
26 Test.case
27 code
28 ~code
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)
32 )
33 ; ( let code = "abc[0] := foo()" in
34 Test.case
35 code
36 ~code
37 ~out_lexing:
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)
41 )
42 ; ( let code = "abc [5] of nil" in
43 Test.case
44 code
45 ~code
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)
49 )
50 ; ( let code = "f(\"a\", 3, foo)" in
51 Test.case
52 code
53 ~code
54 ~out_lexing:
55 (Some [ID "f"; LPAREN; STRING "a"; COMMA; INT 3; COMMA; ID "foo"; RPAREN])
56 ~is_error_expected_semant:(Some Error.is_unknown_id)
57 )
58 ; ( let code =
59 "let \
60 type a = int \
61 type b = a \
62 type c = b \
63 var i : a := 2 \
64 var j : c := 3 \
65 in \
66 i := j \
67 end \
68 "
69 in
70 Test.case
71 "Type aliases"
72 ~code
73 )
74 ; ( let code =
75 "let \
76 type a = {x:int, y:int} \
77 type b = {x:int, y:int} /* new type generated */ \
78 var foo : a := a {x = 1, y = 2} \
79 var bar : b := b {x = 1, y = 2} \
80 in \
81 foo = bar /* incompatible types */ \
82 end \
83 "
84 in
85 Test.case
86 "Incompatible records"
87 ~code
88 (* TODO: Be more specific *)
89 ~is_error_expected_semant:(Some Error.is_wrong_type)
90 )
91 ]
92
93 let book ~dir =
94 Tiger_test_cases_book.read ~from_dir:dir
95
96 let all ~dir =
97 (book ~dir) @ micro
This page took 0.092243 seconds and 4 git commands to generate.