Browse Source

Another closure test comes in.

pull/50/head
Rafal Kupiec 1 year ago
parent
commit
5cc803d07c
Signed by: belliash GPG Key ID: 4E829243E0CFE6B4
2 changed files with 39 additions and 0 deletions
  1. +36
    -0
      tests/closure_test.aer
  2. +3
    -0
      tests/closure_test.exp

+ 36
- 0
tests/closure_test.aer View File

@ -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");
}
}

+ 3
- 0
tests/closure_test.exp View File

@ -0,0 +1,3 @@
13
4
Operation is not supported by class.

Loading…
Cancel
Save