diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-03-05 19:07:13 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-03-05 19:07:13 +0100 |
| commit | 2570830850c6dadadc2c86bf9d6f3203c9aba488 (patch) | |
| tree | f6d00459337da26261c16e39cb4241be6441bfb4 | |
| parent | 9d0a930d811b825b39ee16614e645b6934130cc1 (diff) | |
| download | sylt-2570830850c6dadadc2c86bf9d6f3203c9aba488.tar.gz | |
convert tests to files
72 files changed, 599 insertions, 619 deletions
diff --git a/progs/bench/fib.sy b/progs/bench/fib.sy index de68f5c..76c3af7 100644 --- a/progs/bench/fib.sy +++ b/progs/bench/fib.sy @@ -7,4 +7,8 @@ fib :: fn a:int -> int { ret fib(a - 1) + fib(a - 2) } // 23 is around where things start getting slow. -fib(23) <=> 28657 +start :: fn { + //TODO pass arguments to skip debug printing. this test is very slow otherwise + <!> + // fib(23) <=> 28657 +} diff --git a/progs/bench/fib_iter.sy b/progs/bench/fib_iter.sy index c51469a..f82d6f8 100644 --- a/progs/bench/fib_iter.sy +++ b/progs/bench/fib_iter.sy @@ -1,14 +1,17 @@ // A Fibonacci implementation that is a little // less awful. But we run it 1000 times instead. -j := 0 -for , j < 1000, j = j + 1 { - a := 0 - b := 1 +start :: fn { + <!> + j := 0 + for , j < 1000, j = j + 1 { + a := 0 + b := 1 - for i := 0, i < 50, i = i + 1 { - c := a - a = b - b = c + b + for i := 0, i < 50, i = i + 1 { + c := a + a = b + b = c + b + } + a <=> 12586269025 } - a <=> 12586269025 } diff --git a/progs/bench/sum.sy b/progs/bench/sum.sy index bb6870f..39252cd 100644 --- a/progs/bench/sum.sy +++ b/progs/bench/sum.sy @@ -1,6 +1,9 @@ -// Adds the numbers 0 to 10000 -sum := 0 -for i := 0, i <= 100000, i += 1 { - sum += i +// Adds the numbers 0 to 100000 +start :: fn { + <!> + sum := 0 + for i := 0, i <= 100000, i += 1 { + sum += i + } + sum <=> 5000050000 } -sum <=> 5000050000 diff --git a/progs/tests/simple.sy b/progs/tests/_simple.sy index 84bc86d..84bc86d 100644 --- a/progs/tests/simple.sy +++ b/progs/tests/_simple.sy diff --git a/progs/tests/auto/add.sy b/progs/tests/auto/add.sy new file mode 100644 index 0000000..4e8e643 --- /dev/null +++ b/progs/tests/auto/add.sy @@ -0,0 +1,3 @@ +start :: fn { +(1, 2, 3, 4) + (4, 3, 2, 1) <=> (5, 5, 5, 5) +} diff --git a/progs/tests/auto/advanced_break.sy b/progs/tests/auto/advanced_break.sy new file mode 100644 index 0000000..1cfcece --- /dev/null +++ b/progs/tests/auto/advanced_break.sy @@ -0,0 +1,22 @@ +start :: fn { + +a := 0 +for i := 0, i < 10, i += 1 { + q := 0 + qq := 0 + qqq := 0 + qqqq := 0 + + a = a + 1 + if i == 2 { + break + } + + q + qq + qqq + qqqq +} +a <=> 3 + +} diff --git a/progs/tests/auto/advanced_continue.sy b/progs/tests/auto/advanced_continue.sy new file mode 100644 index 0000000..70a8671 --- /dev/null +++ b/progs/tests/auto/advanced_continue.sy @@ -0,0 +1,22 @@ +start :: fn { + +a := 0 +for i := 0, i < 4, i += 1 { + q := 0 + qq := 0 + qqq := 0 + qqqq := 0 + + if i == 2 { + continue + } + a = a + 1 + + q + qq + qqq + qqqq +} +a <=> 3 + +} diff --git a/progs/tests/auto/assignment.sy b/progs/tests/auto/assignment.sy new file mode 100644 index 0000000..51cbecc --- /dev/null +++ b/progs/tests/auto/assignment.sy @@ -0,0 +1,7 @@ +start :: fn { +a := 1 + b := 2 + a = b + a <=> 2 + b <=> 2 +} diff --git a/progs/tests/auto/blob_complex.sy b/progs/tests/auto/blob_complex.sy new file mode 100644 index 0000000..d40082f --- /dev/null +++ b/progs/tests/auto/blob_complex.sy @@ -0,0 +1,19 @@ +start :: fn { + +a := A() +b := B() +c := C() +b2 := B() + +a +b +c +b2 + +blob A { + c: C +} +blob C { } +blob B { } + +} diff --git a/progs/tests/auto/blob_infer.sy b/progs/tests/auto/blob_infer.sy new file mode 100644 index 0000000..cee18bf --- /dev/null +++ b/progs/tests/auto/blob_infer.sy @@ -0,0 +1,8 @@ +start :: fn { + +blob A { } + +a : A = A() +a + +} diff --git a/progs/tests/auto/blob_simple.sy b/progs/tests/auto/blob_simple.sy new file mode 100644 index 0000000..f05ec07 --- /dev/null +++ b/progs/tests/auto/blob_simple.sy @@ -0,0 +1,10 @@ +start :: fn { + +a := A() +a + +blob A { + a: int +} + +} diff --git a/progs/tests/auto/calls_inside_calls.sy b/progs/tests/auto/calls_inside_calls.sy new file mode 100644 index 0000000..578f418 --- /dev/null +++ b/progs/tests/auto/calls_inside_calls.sy @@ -0,0 +1,11 @@ +start :: fn { +one := fn -> int { + ret 1 + } + add := fn a: int, b: int -> int { + ret a + b + } + add(one(), one()) <=> 2 + add(add(one(), one()), one()) <=> 3 + add(one(), add(one(), one())) <=> 3 +} diff --git a/progs/tests/auto/cluster.sy b/progs/tests/auto/cluster.sy new file mode 100644 index 0000000..8f279e7 --- /dev/null +++ b/progs/tests/auto/cluster.sy @@ -0,0 +1,14 @@ +start :: fn { + +blob A { a: int } +a := A() +a.a = 0 +a.a += 1 +a.a <=> 1 +a.a *= 2 +a.a <=> 2 +a.a /= 2 +a.a <=> 1 +a.a -= 1 +a.a <=> 0 +} diff --git a/progs/tests/auto/compare_constants_equality.sy b/progs/tests/auto/compare_constants_equality.sy new file mode 100644 index 0000000..c8c399b --- /dev/null +++ b/progs/tests/auto/compare_constants_equality.sy @@ -0,0 +1,5 @@ +start :: fn { +if 1 == 2 { + <!> + } +} diff --git a/progs/tests/auto/compare_constants_unequality.sy b/progs/tests/auto/compare_constants_unequality.sy new file mode 100644 index 0000000..8c115b4 --- /dev/null +++ b/progs/tests/auto/compare_constants_unequality.sy @@ -0,0 +1,5 @@ +start :: fn { +if 1 != 1 { + <!> + } +} diff --git a/progs/tests/auto/compare_variable.sy b/progs/tests/auto/compare_variable.sy new file mode 100644 index 0000000..25d21f4 --- /dev/null +++ b/progs/tests/auto/compare_variable.sy @@ -0,0 +1,9 @@ +start :: fn { +a := 1 + if a == 0 { + <!> + } + if a != 1 { + <!> + } +} diff --git a/progs/tests/auto/conflict_markers.sy b/progs/tests/auto/conflict_markers.sy new file mode 100644 index 0000000..715a859 --- /dev/null +++ b/progs/tests/auto/conflict_markers.sy @@ -0,0 +1,11 @@ +start :: fn { + +<<<<<<< HEAD +print extern_test(4.0) +======= +print extern_test(5.0) +>>>>>>> 2 + +} + +// errors: [ErrorKind::SyntaxError(_, _), ErrorKind::GitConflictError(2, 6)] diff --git a/progs/tests/auto/constant_function.sy b/progs/tests/auto/constant_function.sy new file mode 100644 index 0000000..2ec4019 --- /dev/null +++ b/progs/tests/auto/constant_function.sy @@ -0,0 +1,4 @@ +a :: fn {} +start :: fn { + a() +} diff --git a/progs/tests/auto/constant_function_closure.sy b/progs/tests/auto/constant_function_closure.sy new file mode 100644 index 0000000..8c54249 --- /dev/null +++ b/progs/tests/auto/constant_function_closure.sy @@ -0,0 +1,13 @@ +q := 1 + +f :: fn -> int { + q += 1 + ret q +} + +start :: fn { + f() <=> 2 + f() <=> 3 + f() <=> 4 + f() <=> 5 +} diff --git a/progs/tests/auto/constant_function_complex.sy b/progs/tests/auto/constant_function_complex.sy new file mode 100644 index 0000000..6a60ebe --- /dev/null +++ b/progs/tests/auto/constant_function_complex.sy @@ -0,0 +1,19 @@ +h :: fn -> int { + ret 3 +} + +k :: fn -> int { + ret h() +} + +a :: fn -> int { + ret q() +} + +q :: fn -> int { + ret k() +} + +start :: fn { + a() <=> 3 +} diff --git a/progs/tests/auto/constants_in_inner_functions.sy b/progs/tests/auto/constants_in_inner_functions.sy new file mode 100644 index 0000000..3371393 --- /dev/null +++ b/progs/tests/auto/constants_in_inner_functions.sy @@ -0,0 +1,20 @@ +start :: fn { + +q : int = 0 + +f :: fn -> fn -> { + g :: fn { + q += 1 + } + ret g +} + +g := f() +g() +q <=> 1 +g() +q <=> 2 +g() +q <=> 3 + +} diff --git a/progs/tests/auto/div.sy b/progs/tests/auto/div.sy new file mode 100644 index 0000000..3073270 --- /dev/null +++ b/progs/tests/auto/div.sy @@ -0,0 +1,5 @@ +start :: fn { +a := 2 +a /= 2 +a <=> 1 +} diff --git a/progs/tests/auto/else_.sy b/progs/tests/auto/else_.sy new file mode 100644 index 0000000..896aeb4 --- /dev/null +++ b/progs/tests/auto/else_.sy @@ -0,0 +1,10 @@ +start :: fn { +a := 1 + res := 0 + if a == 0 { + <!> + } else { + res = 1 + } + res <=> 1 +} diff --git a/progs/tests/auto/else_if.sy b/progs/tests/auto/else_if.sy new file mode 100644 index 0000000..18b64f6 --- /dev/null +++ b/progs/tests/auto/else_if.sy @@ -0,0 +1,12 @@ +start :: fn { +a := 1 + res := 0 + if a == 0 { + <!> + } else if a == 1 { + res = 1 + } else { + <!> + } + res <=> 1 +} diff --git a/progs/tests/auto/expressions.sy b/progs/tests/auto/expressions.sy new file mode 100644 index 0000000..0f6d6fc --- /dev/null +++ b/progs/tests/auto/expressions.sy @@ -0,0 +1,6 @@ +start :: fn { +1 + 1 // blargh + 2 // blargh + // HARGH + +} diff --git a/progs/tests/auto/factorial.sy b/progs/tests/auto/factorial.sy new file mode 100644 index 0000000..770bc33 --- /dev/null +++ b/progs/tests/auto/factorial.sy @@ -0,0 +1,12 @@ +factorial :: fn n: int -> int { + if n <= 1 { + ret 1 + } + ret n * factorial(n - 1) +} + +start :: fn { + factorial(5) <=> 120 + factorial(6) <=> 720 + factorial(12) <=> 479001600 +} diff --git a/progs/tests/auto/field.sy b/progs/tests/auto/field.sy new file mode 100644 index 0000000..c985297 --- /dev/null +++ b/progs/tests/auto/field.sy @@ -0,0 +1,3 @@ +start :: fn { +blob A { a: int } +} diff --git a/progs/tests/auto/field_assign.sy b/progs/tests/auto/field_assign.sy new file mode 100644 index 0000000..93837ea --- /dev/null +++ b/progs/tests/auto/field_assign.sy @@ -0,0 +1,5 @@ +start :: fn { +blob A { a: int } + a := A() + a.a = 2 +} diff --git a/progs/tests/auto/field_get.sy b/progs/tests/auto/field_get.sy new file mode 100644 index 0000000..0905f6f --- /dev/null +++ b/progs/tests/auto/field_get.sy @@ -0,0 +1,7 @@ +start :: fn { +blob A { a: int } + a := A() + a.a = 2 + a.a <=> 2 + 2 <=> a.a +} diff --git a/progs/tests/auto/in_rhs.sy b/progs/tests/auto/in_rhs.sy new file mode 100644 index 0000000..60e4873 --- /dev/null +++ b/progs/tests/auto/in_rhs.sy @@ -0,0 +1,3 @@ +start :: fn { +5 <=> 1 * 2 + 3 +} diff --git a/progs/tests/auto/instantiate.sy b/progs/tests/auto/instantiate.sy new file mode 100644 index 0000000..7d32bf9 --- /dev/null +++ b/progs/tests/auto/instantiate.sy @@ -0,0 +1,5 @@ +start :: fn { +blob A {} + a := A() + a +} diff --git a/progs/tests/auto/invalid_assign.sy b/progs/tests/auto/invalid_assign.sy new file mode 100644 index 0000000..a8b18f0 --- /dev/null +++ b/progs/tests/auto/invalid_assign.sy @@ -0,0 +1,7 @@ +start :: fn { +a := 1 +a = 0.1 +a +} + +// errors: [ErrorKind::TypeMismatch(Type::Int, Type::Float)] diff --git a/progs/tests/auto/more_types.sy b/progs/tests/auto/more_types.sy new file mode 100644 index 0000000..18d825e --- /dev/null +++ b/progs/tests/auto/more_types.sy @@ -0,0 +1,4 @@ +start :: fn { +a: (str, bool, int) = ("abc", true, 1) +a +} diff --git a/progs/tests/auto/mul.sy b/progs/tests/auto/mul.sy new file mode 100644 index 0000000..78cc14e --- /dev/null +++ b/progs/tests/auto/mul.sy @@ -0,0 +1,3 @@ +start :: fn { +(0, 1, 2) * (2, 3, 4) <=> (0, 3, 8) +} diff --git a/progs/tests/auto/multiple_fields.sy b/progs/tests/auto/multiple_fields.sy new file mode 100644 index 0000000..2a4b3c0 --- /dev/null +++ b/progs/tests/auto/multiple_fields.sy @@ -0,0 +1,11 @@ +start :: fn { +blob A { + a: int + b: int + } + a := A() + a.a = 2 + a.b = 3 + a.a + a.b <=> 5 + 5 <=> a.a + a.b +} diff --git a/progs/tests/auto/multiple_returns.sy b/progs/tests/auto/multiple_returns.sy new file mode 100644 index 0000000..8abc000 --- /dev/null +++ b/progs/tests/auto/multiple_returns.sy @@ -0,0 +1,12 @@ +start :: fn { +f := fn a: int -> int { + if a == 1 { + ret 2 + } else { + ret 3 + } + } + f(0) <=> 3 + f(1) <=> 2 + f(2) <=> 3 +} diff --git a/progs/tests/auto/negation.sy b/progs/tests/auto/negation.sy new file mode 100644 index 0000000..41388d8 --- /dev/null +++ b/progs/tests/auto/negation.sy @@ -0,0 +1,7 @@ +start :: fn { +-1 <=> 0 - 1 + -1 + 2 <=> 1 + -(1 + 2) <=> -3 + 1 + -1 <=> 0 + 2 * -1 <=> -2 +} diff --git a/progs/tests/auto/not.sy b/progs/tests/auto/not.sy new file mode 100644 index 0000000..712690a --- /dev/null +++ b/progs/tests/auto/not.sy @@ -0,0 +1,5 @@ +start :: fn { +f := fn {} + f! + +} diff --git a/progs/tests/auto/one_arg.sy b/progs/tests/auto/one_arg.sy new file mode 100644 index 0000000..9523a67 --- /dev/null +++ b/progs/tests/auto/one_arg.sy @@ -0,0 +1,5 @@ +start :: fn { +f := fn a:int { a <=> 1 } + f! 1 + +} diff --git a/progs/tests/auto/param_1.sy b/progs/tests/auto/param_1.sy new file mode 100644 index 0000000..1781eaf --- /dev/null +++ b/progs/tests/auto/param_1.sy @@ -0,0 +1,4 @@ +start :: fn { +f := fn a: int {} + f(1) +} diff --git a/progs/tests/auto/param_2.sy b/progs/tests/auto/param_2.sy new file mode 100644 index 0000000..ac5fdfd --- /dev/null +++ b/progs/tests/auto/param_2.sy @@ -0,0 +1,7 @@ +start :: fn { +add := fn a: int, b: int -> int { + ret a + b + } + add(1, 1) <=> 2 + add(10, 20) <=> 30 +} diff --git a/progs/tests/auto/param_and_return.sy b/progs/tests/auto/param_and_return.sy new file mode 100644 index 0000000..7e39775 --- /dev/null +++ b/progs/tests/auto/param_and_return.sy @@ -0,0 +1,7 @@ +start :: fn { +f := fn a: int -> int { + ret a * 2 + } + f(1) <=> 2 + f(5) <=> 10 +} diff --git a/progs/tests/auto/parenthesis.sy b/progs/tests/auto/parenthesis.sy new file mode 100644 index 0000000..b456769 --- /dev/null +++ b/progs/tests/auto/parenthesis.sy @@ -0,0 +1,3 @@ +start :: fn { +(1 + 2) * 3 <=> 9 +} diff --git a/progs/tests/auto/passing_functions.sy b/progs/tests/auto/passing_functions.sy new file mode 100644 index 0000000..d1ff70e --- /dev/null +++ b/progs/tests/auto/passing_functions.sy @@ -0,0 +1,9 @@ +start :: fn { +g := fn -> int { + ret 1 + } + f := fn inner: fn -> int -> int { + ret inner() + } + f(g) <=> 1 +} diff --git a/progs/tests/auto/passing_functions_mixed.sy b/progs/tests/auto/passing_functions_mixed.sy new file mode 100644 index 0000000..292e7ce --- /dev/null +++ b/progs/tests/auto/passing_functions_mixed.sy @@ -0,0 +1,9 @@ +start :: fn { +g := fn a: int -> int { + ret a * 2 + } + f := fn inner: fn int -> int, a: int -> int { + ret inner(a) + } + f(g, 2) <=> 4 +} diff --git a/progs/tests/auto/precedence.sy b/progs/tests/auto/precedence.sy new file mode 100644 index 0000000..0aee658 --- /dev/null +++ b/progs/tests/auto/precedence.sy @@ -0,0 +1,8 @@ +start :: fn { +f := fn a: int, b: int -> int { + ret a + b + } + 1 + f(2, 3) <=> 6 + 2 * f(2, 3) <=> 10 + f(2, 3) - (2 + 3) <=> 0 +} diff --git a/progs/tests/auto/return_1.sy b/progs/tests/auto/return_1.sy new file mode 100644 index 0000000..993f9fd --- /dev/null +++ b/progs/tests/auto/return_1.sy @@ -0,0 +1,6 @@ +start :: fn { +f := fn -> int { + ret 1 + } + f() <=> 1 +} diff --git a/progs/tests/auto/returning_closures.sy b/progs/tests/auto/returning_closures.sy new file mode 100644 index 0000000..1c4c091 --- /dev/null +++ b/progs/tests/auto/returning_closures.sy @@ -0,0 +1,24 @@ +start :: fn { + +f : fn -> fn -> int = fn -> fn -> int { + x : int = 0 + f := fn -> int { + x = x + 1 + ret x + } + f() <=> 1 + ret f +} + +a := f() +b := f() + +a() <=> 2 +a() <=> 3 + +b() <=> 2 +b() <=> 3 + +a() <=> 4 + +} diff --git a/progs/tests/auto/simple.sy b/progs/tests/auto/simple.sy new file mode 100644 index 0000000..436dcae --- /dev/null +++ b/progs/tests/auto/simple.sy @@ -0,0 +1,10 @@ +start :: fn { + +a :: 1 +a <=> 1 +b := 2 +{ + a <=> 1 + b <=> 2 +} +} diff --git a/progs/tests/auto/simple_add.sy b/progs/tests/auto/simple_add.sy new file mode 100644 index 0000000..f1952d3 --- /dev/null +++ b/progs/tests/auto/simple_add.sy @@ -0,0 +1,9 @@ +start :: fn { + +a := 0 +b := 99999 +a += 1 +a <=> 1 +b <=> 99999 + +} diff --git a/progs/tests/auto/simple_break.sy b/progs/tests/auto/simple_break.sy new file mode 100644 index 0000000..11c06ad --- /dev/null +++ b/progs/tests/auto/simple_break.sy @@ -0,0 +1,12 @@ +start :: fn { + +a := 0 +for i := 0, i < 10, i += 1 { + a = a + 1 + if i == 2 { + break + } +} +a <=> 3 + +} diff --git a/progs/tests/auto/simple_continue.sy b/progs/tests/auto/simple_continue.sy new file mode 100644 index 0000000..ac2bf81 --- /dev/null +++ b/progs/tests/auto/simple_continue.sy @@ -0,0 +1,12 @@ +start :: fn { + +a := 0 +for i := 0, i < 4, i += 1 { + if i == 2 { + continue + } + a = a + 1 +} +a <=> 3 + +} diff --git a/progs/tests/auto/simple_sub.sy b/progs/tests/auto/simple_sub.sy new file mode 100644 index 0000000..5dad340 --- /dev/null +++ b/progs/tests/auto/simple_sub.sy @@ -0,0 +1,9 @@ +start :: fn { + +a := 0 +b := 99999 +a -= 1 +a <=> -1 +b <=> 99999 + +} diff --git a/progs/tests/auto/simplest.sy b/progs/tests/auto/simplest.sy new file mode 100644 index 0000000..5669dc0 --- /dev/null +++ b/progs/tests/auto/simplest.sy @@ -0,0 +1,4 @@ +start :: fn { +f := fn {} + f() +} diff --git a/progs/tests/auto/single_variable.sy b/progs/tests/auto/single_variable.sy new file mode 100644 index 0000000..00217d2 --- /dev/null +++ b/progs/tests/auto/single_variable.sy @@ -0,0 +1,4 @@ +start :: fn { +a := 1 + a <=> 1 +} diff --git a/progs/tests/auto/stack_ordering.sy b/progs/tests/auto/stack_ordering.sy new file mode 100644 index 0000000..85a36bd --- /dev/null +++ b/progs/tests/auto/stack_ordering.sy @@ -0,0 +1,6 @@ +start :: fn { +a := 1 + b := 2 + b <=> 2 + a <=> 1 +} diff --git a/progs/tests/auto/strange.sy b/progs/tests/auto/strange.sy new file mode 100644 index 0000000..c495041 --- /dev/null +++ b/progs/tests/auto/strange.sy @@ -0,0 +1,15 @@ +start :: fn { + +a := 0 +{ + b := 99999 + { + a := 99999 + a + } + b + a -= 1 +} +a <=> -1 + +} diff --git a/progs/tests/auto/sub.sy b/progs/tests/auto/sub.sy new file mode 100644 index 0000000..755ae67 --- /dev/null +++ b/progs/tests/auto/sub.sy @@ -0,0 +1,3 @@ +start :: fn { +(1, -2, 3, -4) - (4, 3, -2, -1) <=> (-3, 1, 1, -5) +} diff --git a/progs/tests/auto/terms_and_factors.sy b/progs/tests/auto/terms_and_factors.sy new file mode 100644 index 0000000..1fef724 --- /dev/null +++ b/progs/tests/auto/terms_and_factors.sy @@ -0,0 +1,4 @@ +start :: fn { +1 + 1 * 2 <=> 3 + 1 * 2 + 3 <=> 5 +} diff --git a/progs/tests/auto/three_arg.sy b/progs/tests/auto/three_arg.sy new file mode 100644 index 0000000..d948fa0 --- /dev/null +++ b/progs/tests/auto/three_arg.sy @@ -0,0 +1,5 @@ +start :: fn { +f := fn a:int, b:int, c:int { c <=> 13 } + f! 1, 1 + 2, 1 + 4 * 3 + +} diff --git a/progs/tests/auto/two_arg.sy b/progs/tests/auto/two_arg.sy new file mode 100644 index 0000000..60645b5 --- /dev/null +++ b/progs/tests/auto/two_arg.sy @@ -0,0 +1,5 @@ +start :: fn { +f := fn a:int, b:int { b <=> 3 } + f! 1, 1 + 2 + +} diff --git a/progs/tests/auto/two_variables.sy b/progs/tests/auto/two_variables.sy new file mode 100644 index 0000000..9ae183f --- /dev/null +++ b/progs/tests/auto/two_variables.sy @@ -0,0 +1,6 @@ +start :: fn { +a := 1 + b := 2 + a <=> 1 + b <=> 2 +} diff --git a/progs/tests/auto/types.sy b/progs/tests/auto/types.sy new file mode 100644 index 0000000..c045b34 --- /dev/null +++ b/progs/tests/auto/types.sy @@ -0,0 +1,4 @@ +start :: fn { +a: (int, float, int) = (1, 1., 1) +a +} diff --git a/progs/tests/auto/uncallable_type.sy b/progs/tests/auto/uncallable_type.sy new file mode 100644 index 0000000..06ff71a --- /dev/null +++ b/progs/tests/auto/uncallable_type.sy @@ -0,0 +1,9 @@ +start :: fn { + + f := fn i: int { + i() + } + f +} + +// errors: [ErrorKind::InvalidProgram] diff --git a/progs/tests/auto/wrong_params.sy b/progs/tests/auto/wrong_params.sy new file mode 100644 index 0000000..6b56e90 --- /dev/null +++ b/progs/tests/auto/wrong_params.sy @@ -0,0 +1,7 @@ +start :: fn { + + f : fn -> int = fn a: int -> int {} +f +} + +// errors: [ErrorKind::TypeMismatch(_, _), ErrorKind::TypeMismatch(Type::Void, Type::Int)] diff --git a/progs/tests/auto/wrong_ret.sy b/progs/tests/auto/wrong_ret.sy new file mode 100644 index 0000000..81f2517 --- /dev/null +++ b/progs/tests/auto/wrong_ret.sy @@ -0,0 +1,7 @@ +start :: fn { + + f : fn -> int = fn {} +f +} + +// errors: [ErrorKind::TypeMismatch(_, _)] diff --git a/progs/tests/faulty.sy b/progs/tests/faulty.sy index 369b8ff..ea1b40d 100644 --- a/progs/tests/faulty.sy +++ b/progs/tests/faulty.sy @@ -1,3 +1,5 @@ asdflökja;;;; 123 asd + +// errors: [ErrorKind::SyntaxError(_, _)] diff --git a/progs/tests/fib.sy b/progs/tests/fib.sy index 1dde6a8..62f38e7 100644 --- a/progs/tests/fib.sy +++ b/progs/tests/fib.sy @@ -1,9 +1,11 @@ -a := 0 -b := 1 +start :: fn { + a := 0 + b := 1 -for i := 0, i < 90, i = i + 1 { - c := a - a = b - b = c + b + for i := 0, i < 90, i = i + 1 { + c := a + a = b + b = c + b + } + a <=> 2880067194370816120 } -a <=> 2880067194370816120 diff --git a/progs/tests/for.sy b/progs/tests/for.sy index a9f8cd2..285cbc3 100644 --- a/progs/tests/for.sy +++ b/progs/tests/for.sy @@ -1,19 +1,21 @@ -a := 0 -for i := 0, i < 3, i = i + 1 { - a = a + i -} -a <=> 3 +start :: fn { + a := 0 + for i := 0, i < 3, i = i + 1 { + a = a + i + } + a <=> 3 -a = 0 -for i := 0, i <= 3, i = i + 1 { - a = a + i -} -a <=> 6 + a = 0 + for i := 0, i <= 3, i = i + 1 { + a = a + i + } + a <=> 6 -a = 0 -for i := 0, i < 3, i = i + 1 { - for j := 0, j < 3, j = j + 1 { - a = a + i * j + a = 0 + for i := 0, i < 3, i = i + 1 { + for j := 0, j < 3, j = j + 1 { + a = a + i * j + } } + a <=> 9 } -a <=> 9 diff --git a/progs/tests/scoping.sy b/progs/tests/scoping.sy index f8e0b00..dfcf92c 100644 --- a/progs/tests/scoping.sy +++ b/progs/tests/scoping.sy @@ -1,14 +1,16 @@ -a : int = 1 -{ +start :: fn { + a : int = 1 + { + a <=> 1 + a : int = a + a + a <=> 2 + } a <=> 1 - a : int = a + a - a <=> 2 -} -a <=> 1 -{ - a = 2 - a : int = 1 - a + { + a = 2 + a : int = 1 + a + } + a <=> 2 } -a <=> 2 @@ -875,37 +875,6 @@ mod tests { } #[macro_export] - macro_rules! test_string { - ($fn:ident, $prog:literal) => { - #[test] - fn $fn() { - crate::tests::panic_after(std::time::Duration::from_millis(500), || { - let prog = std::concat!("start :: fn {", $prog, "\n{}\n}\n"); - match $crate::run_string(&prog, true, Vec::new()) { - Ok(()) => {}, - Err(errs) => { - for e in errs.iter() { - eprintln!("{}", e); - } - eprintln!(" {} - failed\n", stringify!($fn)); - unreachable!(); - } - } - }); - } - }; - ($fn:ident, $prog:literal, $errs:tt) => { - #[test] - fn $fn() { - crate::tests::panic_after(std::time::Duration::from_millis(500), || { - let prog = std::concat!("start :: fn {", $prog, "\n{}\n}\n"); - $crate::assert_errs!($crate::run_string(&prog, true, Vec::new()), $errs); - }) - } - } - } - - #[macro_export] macro_rules! test_file { ($fn:ident, $path:literal) => { #[test] @@ -918,6 +887,7 @@ mod tests { #[test] fn $fn() { use crate::error::ErrorKind; + use crate::Type; let file = std::path::Path::new($path); let res = crate::run_file(&file, true, Vec::new()); @@ -927,518 +897,4 @@ mod tests { } sylt_macro::find_tests!(); - - #[test] - fn unreachable_token() { - assert_errs!(run_string("<!>\n", true, Vec::new()), [ErrorKind::Unreachable]); - } - - #[test] - fn assign_to_constant() { - assert_errs!(run_string("a :: 2\na = 2", true, Vec::new()), [ErrorKind::SyntaxError(_, _)]); - } - - #[test] - fn assign_to_constant_upvalue() { - assert_errs!(run_string("a :: 2\nq :: fn { a = 2 }\nq()\na", true, Vec::new()), [ErrorKind::SyntaxError(_, _)]); - } - - #[test] - fn undefined_blob() { - assert_errs!(run_string("a :: B()\n", true, Vec::new()), [ErrorKind::SyntaxError(_, _)]); - } - - #[test] - fn call_before_link() { - let prog = " -a := 1 -f() -c := 5 - -f :: fn { - c <=> 5 -} -a - "; - assert_errs!(run_string(prog, true, Vec::new()), [ErrorKind::InvalidProgram, ErrorKind::TypeError(_, _)]); - } - - #[test] - fn unused_variable() { - assert_errs!(run_string("a := 1", true, Vec::new()), [ErrorKind::SyntaxError(1, _)]); - } - - #[test] - fn unused_upvalue() { - assert_errs!(run_string("a := 1\nf :: fn { a = 2 }\nf()", true, Vec::new()), [ErrorKind::SyntaxError(1, _)]); - } - - #[test] - fn unused_function() { - assert_errs!(run_string("a := 1\nf := fn { a }\n", true, Vec::new()), [ErrorKind::SyntaxError(2, _)]); - } - - macro_rules! test_multiple { - ($mod:ident, $( $fn:ident : $prog:literal ),+ $( , )? ) => { - mod $mod { - $( test_string!($fn, $prog); )+ - } - } - } - - test_multiple!( - order_of_operations, - terms_and_factors: "1 + 1 * 2 <=> 3 - 1 * 2 + 3 <=> 5", - in_rhs: "5 <=> 1 * 2 + 3", - parenthesis: "(1 + 2) * 3 <=> 9", - negation: "-1 <=> 0 - 1 - -1 + 2 <=> 1 - -(1 + 2) <=> -3 - 1 + -1 <=> 0 - 2 * -1 <=> -2", - ); - - test_multiple!( - variables, - single_variable: "a := 1 - a <=> 1", - two_variables: "a := 1 - b := 2 - a <=> 1 - b <=> 2", - stack_ordering: "a := 1 - b := 2 - b <=> 2 - a <=> 1", - assignment: "a := 1 - b := 2 - a = b - a <=> 2 - b <=> 2", - ); - - test_multiple!( - if_, - compare_constants_equality: "if 1 == 2 { - <!> - }", - compare_constants_unequality: "if 1 != 1 { - <!> - }", - compare_variable: "a := 1 - if a == 0 { - <!> - } - if a != 1 { - <!> - }", - else_: "a := 1 - res := 0 - if a == 0 { - <!> - } else { - res = 1 - } - res <=> 1", - else_if: "a := 1 - res := 0 - if a == 0 { - <!> - } else if a == 1 { - res = 1 - } else { - <!> - } - res <=> 1", - ); - - test_multiple!( - fun, - simplest: "f := fn {} - f()", - param_1: "f := fn a: int {} - f(1)", - return_1: "f := fn -> int { - ret 1 - } - f() <=> 1", - param_and_return: "f := fn a: int -> int { - ret a * 2 - } - f(1) <=> 2 - f(5) <=> 10", - param_2: "add := fn a: int, b: int -> int { - ret a + b - } - add(1, 1) <=> 2 - add(10, 20) <=> 30", - calls_inside_calls: "one := fn -> int { - ret 1 - } - add := fn a: int, b: int -> int { - ret a + b - } - add(one(), one()) <=> 2 - add(add(one(), one()), one()) <=> 3 - add(one(), add(one(), one())) <=> 3", - passing_functions: "g := fn -> int { - ret 1 - } - f := fn inner: fn -> int -> int { - ret inner() - } - f(g) <=> 1", - passing_functions_mixed: "g := fn a: int -> int { - ret a * 2 - } - f := fn inner: fn int -> int, a: int -> int { - ret inner(a) - } - f(g, 2) <=> 4", - multiple_returns: "f := fn a: int -> int { - if a == 1 { - ret 2 - } else { - ret 3 - } - } - f(0) <=> 3 - f(1) <=> 2 - f(2) <=> 3", - precedence: "f := fn a: int, b: int -> int { - ret a + b - } - 1 + f(2, 3) <=> 6 - 2 * f(2, 3) <=> 10 - f(2, 3) - (2 + 3) <=> 0", - factorial: "factorial : fn int -> int = fn n: int -> int { - if n <= 1 { - ret 1 - } - ret n * factorial(n - 1) - } - factorial(5) <=> 120 - factorial(6) <=> 720 - factorial(12) <=> 479001600", - - returning_closures: " -f : fn -> fn -> int = fn -> fn -> int { - x : int = 0 - f := fn -> int { - x = x + 1 - ret x - } - f() <=> 1 - ret f -} - -a := f() -b := f() - -a() <=> 2 -a() <=> 3 - -b() <=> 2 -b() <=> 3 - -a() <=> 4 -", - ); - - test_multiple!( - blob, - simple: "blob A {}", - instantiate: "blob A {} - a := A() - a", - field: "blob A { a: int }", - field_assign: "blob A { a: int } - a := A() - a.a = 2", - field_get: "blob A { a: int } - a := A() - a.a = 2 - a.a <=> 2 - 2 <=> a.a", - multiple_fields: "blob A { - a: int - b: int - } - a := A() - a.a = 2 - a.b = 3 - a.a + a.b <=> 5 - 5 <=> a.a + a.b", - blob_infer: " -blob A { } -a : A = A() -a -", - ); - - test_multiple!(tuples, - add: "(1, 2, 3, 4) + (4, 3, 2, 1) <=> (5, 5, 5, 5)", - sub: "(1, -2, 3, -4) - (4, 3, -2, -1) <=> (-3, 1, 1, -5)", - mul: "(0, 1, 2) * (2, 3, 4) <=> (0, 3, 8)", - types: "a: (int, float, int) = (1, 1., 1)\na", - more_types: "a: (str, bool, int) = (\"abc\", true, 1)\na", - ); - - test_file!(scoping, "progs/tests/scoping.sy"); - test_file!(for_, "progs/tests/for.sy"); - - test_multiple!( - op_assign, - add: "a := 1\na += 1\na <=> 2", - sub: "a := 2\na -= 1\na <=> 1", - mul: "a := 2\na *= 2\na <=> 4", - div: "a := 2\na /= 2\na <=> 1", - cluster: " -blob A { a: int } -a := A() -a.a = 0 -a.a += 1 -a.a <=> 1 -a.a *= 2 -a.a <=> 2 -a.a /= 2 -a.a <=> 1 -a.a -= 1 -a.a <=> 0" - ); - - test_multiple!( - fancy_call, - not: "f := fn {}\n f!\n", - one_arg: "f := fn a:int { a <=> 1 }\n f! 1\n", - two_arg: "f := fn a:int, b:int { b <=> 3 }\n f! 1, 1 + 2\n", - three_arg: "f := fn a:int, b:int, c:int { c <=> 13 }\n f! 1, 1 + 2, 1 + 4 * 3\n", - ); - - test_multiple!( - newline_regression, - simple: "a := 1 // blargh \na += 1 // blargh \n a <=> 2 // HARGH", - expressions: "1 + 1 // blargh \n 2 // blargh \n // HARGH \n", - ); - - test_multiple!( - break_and_continue, - simple_break: " -a := 0 -for i := 0, i < 10, i += 1 { - a = a + 1 - if i == 2 { - break - } -} -a <=> 3 -", - - simple_continue: " -a := 0 -for i := 0, i < 4, i += 1 { - if i == 2 { - continue - } - a = a + 1 -} -a <=> 3 -", - - advanced_break: " -a := 0 -for i := 0, i < 10, i += 1 { - q := 0 - qq := 0 - qqq := 0 - qqqq := 0 - - a = a + 1 - if i == 2 { - break - } - - q - qq - qqq - qqqq -} -a <=> 3 -", - - advanced_continue: " -a := 0 -for i := 0, i < 4, i += 1 { - q := 0 - qq := 0 - qqq := 0 - qqqq := 0 - - if i == 2 { - continue - } - a = a + 1 - - q - qq - qqq - qqqq -} -a <=> 3 -", - ); - - test_multiple!( - read_constants, - simple: " -a :: 1 -a <=> 1 -b := 2 -{ - a <=> 1 - b <=> 2 -}", - ); - - test_multiple!( - assignment_op_regression, - simple_add: " -a := 0 -b := 99999 -a += 1 -a <=> 1 -b <=> 99999 -", - - simple_sub: " -a := 0 -b := 99999 -a -= 1 -a <=> -1 -b <=> 99999 -", - - strange: " -a := 0 -{ - b := 99999 - { - a := 99999 - a - } - b - a -= 1 -} -a <=> -1 -", - ); - - test_multiple!( - declaration_order, - blob_simple: " -a := A() -a - -blob A { - a: int -} -", - - blob_complex: " -a := A() -b := B() -c := C() -b2 := B() - -a -b -c -b2 - -blob A { - c: C -} -blob C { } -blob B { } -", - - blob_infer: " -blob A { } - -a : A = A() -a -", - - - constant_function: " -a() -a :: fn {} -", - - constant_function_complex: " -h :: fn -> int { - ret 3 -} - -a() <=> 3 - -k :: fn -> int { - ret h() -} - -a :: fn -> int { - ret q() -} - -q :: fn -> int { - ret k() -} -", - - constant_function_closure: " -q := 1 - -f :: fn -> int { - q += 1 - ret q -} - -f() <=> 2 -f() <=> 3 -f() <=> 4 -f() <=> 5 -", - - constants_in_inner_functions: " -q : int = 0 - -f :: fn -> fn -> { - g :: fn { - q += 1 - } - ret g -} - -g := f() -g() -q <=> 1 -g() -q <=> 2 -g() -q <=> 3 -", - - ); - - test_string!(conflict_markers, " -<<<<<<< HEAD -print extern_test(4.0) -======= -print extern_test(5.0) ->>>>>>> 2 -", - [ErrorKind::SyntaxError(_, _), ErrorKind::GitConflictError(2, 6)] - ); - } @@ -824,29 +824,3 @@ impl VM { } } } - -#[cfg(test)] -mod tests { - mod typing { - use crate::error::ErrorKind; - use crate::{test_string, Type}; - - test_string!(uncallable_type, " - f := fn i: int { - i() - } - f", - [ErrorKind::InvalidProgram]); - - test_string!(invalid_assign, "a := 1\na = 0.1\na", - [ErrorKind::TypeMismatch(Type::Int, Type::Float)]); - - test_string!(wrong_params, " - f : fn -> int = fn a: int -> int {}\nf", - [ErrorKind::TypeMismatch(_, _), ErrorKind::TypeMismatch(Type::Void, Type::Int)]); - - test_string!(wrong_ret, " - f : fn -> int = fn {}\nf", - [ErrorKind::TypeMismatch(_, _)]); - } -} |
