1 module List = ListLabels
3 module Test = Tiger_test
5 let read_file filepath =
6 let {Unix.st_size=size; _} = Unix.stat filepath in
7 let buf = Buffer.create size in
8 let ic = open_in filepath in
11 Buffer.add_channel buf ic size;
20 let out_lexing_of_filename =
21 let open Tiger_parser in
26 TYPE; ID "arrtype"; EQ; ARRAY; OF; ID "int";
27 VAR; ID "arr1"; COLON; ID "arrtype"; ASSIGN;
28 ID "arrtype"; LBRACK; INT 10; RBRACK; OF; INT 0;
36 TYPE; ID "myint"; EQ; ID "int";
37 TYPE; ID "arrtype"; EQ; ARRAY; OF; ID "myint";
38 VAR; ID "arr1"; COLON; ID "arrtype"; ASSIGN;
39 ID "arrtype"; LBRACK; INT 10; RBRACK; OF; INT 0;
47 TYPE; ID "rectype"; EQ;
48 LBRACE; ID "name"; COLON; ID "string";
49 COMMA; ID "age"; COLON; ID "int";
51 VAR; ID "rec1"; COLON; ID "rectype"; ASSIGN;
53 LBRACE; ID "name"; EQ; STRING "Nobody";
54 COMMA; ID "age"; EQ; INT 1000;
57 ID "rec1"; DOT; ID "name"; ASSIGN; STRING "Somebody"; SEMICOLON;
64 FUNCTION; ID "nfactor"; LPAREN; ID "n"; COLON; ID "int"; RPAREN; COLON; ID "int"; EQ;
65 IF; ID "n"; EQ; INT 0;
67 ELSE; ID "n"; TIMES; ID "nfactor"; LPAREN; ID "n"; MINUS; INT 1; RPAREN;
69 ID "nfactor"; LPAREN; INT 10; RPAREN;
74 [IF; LPAREN; INT 5; GT; INT 4; RPAREN; THEN; INT 13; ELSE; STRING " "]
76 (* TODO: Fill-in other expected cases *)
79 let out_parsing_of_filename _ =
80 (* TODO: Fill-in expected cases *)
83 let is_error_expected_parsing_of_filename =
84 let module E = Tiger_error in
87 Some (function E.Invalid_syntax _ -> true | _ -> false)
88 (* TODO: Be more specific - test position *)
90 (* TODO: Fill-in other expected cases *)
93 let is_error_expected_semant_of_filename _ =
94 (* TODO: Fill-in expected cases *)
97 let test_case_of_filename filename ~dir =
100 ~code:(read_file (Filename.concat dir filename))
101 ~out_lexing:(out_lexing_of_filename filename)
102 ~out_parsing:(out_parsing_of_filename filename)
103 ~is_error_expected_parsing:(is_error_expected_parsing_of_filename filename)
104 ~is_error_expected_semant:(is_error_expected_semant_of_filename filename)
106 let read ~from_dir:dir =
109 |> List.sort ~cmp:compare
110 |> List.map ~f:(test_case_of_filename ~dir)