X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=compiler%2Fsrc%2Flib%2Ftiger%2Ftiger_test_cases.ml;h=1ead5f5226aa2e197513083e34ed47f606b4324d;hb=HEAD;hp=45a4e1d426e535746373fbd094d6c754aaa8bbec;hpb=6d83a0545c204cf46413799836f7343faabb716e;p=tiger.ml.git diff --git a/compiler/src/lib/tiger/tiger_test_cases.ml b/compiler/src/lib/tiger/tiger_test_cases.ml index 45a4e1d..1ead5f5 100644 --- a/compiler/src/lib/tiger/tiger_test_cases.ml +++ b/compiler/src/lib/tiger/tiger_test_cases.ml @@ -55,21 +55,19 @@ let micro = (Some [ID "f"; LPAREN; STRING "a"; COMMA; INT 3; COMMA; ID "foo"; RPAREN]) ~is_error_expected_semant:(Some Error.is_unknown_id) ) - ; ( let code = - "let \ - type a = int \ - type b = a \ - type c = b \ - var i : a := 2 \ - var j : c := 3 \ - in \ - i := j \ - end \ - " - in - Test.case + ; ( Test.case "Type aliases" - ~code + ~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 \ @@ -88,6 +86,64 @@ let micro = (* TODO: Be more specific *) ~is_error_expected_semant:(Some Error.is_wrong_type) ) + ; ( Test.case + "Recursive type def: int list" + ~code:"\ + let \n\ + type intlist = {hd: int, tl: intlist} \n\ + var lst : intlist := intlist {hd=0, tl = nil} \n\ + in \n\ + lst \n\ + end" + ) + ; ( Test.case + "Cycle in type dec" + ~code:"\ + let \n\ + type a = b \n\ + type b = a \n\ + in \n\ + end \ + " + ~is_error_expected_semant:(Some Error.is_cycle_in_type_dec) + ) + ; ( Test.case + "Cycle in type dec" + ~code:"\ + let \n\ + type a = b \n\ + type b = c \n\ + type c = a \n\ + var x : a := 1 \n\ + in \n\ + end \ + " + ~is_error_expected_semant:(Some Error.is_cycle_in_type_dec) + ) + ; ( Test.case + "Break outside loop" + ~code: + "break" + ~is_error_expected_semant:(Some Error.is_break_outside_loop) + ) + ; ( Test.case + "Break within for loop" + ~code:"for i := 0 to 5 do (print(\"x\"); break)" + ) + ; ( Test.case + "Break after for loop" + ~code:"(for i := 0 to 5 do (print(\"x\"); break); break)" + ~is_error_expected_semant:(Some Error.is_break_outside_loop) + ) + ; ( Test.case + "Break within while loop" + ~code:"while 1 do (print(\"x\"); break)" + ) + ; ( Test.case + "Break after while loop" + ~code:"(while 1 do (print(\"x\"); break); break)" + ~is_error_expected_semant:(Some Error.is_break_outside_loop) + ) ] let book ~dir =