Commit | Line | Data |
---|---|---|
78c9eca5 SK |
1 | open Printf |
2 | ||
3 | module List = ListLabels | |
4 | ||
5 | let test_01 = | |
6 | let code = | |
7 | " | |
8 | /* an array type and an array variable */ | |
9 | let | |
10 | type arrtype = array of int | |
11 | var arr1:arrtype := arrtype [10] of 0 | |
12 | in | |
13 | arr1 | |
14 | end | |
15 | " | |
16 | in | |
17 | let tokens = | |
18 | let open Tiger.Parser.Token in | |
19 | [ LET; | |
20 | TYPE; ID "arrtype"; EQ; ARRAY; OF; ID "int"; | |
21 | VAR; ID "arr1"; COLON; ID "arrtype"; ASSIGN; | |
22 | ID "arrtype"; LBRACK; INT 10; RBRACK; OF; INT 0; | |
23 | IN; | |
24 | ID "arr1"; | |
25 | END | |
26 | ] | |
27 | in | |
28 | (code, tokens) | |
29 | ||
30 | let tokens_of_code code = | |
31 | let lexbuf = Lexing.from_string code in | |
32 | let rec tokens () = | |
33 | match Tiger.Lexer.token lexbuf with | |
34 | | Tiger.Parser.Token.EOF -> [] | |
35 | | token -> token :: tokens () | |
36 | in | |
37 | tokens () | |
38 | ||
39 | let tests = | |
40 | [ test_01 | |
41 | ] | |
42 | ||
43 | let () = | |
44 | List.iter tests ~f:(fun (code, tokens_expected) -> | |
45 | assert ((tokens_of_code code) = tokens_expected) | |
46 | ) |