-let book =
- [ Test.case
- "Book test 1: an array type and an array variable"
- ~code:
- " \
- /* an array type and an array variable */ \
- let \
- type arrtype = array of int \
- var arr1:arrtype := \
- arrtype [10] of 0 \
- in \
- arr1 \
- end \
- "
- ~out_lexing:(
- let open Tiger_parser in
- [ LET;
- TYPE; ID "arrtype"; EQ; ARRAY; OF; ID "int";
- VAR; ID "arr1"; COLON; ID "arrtype"; ASSIGN;
- ID "arrtype"; LBRACK; INT 10; RBRACK; OF; INT 0;
- IN;
- ID "arr1";
- END
- ]
- )
- ; Test.case
- "Book test 2: arr1 is valid since expression 0 is int = myint"
- ~code:
- " \
- /* arr1 is valid since expression 0 is int = myint */ \
- let \
- type myint = int \
- type arrtype = array of myint \
- var arr1:arrtype := \
- arrtype [10] of 0 \
- in \
- arr1 \
- end \
- "
- ~out_lexing:(
- let open Tiger_parser in
- [ LET;
- TYPE; ID "myint"; EQ; ID "int";
- TYPE; ID "arrtype"; EQ; ARRAY; OF; ID "myint";
- VAR; ID "arr1"; COLON; ID "arrtype"; ASSIGN;
- ID "arrtype"; LBRACK; INT 10; RBRACK; OF; INT 0;
- IN;
- ID "arr1";
- END
- ]
- )
- ; Test.case
- "Book test 3: a record type and a record variable"
- ~code:
- " \
- /* a record type and a record variable */ \
- let \
- type rectype = \
- { name : string \
- , age : int \
- } \
- var rec1 : rectype := \
- rectype \
- { name = \"Nobody\" \
- , age = 1000 \
- } \
- in \
- rec1.name := \"Somebody\"; \
- rec1 \
- end \
- "
- ~out_lexing:(
- let open Tiger_parser in
- [ LET;
- TYPE; ID "rectype"; EQ;
- LBRACE; ID "name"; COLON; ID "string";
- COMMA; ID "age"; COLON; ID "int";
- RBRACE;
- VAR; ID "rec1"; COLON; ID "rectype"; ASSIGN;
- ID "rectype";
- LBRACE; ID "name"; EQ; STRING "Nobody";
- COMMA; ID "age"; EQ; INT 1000;
- RBRACE;
- IN;
- ID "rec1"; DOT; ID "name"; ASSIGN; STRING "Somebody"; SEMICOLON;
- ID "rec1";
- END
- ]
- )
- ; Test.case
- "Book test 4: define a recursive function"
- ~code:
- " \
- /* define a recursive function */ \
- let \
- \
- /* calculate n! */ \
- function nfactor(n: int): int = \
- if n = 0 \
- then 1 \
- else n * nfactor(n-1) \
- \
+let micro =
+ let open Tiger_parser in
+ [ (let code = "nil" in Test.case code ~code ~out_lexing:(Some [NIL]))
+ ; (let code = "5" in Test.case code ~code ~out_lexing:(Some [INT 5]))
+ ; (let code = "-5" in Test.case code ~code ~out_lexing:(Some [MINUS; INT 5]))
+ ; ( let code = "f()" in
+ Test.case
+ code
+ ~code
+ ~out_lexing:(Some [ID "f"; LPAREN; RPAREN])
+ (* TODO: Be more specific *)
+ ~is_error_expected_semant:(Some Error.is_unknown_id)
+ )
+ ; ( let code = "abc.i" in
+ Test.case
+ code
+ ~code
+ ~out_lexing:(Some [ID "abc"; DOT; ID "i"])
+ (* TODO: Be more specific *)
+ ~is_error_expected_semant:(Some Error.is_unknown_id)
+ )
+ ; ( let code = "abc[0]" in
+ Test.case
+ code
+ ~code
+ ~out_lexing:(Some [ID "abc"; LBRACK; INT 0; RBRACK])
+ (* TODO: Be more specific *)
+ ~is_error_expected_semant:(Some Error.is_unknown_id)
+ )
+ ; ( let code = "abc[0] := foo()" in
+ Test.case
+ code
+ ~code
+ ~out_lexing:
+ (Some [ID "abc"; LBRACK; INT 0; RBRACK; ASSIGN; ID "foo"; LPAREN; RPAREN])
+ (* TODO: Be more specific *)
+ ~is_error_expected_semant:(Some Error.is_unknown_id)
+ )
+ ; ( let code = "abc [5] of nil" in
+ Test.case
+ code
+ ~code
+ ~out_lexing:(Some [ID "abc"; LBRACK; INT 5; RBRACK; OF; NIL])
+ (* TODO: Be more specific *)
+ ~is_error_expected_semant:(Some Error.is_unknown_type)
+ )
+ ; ( let code = "f(\"a\", 3, foo)" in
+ Test.case
+ code
+ ~code
+ ~out_lexing:
+ (Some [ID "f"; LPAREN; STRING "a"; COMMA; INT 3; COMMA; ID "foo"; RPAREN])
+ ~is_error_expected_semant:(Some Error.is_unknown_id)
+ )
+ ; ( Test.case
+ "Type aliases"
+ ~code:
+ "let \
+ type a = int \
+ type b = a \
+ type c = b \
+ var i : a := 2 \
+ var j : c := 3 \
+ in \
+ i := j \
+ end \
+ "
+ )
+ ; ( let code =
+ "let \
+ type a = {x:int, y:int} \
+ type b = {x:int, y:int} /* new type generated */ \
+ var foo : a := a {x = 1, y = 2} \
+ var bar : b := b {x = 1, y = 2} \