diff --git a/tests/closure_test.aer b/tests/closure_test.aer new file mode 100644 index 0000000..34886da --- /dev/null +++ b/tests/closure_test.aer @@ -0,0 +1,36 @@ +class Operations { + + public callback ops(int $x, int $y, string $op){ + switch($op) { + case 'ADD': + return int() using ($x, $y) { + return $x + $y; + }; + break; + case 'SUB': + return int() using ($x, $y) { + return $x - $y; + }; + break; + default: + return string() { + return 'Operation is not supported by class.'; + }; + } + } +} + +class Program { + + void main() { + callback $fn; + object $op = new Operations(); + $fn = $op->ops(6, 7, 'ADD'); + print($fn() + "\n"); + $fn = $op->ops(6, 2, 'SUB'); + print($fn() + "\n"); + $fn = $op->ops(6, 7, 'MUL'); + print($fn() + "\n"); + } + +} diff --git a/tests/closure_test.exp b/tests/closure_test.exp new file mode 100644 index 0000000..3ca1c19 --- /dev/null +++ b/tests/closure_test.exp @@ -0,0 +1,3 @@ +13 +4 +Operation is not supported by class.