|
4 | 4 | use unittest\{Assert, Expect, Test, Values};
|
5 | 5 |
|
6 | 6 | /**
|
7 |
| - * New in initializers |
| 7 | + * Initialize parameters and properties with arbitrary expressions |
8 | 8 | *
|
| 9 | + * @see https://github.com/xp-framework/compiler/pull/104 |
9 | 10 | * @see https://wiki.php.net/rfc/new_in_initializers
|
10 | 11 | */
|
11 |
| -class InitializeWithNewTest extends EmittingTest { |
| 12 | +class InitializeWithExpressionsTest extends EmittingTest { |
| 13 | + |
| 14 | + /** @return iterable */ |
| 15 | + private function expressions() { |
| 16 | + yield ['"test"', 'test']; |
| 17 | + yield ['[1, 2, 3]', [1, 2, 3]]; |
| 18 | + yield ['MODIFIER_PUBLIC', MODIFIER_PUBLIC]; |
| 19 | + yield ['self::INITIAL', 'initial']; |
| 20 | + yield ['Handle::$DEFAULT', Handle::$DEFAULT]; |
| 21 | + yield ['new Handle(0)', new Handle(0)]; |
| 22 | + yield ['[new Handle(0)]', [new Handle(0)]]; |
| 23 | + } |
12 | 24 |
|
13 |
| - #[Test] |
14 |
| - public function property() { |
15 |
| - $r= $this->run('use lang\ast\unittest\emit\Handle; class <T> { |
16 |
| - private $h= new Handle(0); |
| 25 | + #[Test, Values('expressions')] |
| 26 | + public function property($code, $expected) { |
| 27 | + Assert::equals($expected, $this->run(sprintf('use lang\ast\unittest\emit\Handle; class <T> { |
| 28 | + const INITIAL= "initial"; |
| 29 | + private $h= %s; |
17 | 30 |
|
18 | 31 | public function run() {
|
19 | 32 | return $this->h;
|
20 | 33 | }
|
21 |
| - }'); |
22 |
| - Assert::equals(new Handle(0), $r); |
| 34 | + }', $code))); |
23 | 35 | }
|
24 | 36 |
|
25 | 37 | #[Test]
|
|
0 commit comments