Skip to content

Commit

Permalink
Add tests for non-constant parameter defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Nov 2, 2024
1 parent 4d0ded8 commit 11b7f1a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/test/php/lang/ast/unittest/emit/ParameterTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use lang\{ArrayType, MapType, Primitive, Type, Value, XPClass};
use test\verify\Runtime;
use test\{Action, Assert, Test, Values};
use util\Binford;

class ParameterTest extends EmittingTest {
use AnnotationsOf, NullableSupport;
Expand All @@ -14,7 +15,7 @@ class ParameterTest extends EmittingTest {
* @return lang.reflection.Parameter
*/
private function param($declaration) {
return $this->declare('use lang\Value; class %T { public function fixture('.$declaration.') { } }')
return $this->declare('use lang\Value; use util\Binford; class %T { public function fixture('.$declaration.') { } }')
->method('fixture')
->parameter(0)
;
Expand Down Expand Up @@ -122,6 +123,18 @@ public function optional_parameters_default_value() {
Assert::equals(true, $this->param('$param= true')->default());
}

#[Test]
public function new_as_default() {
$power= $this->param('$power= new Binford(6100)')->default();
Assert::equals(new Binford(6100), $power);
}

#[Test]
public function closure_as_default() {
$function= $this->param('$op= fn($in) => $in * 2')->default();
Assert::equals(2, $function(1));
}

#[Test]
public function trailing_comma_allowed() {
$p= $this->declare('class %T { public function fixture($param, ) { } }')
Expand Down

0 comments on commit 11b7f1a

Please sign in to comment.