- ; 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 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} \