Another closure test comes in.
The build was successful. Details

This commit is contained in:
Rafal Kupiec 2019-04-11 08:58:54 +02:00
parent 31f48b234b
commit 5cc803d07c
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
2 changed files with 39 additions and 0 deletions

36
tests/closure_test.aer Normal file
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
tests/closure_test.exp Normal file
View File

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