Commit | Line | Data |
---|---|---|
5da420a8 | 1 | module Error = Tiger_error |
d3bdde4b | 2 | module Test = Tiger_test |
f752b2c7 | 3 | |
d3bdde4b SK |
4 | let 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 | ) |
3be8511c | 58 | ; ( let code = |
4f2aaee3 SK |
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 \ | |
3be8511c SK |
68 | " |
69 | in | |
70 | Test.case | |
71 | "Type aliases" | |
72 | ~code | |
73 | ) | |
74 | ; ( let code = | |
4f2aaee3 SK |
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 \ | |
3be8511c SK |
83 | " |
84 | in | |
85 | Test.case | |
6d83a054 | 86 | "Incompatible records" |
3be8511c | 87 | ~code |
38ffcb1f SK |
88 | (* TODO: Be more specific *) |
89 | ~is_error_expected_semant:(Some Error.is_wrong_type) | |
3be8511c | 90 | ) |
f752b2c7 | 91 | ] |
543d3420 | 92 | |
38ffcb1f SK |
93 | let book ~dir = |
94 | Tiger_test_cases_book.read ~from_dir:dir | |
95 | ||
96 | let all ~dir = | |
97 | (book ~dir) @ micro |