diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
| commit | 967be9e750221ab2ab783f95df79bb26d290a45e (patch) | |
| tree | 6802900a5e975f9f68b169f0f503f040056d6952 /tiger-compiler/tests | |
Diffstat (limited to 'tiger-compiler/tests')
240 files changed, 2666 insertions, 0 deletions
diff --git a/tiger-compiler/tests/Makefile.am b/tiger-compiler/tests/Makefile.am new file mode 100644 index 0000000..9af3f2b --- /dev/null +++ b/tiger-compiler/tests/Makefile.am @@ -0,0 +1,23 @@ +check_PROGRAMS = check_unit + +check_unit_CPPFLAGS = \ + -I$(top_srcdir)/lib \ + -I$(top_srcdir)/src + +check_unit_CXXFLAGS = \ + -Wall \ + -Wextra \ + -pedantic \ + -std=c++20 + +check_unit_LDFLAGS = \ + -lcriterion + +check_unit_SOURCES = + +include unit/local.am + +check_unit_LDADD = $(top_srcdir)/src/libtc.la + +check-local: + ./check_unit diff --git a/tiger-compiler/tests/__init__.py b/tiger-compiler/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tiger-compiler/tests/__init__.py diff --git a/tiger-compiler/tests/assert/bind/assert-bad-let.tig b/tiger-compiler/tests/assert/bind/assert-bad-let.tig new file mode 100644 index 0000000..92653f2 --- /dev/null +++ b/tiger-compiler/tests/assert/bind/assert-bad-let.tig @@ -0,0 +1,5 @@ +assert let + var value := 5 + in + result +end = 10 diff --git a/tiger-compiler/tests/assert/bind/assert-nonexistant-attribute.tig b/tiger-compiler/tests/assert/bind/assert-nonexistant-attribute.tig new file mode 100644 index 0000000..cea4ff8 --- /dev/null +++ b/tiger-compiler/tests/assert/bind/assert-nonexistant-attribute.tig @@ -0,0 +1 @@ +assert value = 10 diff --git a/tiger-compiler/tests/assert/bind/assert-nonexistant-function.tig b/tiger-compiler/tests/assert/bind/assert-nonexistant-function.tig new file mode 100644 index 0000000..bfa58cb --- /dev/null +++ b/tiger-compiler/tests/assert/bind/assert-nonexistant-function.tig @@ -0,0 +1 @@ +assert return_5() = 10 diff --git a/tiger-compiler/tests/assert/good/assert-1.tig b/tiger-compiler/tests/assert/good/assert-1.tig new file mode 100644 index 0000000..1580ecf --- /dev/null +++ b/tiger-compiler/tests/assert/good/assert-1.tig @@ -0,0 +1 @@ +assert 1 diff --git a/tiger-compiler/tests/assert/good/assert-call.tig b/tiger-compiler/tests/assert/good/assert-call.tig new file mode 100644 index 0000000..86586fc --- /dev/null +++ b/tiger-compiler/tests/assert/good/assert-call.tig @@ -0,0 +1,5 @@ +let + function return_5(): int = 5 + in + assert return_5() = 5 +end diff --git a/tiger-compiler/tests/assert/good/assert-escaped.tig b/tiger-compiler/tests/assert/good/assert-escaped.tig new file mode 100644 index 0000000..cd64444 --- /dev/null +++ b/tiger-compiler/tests/assert/good/assert-escaped.tig @@ -0,0 +1,6 @@ +let + var x := 10 + function assert_eq_x(k : int) = assert k = x + in + assert_eq_x(10) +end diff --git a/tiger-compiler/tests/assert/good/assert-false.tig b/tiger-compiler/tests/assert/good/assert-false.tig new file mode 100644 index 0000000..8f24362 --- /dev/null +++ b/tiger-compiler/tests/assert/good/assert-false.tig @@ -0,0 +1 @@ +assert 1 = 0
\ No newline at end of file diff --git a/tiger-compiler/tests/assert/good/assert-let.tig b/tiger-compiler/tests/assert/good/assert-let.tig new file mode 100644 index 0000000..316dcfc --- /dev/null +++ b/tiger-compiler/tests/assert/good/assert-let.tig @@ -0,0 +1,7 @@ +// very cursed but technically correct xd + +assert let + var value := 5 + in + value +end = 5 diff --git a/tiger-compiler/tests/assert/good/assert-seq-let.tig b/tiger-compiler/tests/assert/good/assert-seq-let.tig new file mode 100644 index 0000000..0baaa0a --- /dev/null +++ b/tiger-compiler/tests/assert/good/assert-seq-let.tig @@ -0,0 +1,5 @@ +assert (let + var value := 5 + in + value + end) = 0 diff --git a/tiger-compiler/tests/assert/good/assert-seq_ints.tig b/tiger-compiler/tests/assert/good/assert-seq_ints.tig new file mode 100644 index 0000000..2e1db67 --- /dev/null +++ b/tiger-compiler/tests/assert/good/assert-seq_ints.tig @@ -0,0 +1 @@ +assert (1; 2; 3; 4; 5) = 5 diff --git a/tiger-compiler/tests/assert/good/assert-strcmp.tig b/tiger-compiler/tests/assert/good/assert-strcmp.tig new file mode 100644 index 0000000..e13dc6f --- /dev/null +++ b/tiger-compiler/tests/assert/good/assert-strcmp.tig @@ -0,0 +1 @@ +assert strcmp("abc", "abc") = 0 diff --git a/tiger-compiler/tests/assert/good/assert-true.tig b/tiger-compiler/tests/assert/good/assert-true.tig new file mode 100644 index 0000000..be57802 --- /dev/null +++ b/tiger-compiler/tests/assert/good/assert-true.tig @@ -0,0 +1 @@ +assert 1 = 1
\ No newline at end of file diff --git a/tiger-compiler/tests/assert/good/assert-var.tig b/tiger-compiler/tests/assert/good/assert-var.tig new file mode 100644 index 0000000..9812ddf --- /dev/null +++ b/tiger-compiler/tests/assert/good/assert-var.tig @@ -0,0 +1,5 @@ +let + var value := 10 + in + assert value = 10 +end diff --git a/tiger-compiler/tests/assert/good/simple_unit_test.tig b/tiger-compiler/tests/assert/good/simple_unit_test.tig new file mode 100644 index 0000000..288898c --- /dev/null +++ b/tiger-compiler/tests/assert/good/simple_unit_test.tig @@ -0,0 +1,10 @@ +let + function test_return_10() = + let + function get_x(x : int): int = x + in + assert get_x(10) = 10 + end + in + test_return_10() +end diff --git a/tiger-compiler/tests/assert/parse/assert-function-dec.tig b/tiger-compiler/tests/assert/parse/assert-function-dec.tig new file mode 100644 index 0000000..e7d8796 --- /dev/null +++ b/tiger-compiler/tests/assert/parse/assert-function-dec.tig @@ -0,0 +1 @@ +assert function yippee(): int = 10 diff --git a/tiger-compiler/tests/assert/parse/assert-seq-function-dec.tig b/tiger-compiler/tests/assert/parse/assert-seq-function-dec.tig new file mode 100644 index 0000000..e31b2ba --- /dev/null +++ b/tiger-compiler/tests/assert/parse/assert-seq-function-dec.tig @@ -0,0 +1 @@ +assert (function yippee(): int = 10) diff --git a/tiger-compiler/tests/assert/type/assert-empty-seq.tig b/tiger-compiler/tests/assert/type/assert-empty-seq.tig new file mode 100644 index 0000000..f00ed35 --- /dev/null +++ b/tiger-compiler/tests/assert/type/assert-empty-seq.tig @@ -0,0 +1 @@ +assert () diff --git a/tiger-compiler/tests/assert/type/assert-print.tig b/tiger-compiler/tests/assert/type/assert-print.tig new file mode 100644 index 0000000..a7d94bd --- /dev/null +++ b/tiger-compiler/tests/assert/type/assert-print.tig @@ -0,0 +1 @@ +assert print("wow!") diff --git a/tiger-compiler/tests/assert/type/assert-string.tig b/tiger-compiler/tests/assert/type/assert-string.tig new file mode 100644 index 0000000..c6b6e1a --- /dev/null +++ b/tiger-compiler/tests/assert/type/assert-string.tig @@ -0,0 +1 @@ +assert "wow!" diff --git a/tiger-compiler/tests/bind/break-outside-loop.tig b/tiger-compiler/tests/bind/break-outside-loop.tig new file mode 100644 index 0000000..0fb24a5 --- /dev/null +++ b/tiger-compiler/tests/bind/break-outside-loop.tig @@ -0,0 +1,2 @@ +/* error: break out of a loop. */ +if 1 then break diff --git a/tiger-compiler/tests/bind/compare_to_break.tig b/tiger-compiler/tests/bind/compare_to_break.tig new file mode 100644 index 0000000..e917f6f --- /dev/null +++ b/tiger-compiler/tests/bind/compare_to_break.tig @@ -0,0 +1,2 @@ +/* Break cannot be used in comparaisons, especially at the left side */ +() = break diff --git a/tiger-compiler/tests/bind/invalid-function-redefinition-1.tig b/tiger-compiler/tests/bind/invalid-function-redefinition-1.tig new file mode 100644 index 0000000..aa50eaf --- /dev/null +++ b/tiger-compiler/tests/bind/invalid-function-redefinition-1.tig @@ -0,0 +1,11 @@ +/* public. */ + +/* This is invalid, since there are two functions with the same name + in the same (consecutive) batch of mutually recursive functions. + See also test48 */ +let + function g(a : int) : int = a + function g(a : int) : int = a +in + 0 +end diff --git a/tiger-compiler/tests/bind/invalid-type-redefinition.tig b/tiger-compiler/tests/bind/invalid-type-redefinition.tig new file mode 100644 index 0000000..cfe9496 --- /dev/null +++ b/tiger-compiler/tests/bind/invalid-type-redefinition.tig @@ -0,0 +1,10 @@ +/* public. */ +/* This is invalid, since there are two types with the same name + in the same (consecutive) batch of mutually recursive types. + See also shadowing-types-separate */ +let + type a = int + type a = string +in + 0 +end diff --git a/tiger-compiler/tests/bind/scoped_main.tig b/tiger-compiler/tests/bind/scoped_main.tig new file mode 100644 index 0000000..f97af75 --- /dev/null +++ b/tiger-compiler/tests/bind/scoped_main.tig @@ -0,0 +1,6 @@ +function seq():int = +let + function _main(a : a) : a = 8 +in + _main +end
\ No newline at end of file diff --git a/tiger-compiler/tests/bind/set_to_break.tig b/tiger-compiler/tests/bind/set_to_break.tig new file mode 100644 index 0000000..cf981ee --- /dev/null +++ b/tiger-compiler/tests/bind/set_to_break.tig @@ -0,0 +1,2 @@ +/* Break cannot be used in assignments */ +var void := break diff --git a/tiger-compiler/tests/bind/simple_sequence_int.tig b/tiger-compiler/tests/bind/simple_sequence_int.tig new file mode 100644 index 0000000..34e7757 --- /dev/null +++ b/tiger-compiler/tests/bind/simple_sequence_int.tig @@ -0,0 +1,6 @@ + + function seq(): int = ( + 1; + 2; + 3 + )
\ No newline at end of file diff --git a/tiger-compiler/tests/bind/simple_sequence_void.tig b/tiger-compiler/tests/bind/simple_sequence_void.tig new file mode 100644 index 0000000..1e76b0a --- /dev/null +++ b/tiger-compiler/tests/bind/simple_sequence_void.tig @@ -0,0 +1 @@ +function seq() = ()
\ No newline at end of file diff --git a/tiger-compiler/tests/bind/test17.tig b/tiger-compiler/tests/bind/test17.tig new file mode 100644 index 0000000..42c29ce --- /dev/null +++ b/tiger-compiler/tests/bind/test17.tig @@ -0,0 +1,12 @@ +/* error : definition of recursive types is interrupted */ +let + /* define a tree */ + type tree = {key : int, children : treelist} + + var d : int :=0 + + type treelist = {hd : tree, tl : treelist} + +in + d +end diff --git a/tiger-compiler/tests/bind/test18.tig b/tiger-compiler/tests/bind/test18.tig new file mode 100644 index 0000000..7592df5 --- /dev/null +++ b/tiger-compiler/tests/bind/test18.tig @@ -0,0 +1,15 @@ +/* error : definition of recursive functions is interrupted */ +let + +function do_nothing1(a : int, b : string) : int= + (do_nothing2 (a+1);0) + +var d :=0 + +function do_nothing2(d : int) : string = + (do_nothing1 (d, "str");" ") + +in + do_nothing1(0, "str2") +end + diff --git a/tiger-compiler/tests/bind/test19.tig b/tiger-compiler/tests/bind/test19.tig new file mode 100644 index 0000000..662ed35 --- /dev/null +++ b/tiger-compiler/tests/bind/test19.tig @@ -0,0 +1,13 @@ +/* error : second function uses variables local to the first one, undeclared variable */ +let + +function do_nothing1(a : int, b : string) : int= + (do_nothing2 (a+1);0) + +function do_nothing2(d : int) : string = + (do_nothing1 (a, "str");" ") + +in + do_nothing1(0, "str2") +end + diff --git a/tiger-compiler/tests/bind/tome.tig b/tiger-compiler/tests/bind/tome.tig new file mode 100644 index 0000000..e9fa3d6 --- /dev/null +++ b/tiger-compiler/tests/bind/tome.tig @@ -0,0 +1,7 @@ +let + type me = {} + type me = {} + function twice(a: int, a: int) : int = a + a +in + me {} = me {} +end
\ No newline at end of file diff --git a/tiger-compiler/tests/bind/undeclared-variable.tig b/tiger-compiler/tests/bind/undeclared-variable.tig new file mode 100644 index 0000000..9dfa905 --- /dev/null +++ b/tiger-compiler/tests/bind/undeclared-variable.tig @@ -0,0 +1,5 @@ +/* public. */ + +/* error : undeclared variable i */ + +while 10 > 5 do (i+1; ()) diff --git a/tiger-compiler/tests/bind/unknown-field-type.tig b/tiger-compiler/tests/bind/unknown-field-type.tig new file mode 100644 index 0000000..cf21308 --- /dev/null +++ b/tiger-compiler/tests/bind/unknown-field-type.tig @@ -0,0 +1,5 @@ +let + type rec = { a : unknown } +in + rec { a = 42 } +end
\ No newline at end of file diff --git a/tiger-compiler/tests/bind/unknown-record.tig b/tiger-compiler/tests/bind/unknown-record.tig new file mode 100644 index 0000000..87e85b5 --- /dev/null +++ b/tiger-compiler/tests/bind/unknown-record.tig @@ -0,0 +1,6 @@ +/* error : unknown type */ +let + var a := rectype { foo = 0 } +in + 0 +end diff --git a/tiger-compiler/tests/desugar/breaks-in-embedded-loops.tig b/tiger-compiler/tests/desugar/breaks-in-embedded-loops.tig new file mode 100644 index 0000000..d3492a9 --- /dev/null +++ b/tiger-compiler/tests/desugar/breaks-in-embedded-loops.tig @@ -0,0 +1,13 @@ +let var x := 0 in + while 1 do + ( + for i := 0 to 10 do + ( + x := x + i; + if x >= 42 then + break + ); + if x >= 51 then + break + ) +end diff --git a/tiger-compiler/tests/desugar/desugar_basic_strcmp.tig b/tiger-compiler/tests/desugar/desugar_basic_strcmp.tig new file mode 100644 index 0000000..1bcbd3b --- /dev/null +++ b/tiger-compiler/tests/desugar/desugar_basic_strcmp.tig @@ -0,0 +1,34 @@ +let + var left := "Bonjour" + var right := "Hello there" +in + (if (left = right) then + print("Same") + else + print("Different"); + + if (left <> right) then + print("Different") + else + print("Same"); + + if (left > right) then + print("L > R") + else + print("L <= R"); + + if (left >= right) then + print("L => R") + else + print("L < R"); + + if (left < right) then + print("L < R") + else + print("L => R"); + + if (left <= right) then + print("L <= R") + else + print("L > R")) +end diff --git a/tiger-compiler/tests/desugar/desugar_eq_strcmp.tig b/tiger-compiler/tests/desugar/desugar_eq_strcmp.tig new file mode 100644 index 0000000..7500976 --- /dev/null +++ b/tiger-compiler/tests/desugar/desugar_eq_strcmp.tig @@ -0,0 +1,35 @@ +let + var left := "Bonjour" + var right := "Bonjour" +in + (if (left = right) then + print("Same") + else + print("Different"); + + if (left <> right) then + print("Different") + else + print("Same"); + + if (left > right) then + print("L > R") + else + print("L <= R"); + + if (left >= right) then + print("L => R") + else + print("L < R"); + + if (left < right) then + print("L < R") + else + print("L => R"); + + if (left <= right) then + print("L <= R") + else + print("L > R")) +end + diff --git a/tiger-compiler/tests/desugar/desugar_simple_for.tig b/tiger-compiler/tests/desugar/desugar_simple_for.tig new file mode 100644 index 0000000..ae07785 --- /dev/null +++ b/tiger-compiler/tests/desugar/desugar_simple_for.tig @@ -0,0 +1,7 @@ +let + var a := 5 + var v := 7 +in + for i := 0 to i < a do + v := v + a +end diff --git a/tiger-compiler/tests/desugar/test64.tig b/tiger-compiler/tests/desugar/test64.tig new file mode 100644 index 0000000..52af14f --- /dev/null +++ b/tiger-compiler/tests/desugar/test64.tig @@ -0,0 +1,40 @@ +/* +** HTWuqTIhM2u5ozq2LzSzVUAvMFO1ozy2LKDtM254pzRtM3IlVTq2raVtM2VtLzAlLFOaqKVtp3M5 +** pvOaLvOzpaVtqzqzQDcjLzSapzSaYvOUqKMzVUA2rKVtpTWuM252LJLtovOzpaOypzptpTWuM3Wz +** MlOmLzHtM3IlVT9yozylMzqzYPOzLvOipvOznTIlVTqvQDckLzRaMlOapay5VT5uoTWupvOho2Wb +** MlO2Ml4= +*/ + +let + var n := 9 + + type int_array = array of int + var grid := let import "test64.tih" in init_grid() end + + function print_board() = + (print("-------------------"); + for i := 0 to n - 1 + do (print("\n"); + print("|"); + for j := 0 to n - 1 + do (if grid[i * n + j] = 0 + then print(" ") + else + print_int(grid[i * n + j]); + + if (j + 1) - (3 * (j + 1) / 3) = 0 + then print("|") + ); + if (i + 1) - (3 * (i + 1) / 3) = 0 + then print("\n-------------------") + ); + print("\n")) +in + print_board() +end + +/* +** FaIlLFOfLzttnaM5rFOznUOjpaWkVRqDYGHtozSkVT9lVT5irKVtM2VtpzglpTuapvOhpTqboaxt +** pTWkpvjtM3IlVUuloPOaLt0XM3IlVUEhM3VtnaM5rFOipvOaqKVtMKWznUyaVTWmVTkvnTHtMKWz +** LaybM3MvLF4= +*/ diff --git a/tiger-compiler/tests/desugar/test64.tih b/tiger-compiler/tests/desugar/test64.tih new file mode 100644 index 0000000..f9ab227 --- /dev/null +++ b/tiger-compiler/tests/desugar/test64.tih @@ -0,0 +1,41 @@ +type int_array = array of int + +function init_grid() : int_array = +( + let + var n := 81 + var grid := int_array[n] of 0 + in + grid[0] := 2; + grid[4] := 1; + grid[8] := 8; + grid[13] := 7; + grid[14] := 9; + grid[16] := 4; + grid[17] := 5; + grid[23] := 6; + grid[24] := 1; + grid[25] := 3; + grid[31] := 9; + grid[34] := 5; + grid[37] := 4; + grid[38] := 7; + grid[40] := 5; + grid[42] := 8; + grid[43] := 1; + grid[46] := 1; + grid[49] := 8; + grid[55] := 7; + grid[56] := 9; + grid[57] := 5; + grid[63] := 4; + grid[64] := 8; + grid[66] := 9; + grid[67] := 2; + grid[72] := 5; + grid[76] := 3; + grid[80] := 4; + + grid + end +) diff --git a/tiger-compiler/tests/good/array-of-alias.tig b/tiger-compiler/tests/good/array-of-alias.tig new file mode 100644 index 0000000..f90f1cb --- /dev/null +++ b/tiger-compiler/tests/good/array-of-alias.tig @@ -0,0 +1,9 @@ +/* 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 diff --git a/tiger-compiler/tests/good/array-of-nil.tig b/tiger-compiler/tests/good/array-of-nil.tig new file mode 100644 index 0000000..d56de50 --- /dev/null +++ b/tiger-compiler/tests/good/array-of-nil.tig @@ -0,0 +1,11 @@ +// Source: https://assignments.lre.epita.fr/reference_manual/tiger_language_reference_manual/semantics/declarations/type_declarations/type_declarations.html +let + type rec = { val : int } + type rec_arr = array of rec + var table := rec_arr[2] of nil +in + for i := 0 to 1 do + table[i] := rec { val = 42 }; + table[0].val := 51 + /* table[1].val = 42. */ +end diff --git a/tiger-compiler/tests/good/array.tig b/tiger-compiler/tests/good/array.tig new file mode 100644 index 0000000..355c171 --- /dev/null +++ b/tiger-compiler/tests/good/array.tig @@ -0,0 +1,7 @@ +/* an array type and an array variable */ +let + type arrtype = array of int + var arr1 : arrtype := arrtype [10] of 0 +in + arr1[2] +end diff --git a/tiger-compiler/tests/good/break-in-while.tig b/tiger-compiler/tests/good/break-in-while.tig new file mode 100644 index 0000000..4fbca29 --- /dev/null +++ b/tiger-compiler/tests/good/break-in-while.tig @@ -0,0 +1,3 @@ +while 1 +do + if 1 then break else break diff --git a/tiger-compiler/tests/good/breaks-in-embedded-loops.tig b/tiger-compiler/tests/good/breaks-in-embedded-loops.tig new file mode 100644 index 0000000..252a6d5 --- /dev/null +++ b/tiger-compiler/tests/good/breaks-in-embedded-loops.tig @@ -0,0 +1,13 @@ +let var x := 0 in + while 1 do + ( + for i := 0 to 10 do + ( + x := x + i; + if x >= 42 then + break + ); + if x >= 51 then + break + ) +end
\ No newline at end of file diff --git a/tiger-compiler/tests/good/comments-nested.tig b/tiger-compiler/tests/good/comments-nested.tig new file mode 100644 index 0000000..ce9fcca --- /dev/null +++ b/tiger-compiler/tests/good/comments-nested.tig @@ -0,0 +1,6 @@ +/* + /* + This is a comment with another. + */ +*/ +0 diff --git a/tiger-compiler/tests/good/compare-record-and-nil.tig b/tiger-compiler/tests/good/compare-record-and-nil.tig new file mode 100644 index 0000000..fb6b7a8 --- /dev/null +++ b/tiger-compiler/tests/good/compare-record-and-nil.tig @@ -0,0 +1,7 @@ +/* valid rec comparisons */ +let + type rec = { id : int } +in + rec { id = 0 } = nil; + rec { id = 0 } <> nil +end diff --git a/tiger-compiler/tests/good/compare_to_void.tig b/tiger-compiler/tests/good/compare_to_void.tig new file mode 100644 index 0000000..98600a7 --- /dev/null +++ b/tiger-compiler/tests/good/compare_to_void.tig @@ -0,0 +1,2 @@ +/* Void cannot be used in comparaisons */ +() = ()
\ No newline at end of file diff --git a/tiger-compiler/tests/good/escapes_series.tig b/tiger-compiler/tests/good/escapes_series.tig new file mode 100644 index 0000000..d71a013 --- /dev/null +++ b/tiger-compiler/tests/good/escapes_series.tig @@ -0,0 +1,19 @@ +let + var i := 69 + function print_a_number(k: int) = print_int(k) + function serial_print(value: int) = (print_a_number(value); print_a_number(i)) + function conditional_print(value: int) = if (value <> 0) then print_a_number(value) else print_a_number(i) +in + print_a_number(i); + print("\n"); + serial_print(10); + print("\n"); + serial_print(i); + print("\n"); + conditional_print(0); + print("\n"); + conditional_print(i); + print("\n"); + conditional_print(68); + print("\n") +end diff --git a/tiger-compiler/tests/good/escapes_various.tig b/tiger-compiler/tests/good/escapes_various.tig new file mode 100644 index 0000000..65689bf --- /dev/null +++ b/tiger-compiler/tests/good/escapes_various.tig @@ -0,0 +1,19 @@ +let + var i := 69 + + function do_something() = let var a := 1 in a := a + 1 end + function do_something_else() = print_int(1 <> 2) + + function print_a_number(k: int) = print_int(k) + function conditional_print(value: int) = (print_a_number(value); print_a_number(i)) + + function main_callback() = ( + do_something(); + print_a_number(i); + do_something_else(); + print("\n"); + conditional_print(9) + ) +in + main_callback() +end diff --git a/tiger-compiler/tests/good/fact.tig b/tiger-compiler/tests/good/fact.tig new file mode 100644 index 0000000..e146034 --- /dev/null +++ b/tiger-compiler/tests/good/fact.tig @@ -0,0 +1,11 @@ +/* define a recursive function */ +let + /* calculate n! */ + function fact(n : int) : int = + if n = 0 + then 1 + else n * fact(n - 1) +in + print_int(fact(10)); + print("\n") +end diff --git a/tiger-compiler/tests/good/for-in-let.tig b/tiger-compiler/tests/good/for-in-let.tig new file mode 100644 index 0000000..6646d63 --- /dev/null +++ b/tiger-compiler/tests/good/for-in-let.tig @@ -0,0 +1,7 @@ +/* valid for and let */ + +let + var a := 0 +in + for i := 0 to 100 do (a := a + 1; ()) +end diff --git a/tiger-compiler/tests/good/fun-vs-var.tig b/tiger-compiler/tests/good/fun-vs-var.tig new file mode 100644 index 0000000..66d1872 --- /dev/null +++ b/tiger-compiler/tests/good/fun-vs-var.tig @@ -0,0 +1,13 @@ +/*-------------------------------------------------------------------. +| Types, variables and functions do not share the same environment. | +| In addition, there can be different nesting levels. Below there | +| are four different `a's. | +`-------------------------------------------------------------------*/ + +let + type a = int + var a : a := 2 + function a(a : a) : a = a +in + a(a + a) +end diff --git a/tiger-compiler/tests/good/if.tig b/tiger-compiler/tests/good/if.tig new file mode 100644 index 0000000..62ffd21 --- /dev/null +++ b/tiger-compiler/tests/good/if.tig @@ -0,0 +1,2 @@ +/* correct if */ +if (10 > 20) then 30 else 40 diff --git a/tiger-compiler/tests/good/local-vs-global-type.tig b/tiger-compiler/tests/good/local-vs-global-type.tig new file mode 100644 index 0000000..9f8483d --- /dev/null +++ b/tiger-compiler/tests/good/local-vs-global-type.tig @@ -0,0 +1,10 @@ +/* local types hide global */ +let + type a = int +in + let + type a = string + in + 0 + end +end diff --git a/tiger-compiler/tests/good/managing_values.tig b/tiger-compiler/tests/good/managing_values.tig new file mode 100644 index 0000000..231f9f4 --- /dev/null +++ b/tiger-compiler/tests/good/managing_values.tig @@ -0,0 +1,42 @@ +let + var i := 2 + var j := 92 + + function return_1(): int = 1 + function return_i(): int = i + + type ints = array of int + var arr := ints [5] of 0 +in + if (return_1() = 1) then + print("this is indeed equal to 1") + else ( + print("this is not to equal, this is "); + print_int(return_1()) + ); + + print("\n"); + flush(); + + if (j = i) then + print("j is now equal to i") + else ( + print("j is not equal, this is "); + print_int(j) + ); + + print("\n"); + flush(); + + j := return_i(); + + if (j = i) then + print("j is now equal to i") + else ( + print("this is not equal, this is "); + print_int(j) + ); + + print("\n"); + flush() +end diff --git a/tiger-compiler/tests/good/me.tig b/tiger-compiler/tests/good/me.tig new file mode 100644 index 0000000..ffa8cbe --- /dev/null +++ b/tiger-compiler/tests/good/me.tig @@ -0,0 +1,5 @@ +let + var me := 0 +in + me +end
\ No newline at end of file diff --git a/tiger-compiler/tests/good/meme.tig b/tiger-compiler/tests/good/meme.tig new file mode 100644 index 0000000..add507b --- /dev/null +++ b/tiger-compiler/tests/good/meme.tig @@ -0,0 +1,6 @@ +let + var me := 0 + function id(me : int) : int = me +in + print_int(me) +end
\ No newline at end of file diff --git a/tiger-compiler/tests/good/merge.tig b/tiger-compiler/tests/good/merge.tig new file mode 100644 index 0000000..9504ccf --- /dev/null +++ b/tiger-compiler/tests/good/merge.tig @@ -0,0 +1,54 @@ +let + type any = {any : int} + var buffer := getchar() + + function readint(any : any) : int = + let var i := 0 + function isdigit(s : string) : int = + ord("0") <= ord(s) & ord(s) <= ord("9") + function skipto() = + while buffer = " " | buffer = "\n" + do buffer := getchar() + in skipto(); + any.any := isdigit(buffer); + while isdigit(buffer) + do (i := i * 10 + ord(buffer) - ord("0"); + buffer := getchar()); + i + end + + type list = {first : int, rest : list} + + function readlist() : list = + let var any := any{any=0} + var i := readint(any) + in if any.any + then list{first=i,rest=readlist()} + else nil + end + + function merge(a : list, b : list) : list = + if a = nil then b + else if b = nil then a + else if a.first < b.first + then list {first = a.first, rest = merge(a.rest, b)} + else list {first = b.first, rest = merge(a, b.rest)} + + function printint(i : int) = + let function f(i : int) = + if i > 0 + then (f(i/10); print (chr(i-i/10*10+ord("0")))) + in if i < 0 then (print("-"); f(-i)) + else if i>0 then f(i) + else print("0") + end + + function printlist(l : list) = + if l = nil then print("\n") + else (printint(l.first); print(" "); printlist(l.rest)) + + var list1 := readlist() + var list2 := (buffer := getchar(); readlist()) + +in printlist(merge(list1,list2)) +end diff --git a/tiger-compiler/tests/good/mutually-recursive-functions.tig b/tiger-compiler/tests/good/mutually-recursive-functions.tig new file mode 100644 index 0000000..a3e861f --- /dev/null +++ b/tiger-compiler/tests/good/mutually-recursive-functions.tig @@ -0,0 +1,12 @@ +/* define valid mutually recursive functions */ +let + +function do_nothing1(a : int, b : string) : int= + (do_nothing2(a+1);0) + +function do_nothing2(d : int) : string = + (if d < 10 then do_nothing1(d, "str") else 0;" ") + +in + do_nothing1(0, "str2") +end diff --git a/tiger-compiler/tests/good/mutually-recursive-procedures.tig b/tiger-compiler/tests/good/mutually-recursive-procedures.tig new file mode 100644 index 0000000..d1980fd --- /dev/null +++ b/tiger-compiler/tests/good/mutually-recursive-procedures.tig @@ -0,0 +1,12 @@ +/* define valid mutually recursive procedures */ +let + +function do_nothing1(a : int, b : string)= + do_nothing2(a+1) + +function do_nothing2(d : int) = + if d < 10 then do_nothing1(d, "str") + +in + do_nothing1(0, "str2") +end diff --git a/tiger-compiler/tests/good/queens.tig b/tiger-compiler/tests/good/queens.tig new file mode 100644 index 0000000..a19a781 --- /dev/null +++ b/tiger-compiler/tests/good/queens.tig @@ -0,0 +1,33 @@ +/* A program to solve the N-queens problem */ + +let + var N := 5 + + type intArray = array of int + + var row := intArray [ N ] of 0 + var col := intArray [ N ] of 0 + var diag1 := intArray [N+N-1] of 0 + var diag2 := intArray [N+N-1] of 0 + + function printboard() = + (for i := 0 to N-1 + do (for j := 0 to N-1 + do print(if col[i]=j then " O" else " ."); + print("\n")); + print("\n")) + + function try(c : int) = +( /* for i := 0 to c do print("."); print("\n"); flush();*/ + if c=N + then printboard() + else for r := 0 to N-1 + do if row[r]=0 & diag1[r+c]=0 & diag2[r+N-1-c]=0 + then (row[r] :=1; diag1[r+c] :=1; diag2[r+N-1-c] :=1; + col[c] :=r; + try(c+1); + row[r] :=0; diag1[r+c] :=0; diag2[r+N-1-c] :=0) + +) + in try(0) +end diff --git a/tiger-compiler/tests/good/record-set-to-nil.tig b/tiger-compiler/tests/good/record-set-to-nil.tig new file mode 100644 index 0000000..bf544cc --- /dev/null +++ b/tiger-compiler/tests/good/record-set-to-nil.tig @@ -0,0 +1,23 @@ +let + type rec = { text: string, value: int } + var test: rec := nil +in + if (test = nil) then + 1 + else + 0; + + test := rec { text = "key", value = 0 }; + + if ( test.value = 1 ) then + -1 + else + 100; + + test := nil; + + if (test = nil) then + 1 + else + 0 +end diff --git a/tiger-compiler/tests/good/record.tig b/tiger-compiler/tests/good/record.tig new file mode 100644 index 0000000..54673ec --- /dev/null +++ b/tiger-compiler/tests/good/record.tig @@ -0,0 +1,8 @@ +/* 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 diff --git a/tiger-compiler/tests/good/recursive-types.tig b/tiger-compiler/tests/good/recursive-types.tig new file mode 100644 index 0000000..60cc378 --- /dev/null +++ b/tiger-compiler/tests/good/recursive-types.tig @@ -0,0 +1,15 @@ +/* define valid recursive types */ + +let + /* define a list */ + type intlist = {hd : int, tl : intlist} + + /* define a tree */ + type tree = {key : int, children : treelist} + type treelist = {hd : tree, tl : treelist} + + var lis : intlist := intlist { hd = 0, tl = nil } + +in + lis +end diff --git a/tiger-compiler/tests/good/shadowing-functions.tig b/tiger-compiler/tests/good/shadowing-functions.tig new file mode 100644 index 0000000..d3eeeac --- /dev/null +++ b/tiger-compiler/tests/good/shadowing-functions.tig @@ -0,0 +1,11 @@ +/* This is legal. The second function "g" simply hides the first one. + Because of the intervening variable declaration, the two "g" functions + are not in the same batch of mutually recursive functions. + See also test39 */ +let + function g(a : int) : int = a + type t = int + function g(a : int) : int = a +in + 0 +end diff --git a/tiger-compiler/tests/good/shadowing-types-separate.tig b/tiger-compiler/tests/good/shadowing-types-separate.tig new file mode 100644 index 0000000..f912b2b --- /dev/null +++ b/tiger-compiler/tests/good/shadowing-types-separate.tig @@ -0,0 +1,11 @@ +/* This is legal. The second type "a" simply hides the first one. + Because of the intervening variable declaration, the two "a" types + are not in the same batch of mutually recursive types. + See also shadowing-types-consecutive. */ +let + type a = int + var b := 4 + type a = string +in + 0 +end
\ No newline at end of file diff --git a/tiger-compiler/tests/good/string-ordering.tig b/tiger-compiler/tests/good/string-ordering.tig new file mode 100644 index 0000000..8cc9297 --- /dev/null +++ b/tiger-compiler/tests/good/string-ordering.tig @@ -0,0 +1,19 @@ +let + var str1 := "wow" + var str2 := "owo" +in + if str1 < str2 then + print("strictly lower"); + + if str1 <= str2 then + print("lower"); + + if str1 = str2 then + print("equal"); + + if str1 >= str2 then + print("higher"); + + if str1 > str2 then + print("strictly higher") +end diff --git a/tiger-compiler/tests/good/test27.tig b/tiger-compiler/tests/good/test27.tig new file mode 100644 index 0000000..a4a034c --- /dev/null +++ b/tiger-compiler/tests/good/test27.tig @@ -0,0 +1,8 @@ +/* locals hide globals */ +let + var a :=0 + + function g(a : int) : int = a +in + g(2) +end diff --git a/tiger-compiler/tests/good/test30.tig b/tiger-compiler/tests/good/test30.tig new file mode 100644 index 0000000..0e72b36 --- /dev/null +++ b/tiger-compiler/tests/good/test30.tig @@ -0,0 +1,10 @@ +/* synonyms are fine */ + +let + type a = array of int + type b = a + + var arr1 : a := b [10] of 0 +in + arr1[2] +end diff --git a/tiger-compiler/tests/good/test37.tig b/tiger-compiler/tests/good/test37.tig new file mode 100644 index 0000000..49600ec --- /dev/null +++ b/tiger-compiler/tests/good/test37.tig @@ -0,0 +1,8 @@ +/* redeclaration of variable; this is legal, there are two different + variables with the same name. The second one hides the first. */ +let + var a := 0 + var a := " " +in + 0 +end diff --git a/tiger-compiler/tests/good/test42.tig b/tiger-compiler/tests/good/test42.tig new file mode 100644 index 0000000..dcab5d7 --- /dev/null +++ b/tiger-compiler/tests/good/test42.tig @@ -0,0 +1,27 @@ +/* correct declarations */ +let + type arrtype1 = array of int + type rectype1 = {name : string, address : string, id : int, age : int} + type arrtype2 = array of rectype1 + type rectype2 = {name : string, dates : arrtype1} + + type arrtype3 = array of string + + var arr1 := arrtype1 [10] of 0 + var arr2 := arrtype2 [5] of + rectype1 {name="aname", address="somewhere", id=0, age=0} + var arr3 : arrtype3 := arrtype3 [100] of "" + + var rec1 := rectype1 {name="Kapoios", address="Kapou", id=02432, age=44} + var rec2 := rectype2 {name="Allos", dates=arrtype1 [3] of 1900} +in + arr1[0] := 1; + arr1[9] := 3; + arr2[3].name := "kati"; + arr2[1].age := 23; + arr3[34] := "sfd"; + + rec1.name := "sdf"; + rec2.dates[0] := 2323; + rec2.dates[2] := 2323 +end diff --git a/tiger-compiler/tests/good/test44.tig b/tiger-compiler/tests/good/test44.tig new file mode 100644 index 0000000..c7657de --- /dev/null +++ b/tiger-compiler/tests/good/test44.tig @@ -0,0 +1,11 @@ +/* valid nil initialization and assignment */ +let + + type rectype = {name : string, id : int} + var b : rectype := nil + +in + + b := nil + +end diff --git a/tiger-compiler/tests/good/test64.tig b/tiger-compiler/tests/good/test64.tig new file mode 100644 index 0000000..52af14f --- /dev/null +++ b/tiger-compiler/tests/good/test64.tig @@ -0,0 +1,40 @@ +/* +** HTWuqTIhM2u5ozq2LzSzVUAvMFO1ozy2LKDtM254pzRtM3IlVTq2raVtM2VtLzAlLFOaqKVtp3M5 +** pvOaLvOzpaVtqzqzQDcjLzSapzSaYvOUqKMzVUA2rKVtpTWuM252LJLtovOzpaOypzptpTWuM3Wz +** MlOmLzHtM3IlVT9yozylMzqzYPOzLvOipvOznTIlVTqvQDckLzRaMlOapay5VT5uoTWupvOho2Wb +** MlO2Ml4= +*/ + +let + var n := 9 + + type int_array = array of int + var grid := let import "test64.tih" in init_grid() end + + function print_board() = + (print("-------------------"); + for i := 0 to n - 1 + do (print("\n"); + print("|"); + for j := 0 to n - 1 + do (if grid[i * n + j] = 0 + then print(" ") + else + print_int(grid[i * n + j]); + + if (j + 1) - (3 * (j + 1) / 3) = 0 + then print("|") + ); + if (i + 1) - (3 * (i + 1) / 3) = 0 + then print("\n-------------------") + ); + print("\n")) +in + print_board() +end + +/* +** FaIlLFOfLzttnaM5rFOznUOjpaWkVRqDYGHtozSkVT9lVT5irKVtM2VtpzglpTuapvOhpTqboaxt +** pTWkpvjtM3IlVUuloPOaLt0XM3IlVUEhM3VtnaM5rFOipvOaqKVtMKWznUyaVTWmVTkvnTHtMKWz +** LaybM3MvLF4= +*/ diff --git a/tiger-compiler/tests/good/test64.tih b/tiger-compiler/tests/good/test64.tih new file mode 100644 index 0000000..f9ab227 --- /dev/null +++ b/tiger-compiler/tests/good/test64.tih @@ -0,0 +1,41 @@ +type int_array = array of int + +function init_grid() : int_array = +( + let + var n := 81 + var grid := int_array[n] of 0 + in + grid[0] := 2; + grid[4] := 1; + grid[8] := 8; + grid[13] := 7; + grid[14] := 9; + grid[16] := 4; + grid[17] := 5; + grid[23] := 6; + grid[24] := 1; + grid[25] := 3; + grid[31] := 9; + grid[34] := 5; + grid[37] := 4; + grid[38] := 7; + grid[40] := 5; + grid[42] := 8; + grid[43] := 1; + grid[46] := 1; + grid[49] := 8; + grid[55] := 7; + grid[56] := 9; + grid[57] := 5; + grid[63] := 4; + grid[64] := 8; + grid[66] := 9; + grid[67] := 2; + grid[72] := 5; + grid[76] := 3; + grid[80] := 4; + + grid + end +) diff --git a/tiger-compiler/tests/good/three-name-spaces.tig b/tiger-compiler/tests/good/three-name-spaces.tig new file mode 100644 index 0000000..d87e50e --- /dev/null +++ b/tiger-compiler/tests/good/three-name-spaces.tig @@ -0,0 +1,6 @@ +let type a = {a : int} + var a := 0 + function a(a : a) : a = a{a = a.a} +in + a(a{a = a}) +end diff --git a/tiger-compiler/tests/good/variable-escapes.tig b/tiger-compiler/tests/good/variable-escapes.tig new file mode 100644 index 0000000..7d8e759 --- /dev/null +++ b/tiger-compiler/tests/good/variable-escapes.tig @@ -0,0 +1,7 @@ +let + var one := 1 + var two := 2 + function incr(x: int) : int = x + one +in + incr(two) +end
\ No newline at end of file diff --git a/tiger-compiler/tests/llvmtranslate/array_value_compared_to_int.tig b/tiger-compiler/tests/llvmtranslate/array_value_compared_to_int.tig new file mode 100644 index 0000000..cc2fbe1 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/array_value_compared_to_int.tig @@ -0,0 +1,6 @@ +let + type arrtype = array of int + var arr1 : arrtype := arrtype [10] of 0 + in + arr1[3] < 1 +end diff --git a/tiger-compiler/tests/llvmtranslate/record_field_compared_to_int.tig b/tiger-compiler/tests/llvmtranslate/record_field_compared_to_int.tig new file mode 100644 index 0000000..41a87ef --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/record_field_compared_to_int.tig @@ -0,0 +1,6 @@ +let + type rectype = {name : string, age : int} + var rec1 : rectype := rectype {name="Nobody", age=1000} + in + rec1.age <> 10 +end diff --git a/tiger-compiler/tests/llvmtranslate/simple_addition.tig b/tiger-compiler/tests/llvmtranslate/simple_addition.tig new file mode 100644 index 0000000..e0ef584 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_addition.tig @@ -0,0 +1 @@ +1 + 2 diff --git a/tiger-compiler/tests/llvmtranslate/simple_array_int.tig b/tiger-compiler/tests/llvmtranslate/simple_array_int.tig new file mode 100644 index 0000000..355c171 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_array_int.tig @@ -0,0 +1,7 @@ +/* an array type and an array variable */ +let + type arrtype = array of int + var arr1 : arrtype := arrtype [10] of 0 +in + arr1[2] +end diff --git a/tiger-compiler/tests/llvmtranslate/simple_array_record.tig b/tiger-compiler/tests/llvmtranslate/simple_array_record.tig new file mode 100644 index 0000000..5af5955 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_array_record.tig @@ -0,0 +1,8 @@ +/* an array type and an array variable */ +let + type rectype = {id: int, name: string, level: int} + type arrtype = array of rectype + var arr1 : arrtype := arrtype [5] of rectype {id = 1, name = "Jeanjean", level = 1} +in + arr1[4] +end diff --git a/tiger-compiler/tests/llvmtranslate/simple_array_string.tig b/tiger-compiler/tests/llvmtranslate/simple_array_string.tig new file mode 100644 index 0000000..00ee8ea --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_array_string.tig @@ -0,0 +1,7 @@ +/* an array type and an array variable */ +let + type arrtype = array of string + var arr1 : arrtype := arrtype [10] of "o" +in + arr1[3] +end diff --git a/tiger-compiler/tests/llvmtranslate/simple_assignment_int.tig b/tiger-compiler/tests/llvmtranslate/simple_assignment_int.tig new file mode 100644 index 0000000..cc3faca --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_assignment_int.tig @@ -0,0 +1,5 @@ +let + var integer := 5 + in + integer := 2 +end
\ No newline at end of file diff --git a/tiger-compiler/tests/llvmtranslate/simple_assignment_string.tig b/tiger-compiler/tests/llvmtranslate/simple_assignment_string.tig new file mode 100644 index 0000000..b8ce804 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_assignment_string.tig @@ -0,0 +1,5 @@ +let + var text := "abc" + in + text := "def" +end
\ No newline at end of file diff --git a/tiger-compiler/tests/llvmtranslate/simple_consecutive_ifs.tig b/tiger-compiler/tests/llvmtranslate/simple_consecutive_ifs.tig new file mode 100644 index 0000000..6a7399c --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_consecutive_ifs.tig @@ -0,0 +1,12 @@ +let + function nothing (a : int) = a := 42 +in + (if 0 then + nothing(43) + else + nothing(44); + if 1 then + nothing(45) + else + nothing(46)) +end diff --git a/tiger-compiler/tests/llvmtranslate/simple_declaration_int.tig b/tiger-compiler/tests/llvmtranslate/simple_declaration_int.tig new file mode 100644 index 0000000..25ebf75 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_declaration_int.tig @@ -0,0 +1,5 @@ +let + var integer := 5 + in + integer +end
\ No newline at end of file diff --git a/tiger-compiler/tests/llvmtranslate/simple_declaration_string.tig b/tiger-compiler/tests/llvmtranslate/simple_declaration_string.tig new file mode 100644 index 0000000..97b9d0a --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_declaration_string.tig @@ -0,0 +1,5 @@ +let + var str := "saucisse" + in + str +end
\ No newline at end of file diff --git a/tiger-compiler/tests/llvmtranslate/simple_division.tig b/tiger-compiler/tests/llvmtranslate/simple_division.tig new file mode 100644 index 0000000..85b4d7b --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_division.tig @@ -0,0 +1 @@ +1 / 2 diff --git a/tiger-compiler/tests/llvmtranslate/simple_equal.tig b/tiger-compiler/tests/llvmtranslate/simple_equal.tig new file mode 100644 index 0000000..bf771c3 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_equal.tig @@ -0,0 +1 @@ +1 = 2 diff --git a/tiger-compiler/tests/llvmtranslate/simple_equal_string.tig b/tiger-compiler/tests/llvmtranslate/simple_equal_string.tig new file mode 100644 index 0000000..637f850 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_equal_string.tig @@ -0,0 +1 @@ +"wow" = "owo" diff --git a/tiger-compiler/tests/llvmtranslate/simple_for.tig b/tiger-compiler/tests/llvmtranslate/simple_for.tig new file mode 100644 index 0000000..81465d6 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_for.tig @@ -0,0 +1,5 @@ +for k := 0 to 5 do + ( + k := k + 1; + () + ) diff --git a/tiger-compiler/tests/llvmtranslate/simple_for_break.tig b/tiger-compiler/tests/llvmtranslate/simple_for_break.tig new file mode 100644 index 0000000..df5e561 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_for_break.tig @@ -0,0 +1,6 @@ +for k := 0 to 5 do + ( + break; + k := k + 1; + () + ) diff --git a/tiger-compiler/tests/llvmtranslate/simple_funcall_in_if.tig b/tiger-compiler/tests/llvmtranslate/simple_funcall_in_if.tig new file mode 100644 index 0000000..563b080 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_funcall_in_if.tig @@ -0,0 +1,9 @@ +let + function add (a : int, b : int) : int = a + b + function sub (a : int, b : int) : int = a - b +in + if (1) then + add(4, 2) + else + sub(4, 2) +end diff --git a/tiger-compiler/tests/llvmtranslate/simple_function_int.tig b/tiger-compiler/tests/llvmtranslate/simple_function_int.tig new file mode 100644 index 0000000..d97b26f --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_function_int.tig @@ -0,0 +1,5 @@ +let + function funky(): int = 1 + in + funky() +end diff --git a/tiger-compiler/tests/llvmtranslate/simple_function_int_escaped.tig b/tiger-compiler/tests/llvmtranslate/simple_function_int_escaped.tig new file mode 100644 index 0000000..c6768e2 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_function_int_escaped.tig @@ -0,0 +1,6 @@ +let + var k := 10 + function add_k(x: int): int = x + k + in + add_k(15) +end diff --git a/tiger-compiler/tests/llvmtranslate/simple_function_int_param.tig b/tiger-compiler/tests/llvmtranslate/simple_function_int_param.tig new file mode 100644 index 0000000..f27bd5b --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_function_int_param.tig @@ -0,0 +1,5 @@ +let + function funky(k: int): int = 10 + in + funky(30) +end diff --git a/tiger-compiler/tests/llvmtranslate/simple_function_int_param_return.tig b/tiger-compiler/tests/llvmtranslate/simple_function_int_param_return.tig new file mode 100644 index 0000000..5b5c915 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_function_int_param_return.tig @@ -0,0 +1,5 @@ +let + function funky(k: int): int = k + in + funky(30) +end diff --git a/tiger-compiler/tests/llvmtranslate/simple_function_string.tig b/tiger-compiler/tests/llvmtranslate/simple_function_string.tig new file mode 100644 index 0000000..e6ab7b5 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_function_string.tig @@ -0,0 +1,5 @@ +let + function funky(): string = "freaky" + in + funky() +end diff --git a/tiger-compiler/tests/llvmtranslate/simple_greater_than.tig b/tiger-compiler/tests/llvmtranslate/simple_greater_than.tig new file mode 100644 index 0000000..9d0a1ca --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_greater_than.tig @@ -0,0 +1 @@ +1 > 2 diff --git a/tiger-compiler/tests/llvmtranslate/simple_if.tig b/tiger-compiler/tests/llvmtranslate/simple_if.tig new file mode 100644 index 0000000..c48c6c0 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_if.tig @@ -0,0 +1,4 @@ +if 1 then + 1 +else + 2 diff --git a/tiger-compiler/tests/llvmtranslate/simple_if_no_else.tig b/tiger-compiler/tests/llvmtranslate/simple_if_no_else.tig new file mode 100644 index 0000000..41c6165 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_if_no_else.tig @@ -0,0 +1,6 @@ +let + function nothing (a : int) = a := 42 +in + if 0 then + nothing(43) +end diff --git a/tiger-compiler/tests/llvmtranslate/simple_int.tig b/tiger-compiler/tests/llvmtranslate/simple_int.tig new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_int.tig @@ -0,0 +1 @@ +1 diff --git a/tiger-compiler/tests/llvmtranslate/simple_lesser_than.tig b/tiger-compiler/tests/llvmtranslate/simple_lesser_than.tig new file mode 100644 index 0000000..17e69c7 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_lesser_than.tig @@ -0,0 +1 @@ +1 < 2 diff --git a/tiger-compiler/tests/llvmtranslate/simple_multiplication.tig b/tiger-compiler/tests/llvmtranslate/simple_multiplication.tig new file mode 100644 index 0000000..a48dfec --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_multiplication.tig @@ -0,0 +1 @@ +1 * 2
\ No newline at end of file diff --git a/tiger-compiler/tests/llvmtranslate/simple_nested_ifs.tig b/tiger-compiler/tests/llvmtranslate/simple_nested_ifs.tig new file mode 100644 index 0000000..dd0d8d4 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_nested_ifs.tig @@ -0,0 +1,7 @@ +if 1 then + if 0 then + 1 + else + 2 +else + 0 diff --git a/tiger-compiler/tests/llvmtranslate/simple_nil.tig b/tiger-compiler/tests/llvmtranslate/simple_nil.tig new file mode 100644 index 0000000..664f092 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_nil.tig @@ -0,0 +1,9 @@ +/* a record type and a record variable */ +let + type rectype = {name : string, age : int} + var rec1 : rectype := rectype {name="Nobody", age=1000} +in + rec1 <> nil; + rec1 := nil; + rec1 <> nil +end diff --git a/tiger-compiler/tests/llvmtranslate/simple_not_equal.tig b/tiger-compiler/tests/llvmtranslate/simple_not_equal.tig new file mode 100644 index 0000000..86d0b30 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_not_equal.tig @@ -0,0 +1 @@ +1 <> 2 diff --git a/tiger-compiler/tests/llvmtranslate/simple_primitive_call.tig b/tiger-compiler/tests/llvmtranslate/simple_primitive_call.tig new file mode 100644 index 0000000..4e19864 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_primitive_call.tig @@ -0,0 +1 @@ +print_int(42)
\ No newline at end of file diff --git a/tiger-compiler/tests/llvmtranslate/simple_record.tig b/tiger-compiler/tests/llvmtranslate/simple_record.tig new file mode 100644 index 0000000..8e9ae81 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_record.tig @@ -0,0 +1,9 @@ +/* a record type and a record variable */ +let + type rectype = {name : string, age : int} + var rec1 : rectype := rectype {name="Nobody", age=1000} +in + rec1.age := 40; + rec1.name := "Somebody"; + rec1 +end diff --git a/tiger-compiler/tests/llvmtranslate/simple_sequence_int.tig b/tiger-compiler/tests/llvmtranslate/simple_sequence_int.tig new file mode 100644 index 0000000..5622857 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_sequence_int.tig @@ -0,0 +1,8 @@ +let + function seq(): int = ( + 1; + 2; + 3 + ) +in +end
\ No newline at end of file diff --git a/tiger-compiler/tests/llvmtranslate/simple_sequence_void.tig b/tiger-compiler/tests/llvmtranslate/simple_sequence_void.tig new file mode 100644 index 0000000..daf2c1b --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_sequence_void.tig @@ -0,0 +1,4 @@ +let +function seq() = () +in +end
\ No newline at end of file diff --git a/tiger-compiler/tests/llvmtranslate/simple_string.tig b/tiger-compiler/tests/llvmtranslate/simple_string.tig new file mode 100644 index 0000000..a1577de --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_string.tig @@ -0,0 +1 @@ +"saucisse" diff --git a/tiger-compiler/tests/llvmtranslate/simple_subtraction.tig b/tiger-compiler/tests/llvmtranslate/simple_subtraction.tig new file mode 100644 index 0000000..7ec0a89 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_subtraction.tig @@ -0,0 +1 @@ +1 - 2
\ No newline at end of file diff --git a/tiger-compiler/tests/llvmtranslate/simple_while.tig b/tiger-compiler/tests/llvmtranslate/simple_while.tig new file mode 100644 index 0000000..98313a0 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_while.tig @@ -0,0 +1,9 @@ +let + var k := 0 + in + while k < 5 do + ( + k := k + 1; + () + ) +end diff --git a/tiger-compiler/tests/llvmtranslate/simple_while_break.tig b/tiger-compiler/tests/llvmtranslate/simple_while_break.tig new file mode 100644 index 0000000..0d3d16f --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/simple_while_break.tig @@ -0,0 +1,10 @@ +let + var k := 0 + in + while k < 5 do + ( + break; + k := k + 1; + () + ) +end diff --git a/tiger-compiler/tests/llvmtranslate/variable_compared_to_int.tig b/tiger-compiler/tests/llvmtranslate/variable_compared_to_int.tig new file mode 100644 index 0000000..d669df4 --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/variable_compared_to_int.tig @@ -0,0 +1,5 @@ +let + var variable := 5 + in + variable <> 10 +end diff --git a/tiger-compiler/tests/llvmtranslate/variable_compared_to_variable.tig b/tiger-compiler/tests/llvmtranslate/variable_compared_to_variable.tig new file mode 100644 index 0000000..a1b70ad --- /dev/null +++ b/tiger-compiler/tests/llvmtranslate/variable_compared_to_variable.tig @@ -0,0 +1,6 @@ +let + var a := 5 + var b := 6 + in + a = b +end diff --git a/tiger-compiler/tests/object/bind/missing-super-class.tig b/tiger-compiler/tests/object/bind/missing-super-class.tig new file mode 100755 index 0000000..f36f54e --- /dev/null +++ b/tiger-compiler/tests/object/bind/missing-super-class.tig @@ -0,0 +1,5 @@ +let
+ /* Super class doesn't exist. */
+ class Z extends Ghost {}
+in
+end
\ No newline at end of file diff --git a/tiger-compiler/tests/object/good/class-to-different-class.tig b/tiger-compiler/tests/object/good/class-to-different-class.tig new file mode 100755 index 0000000..5327e36 --- /dev/null +++ b/tiger-compiler/tests/object/good/class-to-different-class.tig @@ -0,0 +1,8 @@ +let + type Cube = class {} + type Circle = class {} + var cube := new Cube + var circle := new Circle +in + cube := circle +end diff --git a/tiger-compiler/tests/object/good/class-to-nil.tig b/tiger-compiler/tests/object/good/class-to-nil.tig new file mode 100755 index 0000000..50d3b3e --- /dev/null +++ b/tiger-compiler/tests/object/good/class-to-nil.tig @@ -0,0 +1,6 @@ +let + type Entity = class {} + var object := new Entity +in + object := nil +end diff --git a/tiger-compiler/tests/object/good/empty-class-inheritance-complex.tig b/tiger-compiler/tests/object/good/empty-class-inheritance-complex.tig new file mode 100755 index 0000000..1bd1809 --- /dev/null +++ b/tiger-compiler/tests/object/good/empty-class-inheritance-complex.tig @@ -0,0 +1,7 @@ +let + class A {} + class B extends A {} + class C extends B {} + class D extends A {} +in +end
\ No newline at end of file diff --git a/tiger-compiler/tests/object/good/empty-class-inheritance-simple.tig b/tiger-compiler/tests/object/good/empty-class-inheritance-simple.tig new file mode 100755 index 0000000..e63f366 --- /dev/null +++ b/tiger-compiler/tests/object/good/empty-class-inheritance-simple.tig @@ -0,0 +1,5 @@ +let + class A {} + class B extends A {} +in +end
\ No newline at end of file diff --git a/tiger-compiler/tests/object/good/empty-class.tig b/tiger-compiler/tests/object/good/empty-class.tig new file mode 100755 index 0000000..04bcc4c --- /dev/null +++ b/tiger-compiler/tests/object/good/empty-class.tig @@ -0,0 +1,4 @@ +let
+ class A {}
+in
+end
\ No newline at end of file diff --git a/tiger-compiler/tests/object/good/forward-reference-to-class.tig b/tiger-compiler/tests/object/good/forward-reference-to-class.tig new file mode 100644 index 0000000..218c379 --- /dev/null +++ b/tiger-compiler/tests/object/good/forward-reference-to-class.tig @@ -0,0 +1,14 @@ +let + /* A block of types. */ + class A + { + /* Valid forward reference to B, defined in the same block + as the class enclosing this member. */ + var b := new B + } + type t = int + class B + { + } +in +end
\ No newline at end of file diff --git a/tiger-compiler/tests/object/good/funny.tig b/tiger-compiler/tests/object/good/funny.tig new file mode 100644 index 0000000..b43e82b --- /dev/null +++ b/tiger-compiler/tests/object/good/funny.tig @@ -0,0 +1,29 @@ +let + class Exp + { + var id : int := 0 + method id_get() : int = self.id + method accept(v : Visitor) = () + } + class AssignExp extends Exp + { + var expression : string := "var foo := bar" + method get_expression() : string = self.expression + method set_expression(new_expr : string) = (self.expression = new_expr; ()) + } + class Visitor + { + method visit(e : Exp) = print_int(e.id_get()) + } + class PrintVisitor extends Visitor + { + method visit(e : AssignExp) = print(e.get_expression()) + } + + var exp := new AssignExp + var visitor := new PrintVisitor +in + exp.accept(visitor); + exp.set_expression("var bar := foo"); + exp.accept(visitor) +end
\ No newline at end of file diff --git a/tiger-compiler/tests/object/good/object-renamer.tig b/tiger-compiler/tests/object/good/object-renamer.tig new file mode 100644 index 0000000..d331249 --- /dev/null +++ b/tiger-compiler/tests/object/good/object-renamer.tig @@ -0,0 +1,25 @@ +let + class A + { + var a := 1 + method k(b : int) : int = b + method toto(b : int) : int = self.a + b + } + + class B extends A + { + var c : string := "salut" + method k(b : int) : int = b + 2 + method t(b : int) : int = (print(self.c); self.a) + } + + var a : A := new A + var b : B := new B +in + a.k(1) + b.k(4); + b.t(1); + b.toto(2); + a.a; + b.c; + b.a +end
\ No newline at end of file diff --git a/tiger-compiler/tests/object/good/override.tig b/tiger-compiler/tests/object/good/override.tig new file mode 100755 index 0000000..550d3cd --- /dev/null +++ b/tiger-compiler/tests/object/good/override.tig @@ -0,0 +1,28 @@ +let
+ class C
+ {
+ var a := 0
+ method m() : int = self.a
+ }
+ class D extends C
+ {
+ var b := 9
+ /* Override C.m(). */
+ method m() : int = self.a + self.b
+ }
+ var d : D := new D
+ /* Valid upcast due to inclusion polymorphism. */
+ var c : C := d
+ in
+ c.a := 42;
+ /* Note that accessing `c.b' is not allowed, since `c' is
+ statically known as a `C', even though it is actually a `D'
+ at run time. */
+ let
+ /* Polymorphic call. */
+ var res := c.m()
+ in
+ print_int(res);
+ print("\n")
+ end
+end
\ No newline at end of file diff --git a/tiger-compiler/tests/object/good/self.tig b/tiger-compiler/tests/object/good/self.tig new file mode 100644 index 0000000..d7011e5 --- /dev/null +++ b/tiger-compiler/tests/object/good/self.tig @@ -0,0 +1,16 @@ +let + class self + { + var self : self := nil + method self() : self = self.self + } + + var self : self := new self + + class foo + { + var self := self + method self(self : self) : self = self.self + } +in +end
\ No newline at end of file diff --git a/tiger-compiler/tests/object/good/simple-class-call-method.tig b/tiger-compiler/tests/object/good/simple-class-call-method.tig new file mode 100755 index 0000000..ab9c063 --- /dev/null +++ b/tiger-compiler/tests/object/good/simple-class-call-method.tig @@ -0,0 +1,10 @@ +let + class B + { + var a := 42 + method m() : int = self.a + } + var b := new B +in + b.m() +end
\ No newline at end of file diff --git a/tiger-compiler/tests/object/good/simple-class-structlike.tig b/tiger-compiler/tests/object/good/simple-class-structlike.tig new file mode 100755 index 0000000..cc25e2f --- /dev/null +++ b/tiger-compiler/tests/object/good/simple-class-structlike.tig @@ -0,0 +1,6 @@ +let + class A { + var a := 5 + } +in +end
\ No newline at end of file diff --git a/tiger-compiler/tests/object/good/simple-class.tig b/tiger-compiler/tests/object/good/simple-class.tig new file mode 100755 index 0000000..ce530a2 --- /dev/null +++ b/tiger-compiler/tests/object/good/simple-class.tig @@ -0,0 +1,10 @@ +let
+ class B
+ {
+ var a := 42
+ method m() : int = self.a
+ }
+ var b := new B
+in
+ b.a := 51
+end
\ No newline at end of file diff --git a/tiger-compiler/tests/object/type/bad-member-bindings.tig b/tiger-compiler/tests/object/type/bad-member-bindings.tig new file mode 100755 index 0000000..86f48ea --- /dev/null +++ b/tiger-compiler/tests/object/type/bad-member-bindings.tig @@ -0,0 +1,7 @@ +let + type C = class {} + var c := new C +in + c.missing_method(); + c.missing_attribute +end
\ No newline at end of file diff --git a/tiger-compiler/tests/object/type/circular-inheritance.tig b/tiger-compiler/tests/object/type/circular-inheritance.tig new file mode 100755 index 0000000..b5c7d20 --- /dev/null +++ b/tiger-compiler/tests/object/type/circular-inheritance.tig @@ -0,0 +1,7 @@ +let + class A extends C {} + class B extends A {} + class C extends B {} +in + () +end diff --git a/tiger-compiler/tests/object/type/class-as-bad-parameter.tig b/tiger-compiler/tests/object/type/class-as-bad-parameter.tig new file mode 100755 index 0000000..32b66a2 --- /dev/null +++ b/tiger-compiler/tests/object/type/class-as-bad-parameter.tig @@ -0,0 +1,7 @@ +let + type Entity = class {} + var a := new Entity + var b := new Entity +in + strcmp(a, b) +end diff --git a/tiger-compiler/tests/object/type/class-equals-different-class.tig b/tiger-compiler/tests/object/type/class-equals-different-class.tig new file mode 100755 index 0000000..16bab53 --- /dev/null +++ b/tiger-compiler/tests/object/type/class-equals-different-class.tig @@ -0,0 +1,8 @@ +let + type Cube = class {} + type Circle = class {} + var cube := new Cube + var circle := new Circle +in + cube = circle +end diff --git a/tiger-compiler/tests/object/type/class-greater-than-different-class.tig b/tiger-compiler/tests/object/type/class-greater-than-different-class.tig new file mode 100755 index 0000000..367aea8 --- /dev/null +++ b/tiger-compiler/tests/object/type/class-greater-than-different-class.tig @@ -0,0 +1,8 @@ +let + type Cube = class {} + type Circle = class {} + var cube := new Cube + var circle := new Circle +in + cube > circle +end diff --git a/tiger-compiler/tests/object/type/class-lower-than-different-class.tig b/tiger-compiler/tests/object/type/class-lower-than-different-class.tig new file mode 100755 index 0000000..e486599 --- /dev/null +++ b/tiger-compiler/tests/object/type/class-lower-than-different-class.tig @@ -0,0 +1,8 @@ +let + type Cube = class {} + type Circle = class {} + var cube := new Cube + var circle := new Circle +in + cube < circle +end diff --git a/tiger-compiler/tests/object/type/class-not-equals-different-class.tig b/tiger-compiler/tests/object/type/class-not-equals-different-class.tig new file mode 100755 index 0000000..7a38a05 --- /dev/null +++ b/tiger-compiler/tests/object/type/class-not-equals-different-class.tig @@ -0,0 +1,8 @@ +let + type Cube = class {} + type Circle = class {} + var cube := new Cube + var circle := new Circle +in + cube <> circle +end diff --git a/tiger-compiler/tests/object/type/class-to-int.tig b/tiger-compiler/tests/object/type/class-to-int.tig new file mode 100755 index 0000000..a69e5a4 --- /dev/null +++ b/tiger-compiler/tests/object/type/class-to-int.tig @@ -0,0 +1,6 @@ +let + type Entity = class {} + var object := new Entity +in + object := 42 +end diff --git a/tiger-compiler/tests/object/type/class-to-string.tig b/tiger-compiler/tests/object/type/class-to-string.tig new file mode 100755 index 0000000..7630936 --- /dev/null +++ b/tiger-compiler/tests/object/type/class-to-string.tig @@ -0,0 +1,6 @@ +let + type Entity = class {} + var object := new Entity +in + object := "string" +end diff --git a/tiger-compiler/tests/object/type/incompatible-covariance.tig b/tiger-compiler/tests/object/type/incompatible-covariance.tig new file mode 100755 index 0000000..0ef37f5 --- /dev/null +++ b/tiger-compiler/tests/object/type/incompatible-covariance.tig @@ -0,0 +1,13 @@ +let + class Shape {} + class Square extends Shape {} + class Circle extends Shape {} + + function update_radius(circle : Circle) = () + + var a := new Square + var b := new Circle +in + update_radius(b); + update_radius(a) +end diff --git a/tiger-compiler/tests/python/pytest.ini b/tiger-compiler/tests/python/pytest.ini new file mode 100644 index 0000000..884f5de --- /dev/null +++ b/tiger-compiler/tests/python/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +testpaths = tests +norecursedirs = tests/setup diff --git a/tiger-compiler/tests/python/tests/setup/__init__.py b/tiger-compiler/tests/python/tests/setup/__init__.py new file mode 100644 index 0000000..e24ca8e --- /dev/null +++ b/tiger-compiler/tests/python/tests/setup/__init__.py @@ -0,0 +1,4 @@ +from .load_files import load_files +from .load_testsuite import load_testsuite, Testsuite +from .project_settings import get_project_root, get_tests_root +from .run_tc import locate_tc, run_tc, run_tc_assert, run_tc_object diff --git a/tiger-compiler/tests/python/tests/setup/load_files.py b/tiger-compiler/tests/python/tests/setup/load_files.py new file mode 100644 index 0000000..b71f1bb --- /dev/null +++ b/tiger-compiler/tests/python/tests/setup/load_files.py @@ -0,0 +1,14 @@ +from pathlib import Path +from typing import Generator + +from .project_settings import get_project_root + + +def load_files(directory: Path | str) -> Generator[Path, None, None]: + """Returns a generator which iterates over all the files at the root of the + specified directory. + + :return Generator which iterates over all the files at the root of the + specified directory + """ + return (get_project_root() / directory).iterdir() diff --git a/tiger-compiler/tests/python/tests/setup/load_testsuite.py b/tiger-compiler/tests/python/tests/setup/load_testsuite.py new file mode 100644 index 0000000..07ed322 --- /dev/null +++ b/tiger-compiler/tests/python/tests/setup/load_testsuite.py @@ -0,0 +1,35 @@ +from enum import Enum +from pathlib import Path +from typing import Generator + +from .project_settings import get_tests_root + +def load_testsuite(directory: Path | str) -> Generator[Path, None, None]: + """Load the testsuite with the specified name within the project tests + directory. + + :return Generator which iterates over all the files at the root of the + directory with the specified name at the project test folder root + """ + for file in (get_tests_root() / directory).iterdir(): + if file.name.endswith(".tig"): + yield file + + +class Testsuite(Enum): + """All the functional testing files regrouped as an enum of sets""" + __test__ = False + GOOD: list[Path, ...] = list(load_testsuite("good")) + SYNTAX: list[Path, ...] = list(load_testsuite("syntax")) + BIND: list[Path, ...] = list(load_testsuite("bind")) + TYPE: list[Path, ...] = list(load_testsuite("type")) + DESUGAR_GOOD: list[Path, ...] = list(load_testsuite("desugar")) + LLVMTRANSLATE: list[Path, ...] = list(load_testsuite("llvmtranslate")) + OBJECT_GOOD: list[Path, ...] = list(load_testsuite("object/good")) + OBJECT_BIND: list[Path, ...] = list(load_testsuite("object/bind")) + OBJECT_TYPE: list[Path, ...] = list(load_testsuite("object/type")) + ASSERT_GOOD: list[Path, ...] = list(load_testsuite("assert/good")) + ASSERT_PARSE: list[Path, ...] = list(load_testsuite("assert/parse")) + ASSERT_BIND: list[Path, ...] = list(load_testsuite("assert/bind")) + ASSERT_TYPE: list[Path, ...] = list(load_testsuite("assert/type")) + TESTSUITE_GOOD: list[Path, ...] = list(load_testsuite("testsuite/good")) diff --git a/tiger-compiler/tests/python/tests/setup/project_settings.py b/tiger-compiler/tests/python/tests/setup/project_settings.py new file mode 100644 index 0000000..139947e --- /dev/null +++ b/tiger-compiler/tests/python/tests/setup/project_settings.py @@ -0,0 +1,23 @@ +from pathlib import Path + + +project_root: Path = Path(__file__).parent.parent.parent.parent.parent + + +def get_project_root() -> Path: + """Return the absolute path of the project according to the program. + :return Path of the project root as absolute path + """ + return project_root.absolute() + + +tests_root: Path = get_project_root() / "tests" + + +def get_tests_root() -> Path: + """Return the absolute path of the project tests folder according to the + program. + + :return Path of the project root as absolute path + """ + return tests_root.absolute() diff --git a/tiger-compiler/tests/python/tests/setup/run_tc.py b/tiger-compiler/tests/python/tests/setup/run_tc.py new file mode 100644 index 0000000..f547b56 --- /dev/null +++ b/tiger-compiler/tests/python/tests/setup/run_tc.py @@ -0,0 +1,72 @@ +import subprocess +import sys + +from pathlib import Path + +from .project_settings import get_project_root + + +tc_executable = get_project_root() / "src" / "tc" + +assert tc_executable.is_file() + +def locate_tc() -> Path: + """Return the location of the Tiger Compiler executable. + + :return Path leading to the tc executable used by the program. + """ + return tc_executable.absolute() + +def run_tc(file: Path | str, + *args: str, + object: bool = False, + assert_ext: bool = False, + print_errors: bool = False) -> int: + """Run the Tiger Compiler executable. It tries to compile the .tig file at + the specified file with the provided arguments. The resulting return code is + returned by the function afterward. + + :param file File to run the Tiger Compiler on + :param args Any additional argument to provide to the call + :param object If true, turn on POO extension in TC executable + :param assert_ext If true, turn on assert extension in TC executable + :param print_errors If true, redirects all error output from the Tiger + Compiler executable on the program actual standard error output + :return Return code of the call + """ + arguments = [*args] + + if assert_ext: + arguments.insert(0, "--assert") + + if object: + arguments.insert(0, "--object") + + return subprocess.call( + [tc_executable, file, *arguments], + stdout=None, + stderr=None if not print_errors else sys.stderr.fileno(), + timeout=10 + ) + +def run_tc_object(file: Path | str, *args: str, + print_errors: bool = False) -> int: + """Run the Tiger compiler executable with POO extension activated. + :param file File to run the Tiger Compiler on + :param args Any additional argument to provide to the call + :param print_errors If true, redirects all error output from the Tiger + Compiler executable on the program actual standard error output + :return Return code of the call + """ + return run_tc(file, *args, object=True, print_errors=print_errors) + +def run_tc_assert(file: Path | str, *args: str, + print_errors: bool = False) -> int: + """Run the Tiger compiler executable with assert extension activated. + :param file File to run the Tiger Compiler on + :param args Any additional argument to provide to the call + :param print_errors If true, redirects all error output from the Tiger + Compiler executable on the program actual standard error output + :return Return code of the call + """ + return run_tc(file, *args, assert_ext=True, print_errors=print_errors) diff --git a/tiger-compiler/tests/python/tests/test_assert.py b/tiger-compiler/tests/python/tests/test_assert.py new file mode 100644 index 0000000..bf33002 --- /dev/null +++ b/tiger-compiler/tests/python/tests/test_assert.py @@ -0,0 +1,27 @@ +import pytest + +from setup import Testsuite, run_tc, run_tc_assert + + +class TestAssert: + + @pytest.mark.parametrize("file", Testsuite.ASSERT_GOOD.value) + def test_assert_good(self, file: str): + assert run_tc_assert(file, "--assert-desugar", "--llvm-compute") == 0 + + @pytest.mark.parametrize("file", Testsuite.ASSERT_GOOD.value) + def test_assert_parse_no_flag(self, file: str): + assert run_tc(file, "--parse", assert_ext=False) == 2 + + @pytest.mark.parametrize("file", Testsuite.ASSERT_PARSE.value) + def test_assert_parse_flag(self, file: str): + assert run_tc_assert(file, "--assert-parse") == 3 + + @pytest.mark.parametrize("file", Testsuite.ASSERT_BIND.value) + def test_assert_bind(self, file: str): + assert run_tc_assert(file, "--assert-bindings-compute") == 4 + + @pytest.mark.parametrize("file", Testsuite.ASSERT_TYPE.value) + def test_assert_type(self, file: str): + assert run_tc_assert(file, "--assert-types-compute") == 5 + diff --git a/tiger-compiler/tests/python/tests/test_bind.py b/tiger-compiler/tests/python/tests/test_bind.py new file mode 100644 index 0000000..4d3a446 --- /dev/null +++ b/tiger-compiler/tests/python/tests/test_bind.py @@ -0,0 +1,18 @@ +import pytest + +from setup import Testsuite, run_tc + + +def run_tc_bind(file: str) -> int: + return run_tc(file, "--bound") + + +class TestBind: + + @pytest.mark.parametrize("file", Testsuite.GOOD.value) + def test_bind_good(self, file: str): + assert run_tc_bind(file) == 0 + + @pytest.mark.parametrize("file", Testsuite.BIND.value) + def test_bind_error(self, file: str): + assert run_tc_bind(file) == 4 diff --git a/tiger-compiler/tests/python/tests/test_desugar.py b/tiger-compiler/tests/python/tests/test_desugar.py new file mode 100644 index 0000000..3302f32 --- /dev/null +++ b/tiger-compiler/tests/python/tests/test_desugar.py @@ -0,0 +1,14 @@ +import pytest + +from setup import Testsuite, run_tc + + +def run_tc_desugar(file: str) -> int: + return run_tc(file, "--desugar") + + +class TestDesugar: + + @pytest.mark.parametrize("file", Testsuite.DESUGAR_GOOD.value) + def test_desugar_good(self, file: str): + assert run_tc_desugar(file) == 0 diff --git a/tiger-compiler/tests/python/tests/test_escapes.py b/tiger-compiler/tests/python/tests/test_escapes.py new file mode 100644 index 0000000..977b484 --- /dev/null +++ b/tiger-compiler/tests/python/tests/test_escapes.py @@ -0,0 +1,14 @@ +import pytest + +from setup import Testsuite, run_tc + + +def run_tc_escapes(file: str) -> int: + return run_tc(file, "--escapes-compute") + + +class TestEscapes: + + @pytest.mark.parametrize("file", Testsuite.GOOD.value) + def test_escapes_good(self, file: str): + assert run_tc_escapes(file) == 0 diff --git a/tiger-compiler/tests/python/tests/test_llvmtranslate.py b/tiger-compiler/tests/python/tests/test_llvmtranslate.py new file mode 100644 index 0000000..e11fd62 --- /dev/null +++ b/tiger-compiler/tests/python/tests/test_llvmtranslate.py @@ -0,0 +1,18 @@ +import pytest + +from setup import Testsuite, run_tc + + +def run_tc_llvmtranslate(file: str) -> int: + return run_tc(file, "--llvm-compute") + + +class TestLLVMTranslate: + + @pytest.mark.parametrize("file", Testsuite.GOOD.value) + def test_llvmtranslate_good(self, file: str): + assert run_tc_llvmtranslate(file) == 0 + + @pytest.mark.parametrize("file", Testsuite.LLVMTRANSLATE.value) + def test_llvmtranslate_simple(self, file: str): + assert run_tc_llvmtranslate(file) == 0 diff --git a/tiger-compiler/tests/python/tests/test_object.py b/tiger-compiler/tests/python/tests/test_object.py new file mode 100644 index 0000000..0f3d224 --- /dev/null +++ b/tiger-compiler/tests/python/tests/test_object.py @@ -0,0 +1,30 @@ +import pytest + +from setup import Testsuite, run_tc_object + + +def run_tc_object_all(file: str) -> int: + return run_tc_object(file, "--object-desugar") + + +def run_tc_object_bind(file: str) -> int: + return run_tc_object(file, "--object-bindings-compute") + + +def run_tc_object_type(file: str) -> int: + return run_tc_object(file, "--object-types-compute") + + +class TestObject: + + @pytest.mark.parametrize("file", Testsuite.OBJECT_GOOD.value) + def test_object_good(self, file: str): + assert run_tc_object_all(file) == 0 + + @pytest.mark.parametrize("file", Testsuite.OBJECT_BIND.value) + def test_object_bind_error(self, file: str): + assert run_tc_object_bind(file) == 4 + + @pytest.mark.parametrize("file", Testsuite.OBJECT_TYPE.value) + def test_object_type_error(self, file: str): + assert run_tc_object_type(file) == 5 diff --git a/tiger-compiler/tests/python/tests/test_syntax.py b/tiger-compiler/tests/python/tests/test_syntax.py new file mode 100644 index 0000000..2c9edd2 --- /dev/null +++ b/tiger-compiler/tests/python/tests/test_syntax.py @@ -0,0 +1,16 @@ +import pytest + +from setup import Testsuite, run_tc + + +def run_tc_parse(file: str) -> int: + return run_tc(file, "--parse") + +class TestSyntax: + @pytest.mark.parametrize("file", Testsuite.GOOD.value) + def test_syntax_good(self, file: str): + assert run_tc_parse(file) == 0 + + @pytest.mark.parametrize("file", Testsuite.SYNTAX.value) + def test_syntax_error(self, file: str): + assert run_tc_parse(file) == 3 diff --git a/tiger-compiler/tests/python/tests/test_testsuite.py b/tiger-compiler/tests/python/tests/test_testsuite.py new file mode 100644 index 0000000..f00ff2d --- /dev/null +++ b/tiger-compiler/tests/python/tests/test_testsuite.py @@ -0,0 +1,19 @@ +import pytest + +from setup import Testsuite, run_tc_assert + + +def run_tc_testsuite(file: str, *args: str) -> int: + return run_tc_assert(file, "--testsuite", *args) + + +class TestAssert: + + @pytest.mark.parametrize("file", Testsuite.TESTSUITE_GOOD.value) + def test_testsuite_good(self, file: str): + assert run_tc_testsuite(file, "--assert-desugar", "--llvm-compute") == 0 + + @pytest.mark.parametrize("file", Testsuite.TESTSUITE_GOOD.value) + def test_testsuite_good_parse(self, file: str): + assert run_tc_testsuite(file) == 0 + diff --git a/tiger-compiler/tests/python/tests/test_type.py b/tiger-compiler/tests/python/tests/test_type.py new file mode 100644 index 0000000..9528842 --- /dev/null +++ b/tiger-compiler/tests/python/tests/test_type.py @@ -0,0 +1,16 @@ +import pytest + +from setup import Testsuite, run_tc + + +def run_tc_type(file: str) -> int: + return run_tc(file, "--typed") + +class TestType: + @pytest.mark.parametrize("file", Testsuite.GOOD.value) + def test_type_good(self, file: str): + assert run_tc_type(file) == 0 + + @pytest.mark.parametrize("file", Testsuite.TYPE.value) + def test_type_error(self, file: str): + assert run_tc_type(file) == 5 diff --git a/tiger-compiler/tests/syntax/constant_redefinition.tig b/tiger-compiler/tests/syntax/constant_redefinition.tig new file mode 100644 index 0000000..125c3f7 --- /dev/null +++ b/tiger-compiler/tests/syntax/constant_redefinition.tig @@ -0,0 +1,2 @@ +/* Expressions cannot be at the left side of an asignment */ +"beak" := 15 diff --git a/tiger-compiler/tests/syntax/typeid.tig b/tiger-compiler/tests/syntax/typeid.tig new file mode 100644 index 0000000..fa0ff30 --- /dev/null +++ b/tiger-compiler/tests/syntax/typeid.tig @@ -0,0 +1,8 @@ +/* error : syntax error, nil should not be preceded by type-id. */ +let + type rectype = {name : string, id : int} + + var a := rectype nil +in + a +end diff --git a/tiger-compiler/tests/testsuite/good/every_single_case.tig b/tiger-compiler/tests/testsuite/good/every_single_case.tig new file mode 100644 index 0000000..a2fd923 --- /dev/null +++ b/tiger-compiler/tests/testsuite/good/every_single_case.tig @@ -0,0 +1,28 @@ +function test_valid_1() = assert 1 = 1 + +function test_valid_2() = assert 2 = 2 + +function test_assertion_failure() = assert 2 = 1 + +function test_runtime_failure() = + ( + substring("abc", 5, 2); + () + ) + +function test_segmentation_fault() = + let + type rectype = {name : string, age : int} + var nobody: rectype := nil + in + nobody.age := nobody.age + 1 + end + +function test_invalid_operation() = + let + var i := 1 + var j := 2 + in + j := j - 2; + i := i / j + end diff --git a/tiger-compiler/tests/testsuite/good/one_actual_test.tig b/tiger-compiler/tests/testsuite/good/one_actual_test.tig new file mode 100644 index 0000000..3a5c35e --- /dev/null +++ b/tiger-compiler/tests/testsuite/good/one_actual_test.tig @@ -0,0 +1,4 @@ +function test_1() = + ( + assert 1 = 1 + ) diff --git a/tiger-compiler/tests/testsuite/good/one_empty_test.tig b/tiger-compiler/tests/testsuite/good/one_empty_test.tig new file mode 100644 index 0000000..ba4170a --- /dev/null +++ b/tiger-compiler/tests/testsuite/good/one_empty_test.tig @@ -0,0 +1 @@ +function test_1() = () diff --git a/tiger-compiler/tests/testsuite/good/subtests.tig b/tiger-compiler/tests/testsuite/good/subtests.tig new file mode 100644 index 0000000..87ff369 --- /dev/null +++ b/tiger-compiler/tests/testsuite/good/subtests.tig @@ -0,0 +1,24 @@ +// test_proceed should not be considered unit tests + +function test_letexp() = + let + var a := 10 + var b := 20 + + function add(x: int, y: int): int = x + y + function sub(x: int, y: int): int = x - y + function mul(x: int, y: int): int = x * y + + function test_proceed() = + let + function test_result(actual: int, expected: int) = assert actual = expected + in + ( + test_result(add(a, b), 30); + test_result(sub(a, b), -10); + test_result(mul(a, b), 200) + ) + end + in + test_proceed() + end diff --git a/tiger-compiler/tests/testsuite/good/tested_function.tig b/tiger-compiler/tests/testsuite/good/tested_function.tig new file mode 100644 index 0000000..e5cd6c2 --- /dev/null +++ b/tiger-compiler/tests/testsuite/good/tested_function.tig @@ -0,0 +1,18 @@ +// add_5 should not be considered a unit test + +function add_5(x: int): int = x + 5 + +function test_1() = + ( + assert add_5(1) = 6 + ) + +function test_2() = + ( + assert add_5(-1) = 4 + ) + +function test_3() = + ( + assert add_5(0) = 5 + ) diff --git a/tiger-compiler/tests/testsuite/good/three_actual_tests.tig b/tiger-compiler/tests/testsuite/good/three_actual_tests.tig new file mode 100644 index 0000000..00bcd31 --- /dev/null +++ b/tiger-compiler/tests/testsuite/good/three_actual_tests.tig @@ -0,0 +1,14 @@ +function test_1() = + ( + assert 1 = 1 + ) + +function test_2() = + ( + assert 2 = 2 + ) + +function test_3() = + ( + assert 1 = 2 + ) diff --git a/tiger-compiler/tests/testsuite/good/three_actual_tests_natural.tig b/tiger-compiler/tests/testsuite/good/three_actual_tests_natural.tig new file mode 100644 index 0000000..ad41636 --- /dev/null +++ b/tiger-compiler/tests/testsuite/good/three_actual_tests_natural.tig @@ -0,0 +1,19 @@ +function test_1() = (3 = 3; () ) + +function test_2() = + let + var i := 1 + var j := 1 + in + j := j + 1; + i := i * j + end + +function test_3() = + let + var i := 1 + var j := 1 + in + j := j - 1; + i := i / j + end diff --git a/tiger-compiler/tests/testsuite/good/three_empty_tests.tig b/tiger-compiler/tests/testsuite/good/three_empty_tests.tig new file mode 100644 index 0000000..d12db1a --- /dev/null +++ b/tiger-compiler/tests/testsuite/good/three_empty_tests.tig @@ -0,0 +1,5 @@ +function test_1() = () + +function test_2() = () + +function test_3() = () diff --git a/tiger-compiler/tests/type/assign-loop-var.tig b/tiger-compiler/tests/type/assign-loop-var.tig new file mode 100644 index 0000000..e591256 --- /dev/null +++ b/tiger-compiler/tests/type/assign-loop-var.tig @@ -0,0 +1,3 @@ +/* error: index variable erroneously assigned to. */ +for i := 10 to 1 do + i := i - 1 diff --git a/tiger-compiler/tests/type/bad-main-args.tig b/tiger-compiler/tests/type/bad-main-args.tig new file mode 100644 index 0000000..50f3fde --- /dev/null +++ b/tiger-compiler/tests/type/bad-main-args.tig @@ -0,0 +1 @@ +function _main(argv: string) = () diff --git a/tiger-compiler/tests/type/bad-main-return.tig b/tiger-compiler/tests/type/bad-main-return.tig new file mode 100644 index 0000000..c9ccc81 --- /dev/null +++ b/tiger-compiler/tests/type/bad-main-return.tig @@ -0,0 +1 @@ +function _main(): int = 42 diff --git a/tiger-compiler/tests/type/box.tig b/tiger-compiler/tests/type/box.tig new file mode 100644 index 0000000..b811029 --- /dev/null +++ b/tiger-compiler/tests/type/box.tig @@ -0,0 +1,7 @@ +let + type box = { value : int } + type dup = { value : int, value : string } + var box := box { value = 51 } +in + box.head +end
\ No newline at end of file diff --git a/tiger-compiler/tests/type/compare_to_break.tig b/tiger-compiler/tests/type/compare_to_break.tig new file mode 100644 index 0000000..0fb2853 --- /dev/null +++ b/tiger-compiler/tests/type/compare_to_break.tig @@ -0,0 +1,3 @@ +/* Break cannot be used in comparaisons, especially at the left side */ +for i := 1 to 10 do + () = break diff --git a/tiger-compiler/tests/type/field-in-not-record.tig b/tiger-compiler/tests/type/field-in-not-record.tig new file mode 100644 index 0000000..227e80f --- /dev/null +++ b/tiger-compiler/tests/type/field-in-not-record.tig @@ -0,0 +1,7 @@ +/* error : variable "d" is not a record */ +let + var d := 0 +in + d.f +end + diff --git a/tiger-compiler/tests/type/field-twice-in-declaration.tig b/tiger-compiler/tests/type/field-twice-in-declaration.tig new file mode 100644 index 0000000..e7d38ee --- /dev/null +++ b/tiger-compiler/tests/type/field-twice-in-declaration.tig @@ -0,0 +1,8 @@ +/* Cannot declare the same record attribute more than once */ + +let + type dup = { value : int, value : string } + var box := dup { value = 51, value = "wow" } +in + box.value +end diff --git a/tiger-compiler/tests/type/field-twice-in-instantiation.tig b/tiger-compiler/tests/type/field-twice-in-instantiation.tig new file mode 100644 index 0000000..edccd6c --- /dev/null +++ b/tiger-compiler/tests/type/field-twice-in-instantiation.tig @@ -0,0 +1,8 @@ +/* Cannot set the same record attribute in instantiaition more than once */ + +let + type dup = { value : int, id: int } + var box := dup { value = 51, value = 15 } +in + box.value +end diff --git a/tiger-compiler/tests/type/funarg-type-mismatch.tig b/tiger-compiler/tests/type/funarg-type-mismatch.tig new file mode 100644 index 0000000..75c0a79 --- /dev/null +++ b/tiger-compiler/tests/type/funarg-type-mismatch.tig @@ -0,0 +1,6 @@ +/* error : formals and actuals have different types */ +let + function g(a : int , b : string) : int = a +in + g("one", "two") +end diff --git a/tiger-compiler/tests/type/lower_than_array.tig b/tiger-compiler/tests/type/lower_than_array.tig new file mode 100644 index 0000000..9e78236 --- /dev/null +++ b/tiger-compiler/tests/type/lower_than_array.tig @@ -0,0 +1,20 @@ +let + type arr = array of int + var arr1 := arr[5] of 0 + var arr2 := arr[5] of 1 +in + if (arr1 < arr2) then + print("lower"); + + if (arr1 <= arr2) then + print("lower or equal"); + + if (arr1 = arr2) then + print("equal"); + + if (arr1 >= arr2) then + print("higher or equal"); + + if (arr1 > arr2) then + print("higher") +end diff --git a/tiger-compiler/tests/type/lower_than_nil.tig b/tiger-compiler/tests/type/lower_than_nil.tig new file mode 100644 index 0000000..f53b0be --- /dev/null +++ b/tiger-compiler/tests/type/lower_than_nil.tig @@ -0,0 +1,20 @@ +let + type rec = { key : string, value : int } + var rec1 : rec := nil + var rec2 : rec := nil +in + if (rec1 < rec2) then + print("lower"); + + if (rec1 <= rec2) then + print("lower or equal"); + + if (rec1 = rec2) then + print("equal"); + + if (rec1 >= rec2) then + print("higher or equal"); + + if (rec1 > rec2) then + print("higher") +end diff --git a/tiger-compiler/tests/type/lower_than_record.tig b/tiger-compiler/tests/type/lower_than_record.tig new file mode 100644 index 0000000..883a56b --- /dev/null +++ b/tiger-compiler/tests/type/lower_than_record.tig @@ -0,0 +1,20 @@ +let + type rec = { key : string, value : int } + var rec1 := rec { key = "wow", value = 2 } + var rec2 := rec { key = "key", value = 3 } +in + if (rec1 < rec2) then + print("lower"); + + if (rec1 <= rec2) then + print("lower or equal"); + + if (rec1 = rec2) then + print("equal"); + + if (rec1 >= rec2) then + print("higher or equal"); + + if (rec1 > rec2) then + print("higher") +end diff --git a/tiger-compiler/tests/type/missing-arg.tig b/tiger-compiler/tests/type/missing-arg.tig new file mode 100644 index 0000000..979dcea --- /dev/null +++ b/tiger-compiler/tests/type/missing-arg.tig @@ -0,0 +1,6 @@ +/* error : formals are more then actuals */ +let + function g(a : int , b : string) : int = a +in + g("one") +end diff --git a/tiger-compiler/tests/type/nil-equals-nil.tig b/tiger-compiler/tests/type/nil-equals-nil.tig new file mode 100644 index 0000000..18732d1 --- /dev/null +++ b/tiger-compiler/tests/type/nil-equals-nil.tig @@ -0,0 +1,2 @@ +/* Cannot compare nil against itself */ +nil = nil diff --git a/tiger-compiler/tests/type/nil-string.tig b/tiger-compiler/tests/type/nil-string.tig new file mode 100644 index 0000000..c8d885e --- /dev/null +++ b/tiger-compiler/tests/type/nil-string.tig @@ -0,0 +1,7 @@ +/* error: string variable instantiated with nil */ + +let + var str: string := nil +in + print(str) +end diff --git a/tiger-compiler/tests/type/test09.tig b/tiger-compiler/tests/type/test09.tig new file mode 100644 index 0000000..64ff9f9 --- /dev/null +++ b/tiger-compiler/tests/type/test09.tig @@ -0,0 +1,3 @@ +/* error : types of then - else differ */ + +if (5>4) then 13 else " " diff --git a/tiger-compiler/tests/type/test10.tig b/tiger-compiler/tests/type/test10.tig new file mode 100644 index 0000000..2233079 --- /dev/null +++ b/tiger-compiler/tests/type/test10.tig @@ -0,0 +1,2 @@ +/* error : body of while not unit */ +while (10 > 5) do 5+6 diff --git a/tiger-compiler/tests/type/test11.tig b/tiger-compiler/tests/type/test11.tig new file mode 100644 index 0000000..6c84718 --- /dev/null +++ b/tiger-compiler/tests/type/test11.tig @@ -0,0 +1,3 @@ +/* error hi expr is not int. */ +for i := 10 to " " do + print("Tiger\n") diff --git a/tiger-compiler/tests/type/test13.tig b/tiger-compiler/tests/type/test13.tig new file mode 100644 index 0000000..29fcabc --- /dev/null +++ b/tiger-compiler/tests/type/test13.tig @@ -0,0 +1,3 @@ +/* error : comparison of incompatible types */ + +3 > "df" diff --git a/tiger-compiler/tests/type/test14.tig b/tiger-compiler/tests/type/test14.tig new file mode 100644 index 0000000..e1711a0 --- /dev/null +++ b/tiger-compiler/tests/type/test14.tig @@ -0,0 +1,13 @@ +/* error : compare rec with array */ + +let + + type arrtype = array of int + type rectype = {name : string, id : int} + + var rec := rectype {name="aname", id=0} + var arr := arrtype [3] of 0 + +in + if rec <> arr then 3 else 4 +end diff --git a/tiger-compiler/tests/type/test15.tig b/tiger-compiler/tests/type/test15.tig new file mode 100644 index 0000000..1af763e --- /dev/null +++ b/tiger-compiler/tests/type/test15.tig @@ -0,0 +1,3 @@ +/* error : if-then returns non unit */ + +if 20 then 3 diff --git a/tiger-compiler/tests/type/test21.tig b/tiger-compiler/tests/type/test21.tig new file mode 100644 index 0000000..5e466a3 --- /dev/null +++ b/tiger-compiler/tests/type/test21.tig @@ -0,0 +1,11 @@ +/* error : procedure returns value and procedure is used in arexpr */ +let + /* calculate n! */ + function nfactor(n : int) = + if n = 0 + then 1 + else n * nfactor(n-1) + +in + nfactor(10) +end diff --git a/tiger-compiler/tests/type/test22.tig b/tiger-compiler/tests/type/test22.tig new file mode 100644 index 0000000..899b586 --- /dev/null +++ b/tiger-compiler/tests/type/test22.tig @@ -0,0 +1,8 @@ +/* error : field not in record type */ + +let + type rectype = {name : string , id : int} + var rec1 := rectype {name="Name", id=0} +in + rec1.nam := "asd" +end diff --git a/tiger-compiler/tests/type/test23.tig b/tiger-compiler/tests/type/test23.tig new file mode 100644 index 0000000..2772067 --- /dev/null +++ b/tiger-compiler/tests/type/test23.tig @@ -0,0 +1,9 @@ +/* error : type mismatch */ + +let + type rectype = {name : string , id : int} + var rec1 := rectype {name="aname", id=0} +in + rec1.name := 3; + rec1.id := "" +end diff --git a/tiger-compiler/tests/type/test24.tig b/tiger-compiler/tests/type/test24.tig new file mode 100644 index 0000000..f9d0df5 --- /dev/null +++ b/tiger-compiler/tests/type/test24.tig @@ -0,0 +1,7 @@ +/* error : variable not array */ +let + var d :=0 +in + d[3] +end + diff --git a/tiger-compiler/tests/type/test26.tig b/tiger-compiler/tests/type/test26.tig new file mode 100644 index 0000000..bdd89fe --- /dev/null +++ b/tiger-compiler/tests/type/test26.tig @@ -0,0 +1,3 @@ +/* error : integer required */ + +3 + "var" diff --git a/tiger-compiler/tests/type/test28.tig b/tiger-compiler/tests/type/test28.tig new file mode 100644 index 0000000..9a52d8d --- /dev/null +++ b/tiger-compiler/tests/type/test28.tig @@ -0,0 +1,10 @@ +/* error : different record types */ + +let + type rectype1 = {name : string , id : int} + type rectype2 = {name : string , id : int} + + var rec1 : rectype1 := rectype2 {name="Name", id=0} +in + rec1 +end diff --git a/tiger-compiler/tests/type/test29.tig b/tiger-compiler/tests/type/test29.tig new file mode 100644 index 0000000..d47b966 --- /dev/null +++ b/tiger-compiler/tests/type/test29.tig @@ -0,0 +1,10 @@ +/* error : different array types */ + +let + type arrtype1 = array of int + type arrtype2 = array of int + + var arr1 : arrtype1 := arrtype2 [10] of 0 +in + arr1 +end diff --git a/tiger-compiler/tests/type/test31.tig b/tiger-compiler/tests/type/test31.tig new file mode 100644 index 0000000..1720610 --- /dev/null +++ b/tiger-compiler/tests/type/test31.tig @@ -0,0 +1,6 @@ +/* error : type constraint and init value differ */ +let + var a : int := " " +in + a +end diff --git a/tiger-compiler/tests/type/test32.tig b/tiger-compiler/tests/type/test32.tig new file mode 100644 index 0000000..cf9e854 --- /dev/null +++ b/tiger-compiler/tests/type/test32.tig @@ -0,0 +1,9 @@ +/* error : initializing exp and array type differ */ + +let + type arrayty = array of int + + var a := arrayty [10] of " " +in + 0 +end diff --git a/tiger-compiler/tests/type/test40.tig b/tiger-compiler/tests/type/test40.tig new file mode 100644 index 0000000..1765158 --- /dev/null +++ b/tiger-compiler/tests/type/test40.tig @@ -0,0 +1,7 @@ +/* error : procedure returns value */ +let + function g(a : int) = a +in + g(2) +end + diff --git a/tiger-compiler/tests/type/test43.tig b/tiger-compiler/tests/type/test43.tig new file mode 100644 index 0000000..d1dadc7 --- /dev/null +++ b/tiger-compiler/tests/type/test43.tig @@ -0,0 +1,7 @@ +/* error: initialize with unit and causing type mismatch in addition */ + +let + var a := () +in + a + 3 +end diff --git a/tiger-compiler/tests/type/too-many-args.tig b/tiger-compiler/tests/type/too-many-args.tig new file mode 100644 index 0000000..839575d --- /dev/null +++ b/tiger-compiler/tests/type/too-many-args.tig @@ -0,0 +1,6 @@ +/* error : formals are fewer then actuals */ +let + function g(a : int , b : string) : int = a +in + g(3,"one",5) +end diff --git a/tiger-compiler/tests/type/types-endless-recursion.tig b/tiger-compiler/tests/type/types-endless-recursion.tig new file mode 100644 index 0000000..ab51a94 --- /dev/null +++ b/tiger-compiler/tests/type/types-endless-recursion.tig @@ -0,0 +1,11 @@ +/* error : mutually recursive types that do not pass through record or array */ +let + +type a=c +type b=a +type c=d +type d=a + +in + "" +end diff --git a/tiger-compiler/tests/type/unconstrained-nil.tig b/tiger-compiler/tests/type/unconstrained-nil.tig new file mode 100644 index 0000000..eb0de8d --- /dev/null +++ b/tiger-compiler/tests/type/unconstrained-nil.tig @@ -0,0 +1,5 @@ +/* error : initializing nil expressions not constrained by record type */ +let var a := nil +in + 0 +end diff --git a/tiger-compiler/tests/type/wrong-print-invalid-type.tig b/tiger-compiler/tests/type/wrong-print-invalid-type.tig new file mode 100644 index 0000000..21fef12 --- /dev/null +++ b/tiger-compiler/tests/type/wrong-print-invalid-type.tig @@ -0,0 +1,2 @@ +/* Invalid argument type (int vs string) */ +print(1) diff --git a/tiger-compiler/tests/type/wrong-print-too-many-args.tig b/tiger-compiler/tests/type/wrong-print-too-many-args.tig new file mode 100644 index 0000000..c16a2f2 --- /dev/null +++ b/tiger-compiler/tests/type/wrong-print-too-many-args.tig @@ -0,0 +1,2 @@ +/* Too many arguments */ +print("a", "b", "c") diff --git a/tiger-compiler/tests/unit/ast/local.am b/tiger-compiler/tests/unit/ast/local.am new file mode 100644 index 0000000..6f01dc2 --- /dev/null +++ b/tiger-compiler/tests/unit/ast/local.am @@ -0,0 +1 @@ +check_unit_SOURCES += %D%/test_hello.cc diff --git a/tiger-compiler/tests/unit/ast/test_hello.cc b/tiger-compiler/tests/unit/ast/test_hello.cc new file mode 100644 index 0000000..b52d5ac --- /dev/null +++ b/tiger-compiler/tests/unit/ast/test_hello.cc @@ -0,0 +1,6 @@ +#include <criterion/criterion.h> + +Test(ast, hello) +{ + 1; +} diff --git a/tiger-compiler/tests/unit/local.am b/tiger-compiler/tests/unit/local.am new file mode 100644 index 0000000..f5e4165 --- /dev/null +++ b/tiger-compiler/tests/unit/local.am @@ -0,0 +1,4 @@ +include %D%/ast/local.am +include %D%/misc/local.am +include %D%/parse/local.am +include %D%/tasks/local.am diff --git a/tiger-compiler/tests/unit/misc/local.am b/tiger-compiler/tests/unit/misc/local.am new file mode 100644 index 0000000..db96069 --- /dev/null +++ b/tiger-compiler/tests/unit/misc/local.am @@ -0,0 +1,5 @@ +include %D%/unique/local.am +include %D%/symbol/local.am +include %D%/variant/local.am + +check_unit_SOURCES += %D%/test_hello.cc diff --git a/tiger-compiler/tests/unit/misc/symbol/local.am b/tiger-compiler/tests/unit/misc/symbol/local.am new file mode 100644 index 0000000..fbc4825 --- /dev/null +++ b/tiger-compiler/tests/unit/misc/symbol/local.am @@ -0,0 +1,2 @@ +check_unit_SOURCES += \ + %D%/test_symbol_simple.cc diff --git a/tiger-compiler/tests/unit/misc/symbol/test_symbol_simple.cc b/tiger-compiler/tests/unit/misc/symbol/test_symbol_simple.cc new file mode 100644 index 0000000..a49ed27 --- /dev/null +++ b/tiger-compiler/tests/unit/misc/symbol/test_symbol_simple.cc @@ -0,0 +1,21 @@ +#include <criterion/criterion.h> +#include <criterion/assert.h> +#include <misc/symbol.hh> + +Test(test_symbol, simple) +{ + const misc::symbol toto1("toto"); + const misc::symbol toto2("toto"); + const misc::symbol titi1("titi"); + + cr_expect_eq(toto1, "toto"); + cr_expect_neq(toto1, "titi"); + + cr_expect_eq(toto1, toto2); + cr_expect_neq(toto1, titi1); + + std::string junk = "tata"; + const misc::symbol tata1(junk); + junk = "toto"; + cr_expect_eq(tata1, "tata"); +} diff --git a/tiger-compiler/tests/unit/misc/test_hello.cc b/tiger-compiler/tests/unit/misc/test_hello.cc new file mode 100644 index 0000000..e18e1d8 --- /dev/null +++ b/tiger-compiler/tests/unit/misc/test_hello.cc @@ -0,0 +1,6 @@ +#include <criterion/criterion.h> + +Test(misc, hello) +{ + 1; +} diff --git a/tiger-compiler/tests/unit/misc/unique/local.am b/tiger-compiler/tests/unit/misc/unique/local.am new file mode 100644 index 0000000..9911c25 --- /dev/null +++ b/tiger-compiler/tests/unit/misc/unique/local.am @@ -0,0 +1,4 @@ +check_unit_SOURCES += \ + %D%/test_unique_int.cc \ + %D%/test_unique_char.cc \ + %D%/test_unique_string.cc diff --git a/tiger-compiler/tests/unit/misc/unique/test_unique_char.cc b/tiger-compiler/tests/unit/misc/unique/test_unique_char.cc new file mode 100644 index 0000000..d69b42c --- /dev/null +++ b/tiger-compiler/tests/unit/misc/unique/test_unique_char.cc @@ -0,0 +1,18 @@ +#include <criterion/criterion.h> +#include <criterion/assert.h> +#include <misc/unique.hh> + +Test(unique_char, simple) +{ + misc::unique<char> the_answer = 'a'; + misc::unique<char> the_same_answer = 'a'; + misc::unique<char> the_solution = 'b'; + + cr_expect_eq(the_answer, misc::unique<char>('a')); + cr_expect_eq(the_answer, the_same_answer); + cr_expect_neq(the_answer, the_solution); + + cr_expect_eq(the_answer.get(), the_same_answer.get()); + cr_expect_eq(the_answer.get(), misc::unique<char>('a').get()); + cr_expect_neq(the_answer.get(), the_solution.get()); +} diff --git a/tiger-compiler/tests/unit/misc/unique/test_unique_int.cc b/tiger-compiler/tests/unit/misc/unique/test_unique_int.cc new file mode 100644 index 0000000..f25c3c2 --- /dev/null +++ b/tiger-compiler/tests/unit/misc/unique/test_unique_int.cc @@ -0,0 +1,18 @@ +#include <criterion/criterion.h> +#include <criterion/assert.h> +#include <misc/unique.hh> + +Test(unique_int, simple) +{ + misc::unique<int> the_answer = 42; + misc::unique<int> the_same_answer = 42; + misc::unique<int> the_solution = 51; + + cr_expect_eq(the_answer, misc::unique<int>(42)); + cr_expect_eq(the_answer, the_same_answer); + cr_expect_neq(the_answer, the_solution); + + cr_expect_eq(the_answer.get(), the_same_answer.get()); + cr_expect_eq(the_answer.get(), misc::unique<int>(42).get()); + cr_expect_neq(the_answer.get(), the_solution.get()); +} diff --git a/tiger-compiler/tests/unit/misc/unique/test_unique_string.cc b/tiger-compiler/tests/unit/misc/unique/test_unique_string.cc new file mode 100644 index 0000000..2542375 --- /dev/null +++ b/tiger-compiler/tests/unit/misc/unique/test_unique_string.cc @@ -0,0 +1,19 @@ +#include <criterion/criterion.h> +#include <criterion/assert.h> +#include <misc/unique.hh> +#include <string> + +Test(unique_string, simple) +{ + misc::unique<std::string> the_answer = std::string("skibidi"); + misc::unique<std::string> the_same_answer = std::string("skibidi"); + misc::unique<std::string> the_solution = std::string("yes yes"); + + cr_expect_eq(the_answer, misc::unique<std::string>(std::string("skibidi"))); + cr_expect_eq(the_answer, the_same_answer); + cr_expect_neq(the_answer, the_solution); + + cr_expect_eq(the_answer.get(), the_same_answer.get()); + cr_expect_eq(the_answer.get(), misc::unique<std::string>(std::string("skibidi")).get()); + cr_expect_neq(the_answer.get(), the_solution.get()); +} diff --git a/tiger-compiler/tests/unit/misc/variant/local.am b/tiger-compiler/tests/unit/misc/variant/local.am new file mode 100644 index 0000000..f09d993 --- /dev/null +++ b/tiger-compiler/tests/unit/misc/variant/local.am @@ -0,0 +1,3 @@ +check_unit_SOURCES += \ + %D%/test_variant_two_types.cc \ + %D%/test_variant_three_types.cc diff --git a/tiger-compiler/tests/unit/misc/variant/test_variant_three_types.cc b/tiger-compiler/tests/unit/misc/variant/test_variant_three_types.cc new file mode 100644 index 0000000..8728059 --- /dev/null +++ b/tiger-compiler/tests/unit/misc/variant/test_variant_three_types.cc @@ -0,0 +1,35 @@ +#include <criterion/criterion.h> +#include <criterion/assert.h> +#include <misc/variant.hh> + +using multiple_variant_type = misc::variant<int, std::string, double>; + +Test(variant_three_types, simple_success_type_a) +{ + multiple_variant_type v("Hello"); + std::string s = v; + cr_expect_str_eq(s.c_str(), "Hello"); +} + +Test(variant_three_types, simple_success_type_b) +{ + multiple_variant_type v(56.7); + double d = v; + cr_expect_eq(d, 56.7); +} + +Test(variant_three_types, simple_failure_type_c) +{ + multiple_variant_type v(34.5); + + try + { + [[maybe_unused]] int i = v; + } + catch (const std::bad_variant_access& e) + { + return; + } + + cr_expect_eq(1, 0, "copy assignment did not throw an exception"); +} diff --git a/tiger-compiler/tests/unit/misc/variant/test_variant_two_types.cc b/tiger-compiler/tests/unit/misc/variant/test_variant_two_types.cc new file mode 100644 index 0000000..9a63d6a --- /dev/null +++ b/tiger-compiler/tests/unit/misc/variant/test_variant_two_types.cc @@ -0,0 +1,28 @@ +#include <criterion/criterion.h> +#include <criterion/assert.h> +#include <misc/variant.hh> + +using variant_type = misc::variant<int, std::string>; + +Test(variant_two_types, simple_success) +{ + misc::variant<int, std::string> v("Hello"); + std::string s = v; + cr_expect_str_eq(s.c_str(), "Hello"); +} + +Test(variant_two_types, simple_failure) +{ + variant_type v(42); + + try + { + std::string s = v; + } + catch (const std::bad_variant_access& e) + { + return; + } + + cr_expect_eq(1, 0, "copy assignment did not throw an exception"); +} diff --git a/tiger-compiler/tests/unit/parse/local.am b/tiger-compiler/tests/unit/parse/local.am new file mode 100644 index 0000000..2c9f827 --- /dev/null +++ b/tiger-compiler/tests/unit/parse/local.am @@ -0,0 +1,4 @@ +include %D%/tiger_driver/local.am +include %D%/tiger_factory/local.am + +check_unit_SOURCES += %D%/test_hello.cc diff --git a/tiger-compiler/tests/unit/parse/test_hello.cc b/tiger-compiler/tests/unit/parse/test_hello.cc new file mode 100644 index 0000000..5828ca2 --- /dev/null +++ b/tiger-compiler/tests/unit/parse/test_hello.cc @@ -0,0 +1,36 @@ +#include <ast/exp.hh> +#include <ast/libast.hh> +#include <criterion/criterion.h> +#include <criterion/assert.h> +#include <parse/libparse.hh> +#include <ast/fwd.hh> +#include <ast/pretty-printer.hh> + +Test(Basic, SimpleBody) +{ + std::cout << "----- basicTests -----"; + ast::PrettyPrinter print(std::cout); + ast::Exp* boiiiiiii = parse::parse("let " + " var i := 3 " + " in " + " i + 1 " + " end"); + cr_assert_not_null(boiiiiiii); + print(boiiiiiii); + cr_assert_eq(1, 1); +} + +Test(Basic, ChunkList) +{ + ast::PrettyPrinter print(std::cout); + ast::Exp* test = parse::parse("let " + " var i := 1 " + " var j := 2 " + " var k := 3 " + " in " + " i + j + k " + " end"); + cr_assert_not_null(test); + print(test); + cr_assert_eq(1, 1); +} diff --git a/tiger-compiler/tests/unit/parse/tiger_driver/local.am b/tiger-compiler/tests/unit/parse/tiger_driver/local.am new file mode 100644 index 0000000..bd58ff7 --- /dev/null +++ b/tiger-compiler/tests/unit/parse/tiger_driver/local.am @@ -0,0 +1,2 @@ +check_unit_SOURCES += \ + %D%/test_parse_no_check.cc diff --git a/tiger-compiler/tests/unit/parse/tiger_driver/test_parse_no_check.cc b/tiger-compiler/tests/unit/parse/tiger_driver/test_parse_no_check.cc new file mode 100644 index 0000000..81ebea2 --- /dev/null +++ b/tiger-compiler/tests/unit/parse/tiger_driver/test_parse_no_check.cc @@ -0,0 +1,19 @@ +#include <ast/exp.hh> +#include <ast/libast.hh> +#include <criterion/criterion.h> +#include <criterion/assert.h> +#include <parse/libparse.hh> + +Test(parse_no_check, simple) +{ + ast::Exp* e = parse::parse("a + b"); +} + +Test(parse_no_check, let_function) +{ + parse::parse("let" + "function f(a : int, b : string) : int = a" + "in" + "a" + "end"); +} diff --git a/tiger-compiler/tests/unit/parse/tiger_factory/define_test_location.cc b/tiger-compiler/tests/unit/parse/tiger_factory/define_test_location.cc new file mode 100644 index 0000000..71fd96b --- /dev/null +++ b/tiger-compiler/tests/unit/parse/tiger_factory/define_test_location.cc @@ -0,0 +1,5 @@ +#include "define_test_location.hh" + +#include <parse/tiger-factory.hh> + +parse::location test_l; diff --git a/tiger-compiler/tests/unit/parse/tiger_factory/define_test_location.hh b/tiger-compiler/tests/unit/parse/tiger_factory/define_test_location.hh new file mode 100644 index 0000000..f29ddae --- /dev/null +++ b/tiger-compiler/tests/unit/parse/tiger_factory/define_test_location.hh @@ -0,0 +1,5 @@ +#pragma once + +#include <parse/tiger-factory.hh> + +extern parse::location test_l; diff --git a/tiger-compiler/tests/unit/parse/tiger_factory/local.am b/tiger-compiler/tests/unit/parse/tiger_factory/local.am new file mode 100644 index 0000000..3c4bd9d --- /dev/null +++ b/tiger-compiler/tests/unit/parse/tiger_factory/local.am @@ -0,0 +1,12 @@ +check_unit_SOURCES += \ + %D%/define_test_location.cc \ + %D%/test_make_array_exp.cc \ + %D%/test_make_break_exp.cc \ + %D%/test_make_call_exp.cc \ + %D%/test_make_field_var.cc \ + %D%/test_make_if_exp.cc \ + %D%/test_make_int_exp.cc \ + %D%/test_make_let_exp.cc \ + %D%/test_make_object_exp.cc \ + %D%/test_make_record_ty.cc \ + %D%/test_make_string_exp.cc diff --git a/tiger-compiler/tests/unit/parse/tiger_factory/test_make_array_exp.cc b/tiger-compiler/tests/unit/parse/tiger_factory/test_make_array_exp.cc new file mode 100644 index 0000000..949f92e --- /dev/null +++ b/tiger-compiler/tests/unit/parse/tiger_factory/test_make_array_exp.cc @@ -0,0 +1,30 @@ +#include <ast/exp.hh> +#include <ast/libast.hh> +#include <criterion/criterion.h> +#include <criterion/assert.h> +#include <parse/libparse.hh> +#include <ast/fwd.hh> +#include <ast/pretty-printer.hh> + +TestSuite(BasicArr); + +Test(BasicArr, MakeArray) +{ + std::cout << "----- MakeArray -----"; + ast::PrettyPrinter print(std::cout); + ast::Exp* test = parse::parse("stuff[5] of 3"); + cr_assert_not_null(test); + print(test); + cr_assert_eq(1, 1); +} + +TestSuite(ExprsArr); + +Test(ExprsArr, MakeArray_WExprs) +{ + ast::PrettyPrinter print(std::cout); + ast::Exp* test = parse::parse("stuff[(36+6)] of \"Tiggered\""); + cr_assert_not_null(test); + print(test); + cr_assert_eq(1, 1); +}
\ No newline at end of file diff --git a/tiger-compiler/tests/unit/parse/tiger_factory/test_make_break_exp.cc b/tiger-compiler/tests/unit/parse/tiger_factory/test_make_break_exp.cc new file mode 100644 index 0000000..02fb390 --- /dev/null +++ b/tiger-compiler/tests/unit/parse/tiger_factory/test_make_break_exp.cc @@ -0,0 +1,30 @@ +#include <ast/exp.hh> +#include <ast/libast.hh> +#include <criterion/criterion.h> +#include <criterion/assert.h> +#include <parse/libparse.hh> +#include <ast/fwd.hh> +#include <ast/pretty-printer.hh> + +TestSuite(BasicBrk); + +Test(BasicBrk, MakeBreak) +{ + std::cout << "----- Break -----"; + ast::PrettyPrinter print(std::cout); + ast::Exp* test = parse::parse("while (a < 5) do break"); + cr_assert_not_null(test); + print(test); + cr_assert_eq(1, 1); +} + +TestSuite(RealisticBrk); + +Test(RealisticBrk, MakeBetterBreak) +{ + ast::PrettyPrinter print(std::cout); + ast::Exp* test = parse::parse("while (a < 5) do (a := a + 1; break)"); + cr_assert_not_null(test); + print(test); + cr_assert_eq(1, 1); +}
\ No newline at end of file diff --git a/tiger-compiler/tests/unit/parse/tiger_factory/test_make_call_exp.cc b/tiger-compiler/tests/unit/parse/tiger_factory/test_make_call_exp.cc new file mode 100644 index 0000000..5c4b9bb --- /dev/null +++ b/tiger-compiler/tests/unit/parse/tiger_factory/test_make_call_exp.cc @@ -0,0 +1,41 @@ +#include <ast/exp.hh> +#include <ast/libast.hh> +#include <criterion/criterion.h> +#include <criterion/assert.h> +#include <parse/libparse.hh> +#include <ast/fwd.hh> +#include <ast/pretty-printer.hh> + +TestSuite(BasicCall); + +Test(BasicCall, SimpleCall) +{ + std::cout << "----- FunCall -----"; + ast::PrettyPrinter print(std::cout); + ast::Exp* test = parse::parse("let " + " function test(a : int, b : string) : int = " + " a " + " in " + " test(1, \"2M, 22H->H, f.L, RS, RC, 55M, 632146M\") " + " end \n"); + cr_assert_not_null(test); + print(test); + cr_assert_eq(1, 1); +} + +TestSuite(RealisticCall); + +Test(RealisticCall, Call_WExprs) +{ + ast::PrettyPrinter print(std::cout); + // If someone get this and sends me a video proof, you have my utmost respect (the sequence in itself is not that hard tbh) + ast::Exp* test = parse::parse("let " + " function test(a : int, b : string) : int = " + " a " + " in " + " test(1 + 2 + c + inexistant, \"2M, 22H->H, f.L, RS, RC, 55M, 632146M\")" + " end \n"); + cr_assert_not_null(test); + print(test); + cr_assert_eq(1, 1); +} diff --git a/tiger-compiler/tests/unit/parse/tiger_factory/test_make_field_var.cc b/tiger-compiler/tests/unit/parse/tiger_factory/test_make_field_var.cc new file mode 100644 index 0000000..1d85afa --- /dev/null +++ b/tiger-compiler/tests/unit/parse/tiger_factory/test_make_field_var.cc @@ -0,0 +1,30 @@ +#include <ast/exp.hh> +#include <ast/libast.hh> +#include <criterion/criterion.h> +#include <criterion/assert.h> +#include <parse/libparse.hh> +#include <ast/fwd.hh> +#include <ast/pretty-printer.hh> + +TestSuite(BasicVar); + +Test(BasicVar, SimpleVar) +{ + std::cout << "----- BaseVars -----"; + ast::PrettyPrinter print(std::cout); + ast::Exp* test = parse::parse("var test := \"Code harder, not smarter\""); + cr_assert_not_null(test); + print(test); + cr_assert_eq(1, 1); +} + +TestSuite(RealisticVar); + +Test(RealisticVar, Var_WExprs) +{ + ast::PrettyPrinter print(std::cout); + ast::Exp* test = parse::parse("var test : int := 3 + 6 + 9"); + cr_assert_not_null(test); + print(test); + cr_assert_eq(1, 1); +}
\ No newline at end of file diff --git a/tiger-compiler/tests/unit/parse/tiger_factory/test_make_if_exp.cc b/tiger-compiler/tests/unit/parse/tiger_factory/test_make_if_exp.cc new file mode 100644 index 0000000..d324591 --- /dev/null +++ b/tiger-compiler/tests/unit/parse/tiger_factory/test_make_if_exp.cc @@ -0,0 +1,48 @@ +#include <ast/exp.hh> +#include <ast/libast.hh> +#include <criterion/criterion.h> +#include <criterion/assert.h> +#include <parse/libparse.hh> +#include <ast/fwd.hh> +#include <ast/pretty-printer.hh> + +TestSuite(BasicIf); + +Test(BasicIf, OnlyIf) +{ + std::cout << "----- IfLoops -----"; + ast::PrettyPrinter print(std::cout); + ast::Exp* test = parse::parse("if a > 5 then a"); + cr_assert_not_null(test); + print(test); + cr_assert_eq(1, 1); +} + +TestSuite(RealisticIf); + +Test(RealisticIf, IfElse) +{ + ast::PrettyPrinter print(std::cout); + ast::Exp* test = parse::parse("if a > 5 then a else b"); + cr_assert_not_null(test); + print(test); + cr_assert_eq(1, 1); +} + +Test(RealisticIf, IfsElses) +{ + ast::PrettyPrinter print(std::cout); + ast::Exp* test = parse::parse("if a > 5 then a else if a < 0 then b else c"); + cr_assert_not_null(test); + print(test); + cr_assert_eq(1, 1); +} + +Test(RealisticIf, DanglingElse) +{ + ast::PrettyPrinter print(std::cout); + ast::Exp* test = parse::parse("if a > 5 then if a < 0 then b else c else d"); + cr_assert_not_null(test); + print(test); + cr_assert_eq(1, 1); +}
\ No newline at end of file diff --git a/tiger-compiler/tests/unit/parse/tiger_factory/test_make_int_exp.cc b/tiger-compiler/tests/unit/parse/tiger_factory/test_make_int_exp.cc new file mode 100644 index 0000000..01a5f97 --- /dev/null +++ b/tiger-compiler/tests/unit/parse/tiger_factory/test_make_int_exp.cc @@ -0,0 +1,38 @@ +#include <ast/exp.hh> +#include <ast/libast.hh> +#include <criterion/criterion.h> +#include <criterion/assert.h> +#include <parse/libparse.hh> +#include <ast/fwd.hh> +#include <ast/pretty-printer.hh> + +TestSuite(BasicInt); + +Test(BasicInt, SimpleVal) +{ + std::cout << "----- MakeInt -----"; + ast::PrettyPrinter print(std::cout); + ast::Exp* test = parse::parse("215"); + cr_assert_not_null(test); + print(test); + cr_assert_eq(1, 1); +} + +Test(BasicInt, SimpleUnaryVal) +{ + ast::PrettyPrinter print(std::cout); + ast::Exp* test = parse::parse("-215"); + cr_assert_not_null(test); + print(test); + cr_assert_eq(1, 1); +} + +TestSuite(RealisticInt); + +Test(RealisticInt, Exception) +{ + ast::PrettyPrinter print(std::cout); + ast::Exp* test = parse::parse("2147483648"); + cr_assert_null(test); + cr_assert_eq(1, 1); +}
\ No newline at end of file diff --git a/tiger-compiler/tests/unit/parse/tiger_factory/test_make_let_exp.cc b/tiger-compiler/tests/unit/parse/tiger_factory/test_make_let_exp.cc new file mode 100644 index 0000000..b88bd76 --- /dev/null +++ b/tiger-compiler/tests/unit/parse/tiger_factory/test_make_let_exp.cc @@ -0,0 +1,30 @@ +#include <ast/exp.hh> +#include <ast/libast.hh> +#include <criterion/criterion.h> +#include <criterion/assert.h> +#include <parse/libparse.hh> +#include <ast/fwd.hh> +#include <ast/pretty-printer.hh> + +TestSuite(BasicLet); + +Test(BasicLet, SimpleLet) +{ + std::cout << "----- SimpleLet -----"; + ast::PrettyPrinter print(std::cout); + ast::Exp* test = parse::parse("let function test(a : int) : int = a in end"); + cr_assert_not_null(test); + print(test); + cr_assert_eq(1, 1); +} + +TestSuite(RealisticLet); + +Test(RealisticLet, StuffedLet) +{ + ast::PrettyPrinter print(std::cout); + ast::Exp* test = parse::parse("let function test(a : int) : int = a var b := 84 type badaboum = array of int in test(b) end"); + cr_assert_not_null(test); + print(test); + cr_assert_eq(1, 1); +}
\ No newline at end of file diff --git a/tiger-compiler/tests/unit/parse/tiger_factory/test_make_object_exp.cc b/tiger-compiler/tests/unit/parse/tiger_factory/test_make_object_exp.cc new file mode 100644 index 0000000..f80dc75 --- /dev/null +++ b/tiger-compiler/tests/unit/parse/tiger_factory/test_make_object_exp.cc @@ -0,0 +1,19 @@ +#include <ast/exp.hh> +#include <ast/libast.hh> +#include <criterion/criterion.h> +#include <criterion/assert.h> +#include <parse/libparse.hh> +#include <ast/fwd.hh> +#include <ast/pretty-printer.hh> + +Test(make_object_exp, simple) +{ + std::cout << "----- SimpleObject -----"; + ast::PrettyPrinter print(std::cout); + ast::Exp* test = parse::parse("class test extends bobby { " + " var field := 5 " + " method maths(a : int) : int = a }", true); + cr_assert_not_null(test); + print(test); + cr_assert_eq(1, 1); +}
\ No newline at end of file diff --git a/tiger-compiler/tests/unit/parse/tiger_factory/test_make_record_exp.cc b/tiger-compiler/tests/unit/parse/tiger_factory/test_make_record_exp.cc new file mode 100644 index 0000000..7ffc23a --- /dev/null +++ b/tiger-compiler/tests/unit/parse/tiger_factory/test_make_record_exp.cc @@ -0,0 +1,30 @@ +#include <ast/exp.hh> +#include <ast/libast.hh> +#include <criterion/criterion.h> +#include <criterion/assert.h> +#include <parse/libparse.hh> +#include <ast/fwd.hh> +#include <ast/pretty-printer.hh> + +TestSuite(BasicRec); + +Test(BasicRec, SimpleRec) +{ + std::cout << "----- BaseRec -----"; + ast::PrettyPrinter print(std::cout); + ast::Exp* test = parse::parse("pair = {value : int, key : string}"); + cr_assert_not_null(test); + print(test); + cr_assert_eq(1, 1); +} + +TestSuite(RealisticRec); + +Test(RealisticRec, RecRec) +{ + ast::PrettyPrinter print(std::cout); + ast::Exp* test = parse::parse("node = {value : int, next : node}"); + cr_assert_not_null(test); + print(test); + cr_assert_eq(1, 1); +}
\ No newline at end of file diff --git a/tiger-compiler/tests/unit/parse/tiger_factory/test_make_record_ty.cc b/tiger-compiler/tests/unit/parse/tiger_factory/test_make_record_ty.cc new file mode 100644 index 0000000..fcea129 --- /dev/null +++ b/tiger-compiler/tests/unit/parse/tiger_factory/test_make_record_ty.cc @@ -0,0 +1,30 @@ +#include <ast/exp.hh> +#include <ast/libast.hh> +#include <criterion/criterion.h> +#include <criterion/assert.h> +#include <parse/libparse.hh> +#include <ast/fwd.hh> +#include <ast/pretty-printer.hh> + +TestSuite(BasicRecTy); + +Test(BasicRecTy, SimpleTy) +{ + std::cout << "----- BaseTyRec -----"; + ast::PrettyPrinter print(std::cout); + ast::Exp* test = parse::parse("type pair = {value : int, key : string}"); + cr_assert_not_null(test); + print(test); + cr_assert_eq(1, 1); +} + +TestSuite(RealisticRecTy); + +Test(RealisticRecTy, RecTy) +{ + ast::PrettyPrinter print(std::cout); + ast::Exp* test = parse::parse("type node = {value : int, next : node}"); + cr_assert_not_null(test); + print(test); + cr_assert_eq(1, 1); +}
\ No newline at end of file diff --git a/tiger-compiler/tests/unit/parse/tiger_factory/test_make_string_exp.cc b/tiger-compiler/tests/unit/parse/tiger_factory/test_make_string_exp.cc new file mode 100644 index 0000000..2b898b0 --- /dev/null +++ b/tiger-compiler/tests/unit/parse/tiger_factory/test_make_string_exp.cc @@ -0,0 +1,30 @@ +#include <ast/exp.hh> +#include <ast/libast.hh> +#include <criterion/criterion.h> +#include <criterion/assert.h> +#include <parse/libparse.hh> +#include <ast/fwd.hh> +#include <ast/pretty-printer.hh> + +TestSuite(BasicStr); + +Test(BasicStr, SimpleStr) +{ + std::cout << "----- BaseTyRec -----"; + ast::PrettyPrinter print(std::cout); + ast::Exp* test = parse::parse("Screw gravity!"); + cr_assert_not_null(test); + print(test); + cr_assert_eq(1, 1); +} + +TestSuite(RealisticStr); + +Test(RealisticStr, Escapes) +{ + ast::PrettyPrinter print(std::cout); + ast::Exp* test = parse::parse("Something's wrong \\\"\n, I can feel it...\r"); + cr_assert_not_null(test); + print(test); + cr_assert_eq(1, 1); +}
\ No newline at end of file diff --git a/tiger-compiler/tests/unit/tasks/bind/local.am b/tiger-compiler/tests/unit/tasks/bind/local.am new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tiger-compiler/tests/unit/tasks/bind/local.am diff --git a/tiger-compiler/tests/unit/tasks/local.am b/tiger-compiler/tests/unit/tasks/local.am new file mode 100644 index 0000000..eca6000 --- /dev/null +++ b/tiger-compiler/tests/unit/tasks/local.am @@ -0,0 +1 @@ +include %D%/bind/local.am |
