diff options
Diffstat (limited to 'progs/tests/func')
| -rw-r--r-- | progs/tests/func/calls_inside_calls.sy | 11 | ||||
| -rw-r--r-- | progs/tests/func/exclamation_calling.sy | 5 | ||||
| -rw-r--r-- | progs/tests/func/inner_simple.sy | 4 | ||||
| -rw-r--r-- | progs/tests/func/multiple_returns.sy | 12 | ||||
| -rw-r--r-- | progs/tests/func/one_arg.sy | 5 | ||||
| -rw-r--r-- | progs/tests/func/param_1.sy | 4 | ||||
| -rw-r--r-- | progs/tests/func/param_2.sy | 7 | ||||
| -rw-r--r-- | progs/tests/func/param_and_return.sy | 7 | ||||
| -rw-r--r-- | progs/tests/func/passing_functions_as_arguments.sy | 9 | ||||
| -rw-r--r-- | progs/tests/func/passing_functions_as_arguments_mixed.sy | 9 | ||||
| -rw-r--r-- | progs/tests/func/precedence.sy | 8 | ||||
| -rw-r--r-- | progs/tests/func/return_1.sy | 6 | ||||
| -rw-r--r-- | progs/tests/func/returning_closures.sy | 24 | ||||
| -rw-r--r-- | progs/tests/func/three_arg.sy | 5 | ||||
| -rw-r--r-- | progs/tests/func/two_arg.sy | 5 | ||||
| -rw-r--r-- | progs/tests/func/uncallable_type.sy | 8 | ||||
| -rw-r--r-- | progs/tests/func/wrong_params.sy | 7 | ||||
| -rw-r--r-- | progs/tests/func/wrong_ret.sy | 7 |
18 files changed, 143 insertions, 0 deletions
diff --git a/progs/tests/func/calls_inside_calls.sy b/progs/tests/func/calls_inside_calls.sy new file mode 100644 index 0000000..5f6716b --- /dev/null +++ b/progs/tests/func/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/func/exclamation_calling.sy b/progs/tests/func/exclamation_calling.sy new file mode 100644 index 0000000..02dd81d --- /dev/null +++ b/progs/tests/func/exclamation_calling.sy @@ -0,0 +1,5 @@ +start :: fn { + f := fn {} + f! + +} diff --git a/progs/tests/func/inner_simple.sy b/progs/tests/func/inner_simple.sy new file mode 100644 index 0000000..14a6534 --- /dev/null +++ b/progs/tests/func/inner_simple.sy @@ -0,0 +1,4 @@ +start :: fn { + f := fn {} + f() +} diff --git a/progs/tests/func/multiple_returns.sy b/progs/tests/func/multiple_returns.sy new file mode 100644 index 0000000..6cb5e1a --- /dev/null +++ b/progs/tests/func/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/func/one_arg.sy b/progs/tests/func/one_arg.sy new file mode 100644 index 0000000..e7dee83 --- /dev/null +++ b/progs/tests/func/one_arg.sy @@ -0,0 +1,5 @@ +start :: fn { + f := fn a:int { a <=> 1 } + f! 1 + +} diff --git a/progs/tests/func/param_1.sy b/progs/tests/func/param_1.sy new file mode 100644 index 0000000..c96089e --- /dev/null +++ b/progs/tests/func/param_1.sy @@ -0,0 +1,4 @@ +start :: fn { + f := fn a: int {} + f(1) +} diff --git a/progs/tests/func/param_2.sy b/progs/tests/func/param_2.sy new file mode 100644 index 0000000..1915c42 --- /dev/null +++ b/progs/tests/func/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/func/param_and_return.sy b/progs/tests/func/param_and_return.sy new file mode 100644 index 0000000..2752fcc --- /dev/null +++ b/progs/tests/func/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/func/passing_functions_as_arguments.sy b/progs/tests/func/passing_functions_as_arguments.sy new file mode 100644 index 0000000..e09a125 --- /dev/null +++ b/progs/tests/func/passing_functions_as_arguments.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/func/passing_functions_as_arguments_mixed.sy b/progs/tests/func/passing_functions_as_arguments_mixed.sy new file mode 100644 index 0000000..b08128e --- /dev/null +++ b/progs/tests/func/passing_functions_as_arguments_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/func/precedence.sy b/progs/tests/func/precedence.sy new file mode 100644 index 0000000..ae08e05 --- /dev/null +++ b/progs/tests/func/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/func/return_1.sy b/progs/tests/func/return_1.sy new file mode 100644 index 0000000..533208f --- /dev/null +++ b/progs/tests/func/return_1.sy @@ -0,0 +1,6 @@ +start :: fn { + f := fn -> int { + ret 1 + } + f() <=> 1 +} diff --git a/progs/tests/func/returning_closures.sy b/progs/tests/func/returning_closures.sy new file mode 100644 index 0000000..4d69d5a --- /dev/null +++ b/progs/tests/func/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/func/three_arg.sy b/progs/tests/func/three_arg.sy new file mode 100644 index 0000000..56eb634 --- /dev/null +++ b/progs/tests/func/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/func/two_arg.sy b/progs/tests/func/two_arg.sy new file mode 100644 index 0000000..09ea1f7 --- /dev/null +++ b/progs/tests/func/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/func/uncallable_type.sy b/progs/tests/func/uncallable_type.sy new file mode 100644 index 0000000..dbe6e81 --- /dev/null +++ b/progs/tests/func/uncallable_type.sy @@ -0,0 +1,8 @@ +start :: fn { + f := fn i: int { + i() + } + f +} + +// errors: [ErrorKind::InvalidProgram] diff --git a/progs/tests/func/wrong_params.sy b/progs/tests/func/wrong_params.sy new file mode 100644 index 0000000..e49e89b --- /dev/null +++ b/progs/tests/func/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/func/wrong_ret.sy b/progs/tests/func/wrong_ret.sy new file mode 100644 index 0000000..6c4a9a5 --- /dev/null +++ b/progs/tests/func/wrong_ret.sy @@ -0,0 +1,7 @@ +start :: fn { + + f : fn -> int = fn {} + f +} + +// errors: [ErrorKind::TypeMismatch(_, _)] |
