Skip to content

Commit 5134c3f

Browse files
committed
Verify first-class callable and PFAs both return Closure instances
1 parent c247e5f commit 5134c3f

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

src/test/php/lang/ast/unittest/emit/CallableSyntaxTest.class.php

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php namespace lang\ast\unittest\emit;
22

3+
use Closure;
34
use lang\Error;
45
use test\verify\Runtime;
56
use test\{Assert, Expect, Test, Values};
@@ -23,33 +24,33 @@ private function verify($code) {
2324
Assert::equals(4, $this->run($code)('Test'));
2425
}
2526

26-
#[Test]
27-
public function native_function_variadic() {
28-
$this->verify('class %T {
29-
public function run() { return strlen(...); }
30-
}');
27+
#[Test, Values(['strlen(...)', 'strlen(?)'])]
28+
public function returns_closure($notation) {
29+
Assert::instance(Closure::class, $this->run('class %T {
30+
public function run() { return '.$notation.'; }
31+
}'));
3132
}
3233

33-
#[Test]
34-
public function native_function_argument() {
34+
#[Test, Values(['strlen(...)', 'strlen(?)'])]
35+
public function native_function($notation) {
3536
$this->verify('class %T {
36-
public function run() { return strlen(?); }
37+
public function run() { return '.$notation.'; }
3738
}');
3839
}
3940

40-
#[Test]
41-
public function instance_method() {
41+
#[Test, Values(['$this->length(...)', '$this->length(?)'])]
42+
public function instance_method($notation) {
4243
$this->verify('class %T {
4344
public function length($arg) { return strlen($arg); }
44-
public function run() { return $this->length(...); }
45+
public function run() { return '.$notation.'; }
4546
}');
4647
}
4748

48-
#[Test]
49-
public function class_method() {
49+
#[Test, Values(['self::length(...)', 'self::length(?)'])]
50+
public function class_method($notation) {
5051
$this->verify('class %T {
5152
public static function length($arg) { return strlen($arg); }
52-
public function run() { return self::length(...); }
53+
public function run() { return '.$notation.'; }
5354
}');
5455
}
5556

@@ -159,8 +160,8 @@ public function run() {
159160
}');
160161
}
161162

162-
#[Test]
163-
public function instantiation_variadic() {
163+
#[Test, Values(['new Handle(...)', 'new Handle(?)'])]
164+
public function instantiation($notation) {
164165
$f= $this->run('use lang\ast\unittest\emit\Handle; class %T {
165166
public function run() {
166167
return new Handle(...);
@@ -169,16 +170,6 @@ public function run() {
169170
Assert::equals(new Handle(1), $f(1));
170171
}
171172

172-
#[Test]
173-
public function instantiation_argument() {
174-
$f= $this->run('use lang\ast\unittest\emit\Handle; class %T {
175-
public function run() {
176-
return new Handle(?);
177-
}
178-
}');
179-
Assert::equals(new Handle(1), $f(1));
180-
}
181-
182173
#[Test]
183174
public function instantiation_in_map() {
184175
$r= $this->run('use lang\ast\unittest\emit\Handle; class %T {

0 commit comments

Comments
 (0)