File tree Expand file tree Collapse file tree 2 files changed +83
-0
lines changed
test/php/lang/ast/unittest/emit Expand file tree Collapse file tree 2 files changed +83
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php namespace lang \ast \emit ;
2
+
3
+ use lang \ast \types \{
4
+ IsArray ,
5
+ IsFunction ,
6
+ IsGeneric ,
7
+ IsIntersection ,
8
+ IsLiteral ,
9
+ IsMap ,
10
+ IsNullable ,
11
+ IsUnion ,
12
+ IsValue
13
+ };
14
+
15
+ /**
16
+ * PHP 8.5 syntax
17
+ *
18
+ * @test lang.ast.unittest.emit.PHP85Test
19
+ * @see https://wiki.php.net/rfc#php_85
20
+ */
21
+ class PHP85 extends PHP {
22
+ use RewriteBlockLambdaExpressions;
23
+
24
+ public $ targetVersion = 80500 ;
25
+
26
+ /** Sets up type => literal mappings */
27
+ public function __construct () {
28
+ $ this ->literals = [
29
+ IsArray::class => function ($ t ) { return 'array ' ; },
30
+ IsMap::class => function ($ t ) { return 'array ' ; },
31
+ IsFunction::class => function ($ t ) { return 'callable ' ; },
32
+ IsValue::class => function ($ t ) { return $ t ->literal (); },
33
+ IsNullable::class => function ($ t ) {
34
+ if (null === ($ l = $ this ->literal ($ t ->element ))) return null ;
35
+ return $ t ->element instanceof IsUnion ? $ l .'|null ' : '? ' .$ l ;
36
+ },
37
+ IsIntersection::class => function ($ t ) {
38
+ $ i = '' ;
39
+ foreach ($ t ->components as $ component ) {
40
+ if (null === ($ l = $ this ->literal ($ component ))) return null ;
41
+ $ i .= '& ' .$ l ;
42
+ }
43
+ return substr ($ i , 1 );
44
+ },
45
+ IsUnion::class => function ($ t ) {
46
+ $ u = '' ;
47
+ foreach ($ t ->components as $ component ) {
48
+ if (null === ($ l = $ this ->literal ($ component ))) return null ;
49
+ $ u .= '| ' .$ l ;
50
+ }
51
+ return substr ($ u , 1 );
52
+ },
53
+ IsLiteral::class => function ($ t ) { return $ t ->literal (); },
54
+ IsGeneric::class => function ($ t ) { return null ; }
55
+ ];
56
+ }
57
+ }
Original file line number Diff line number Diff line change
1
+ <?php namespace lang \ast \unittest \emit ;
2
+
3
+ use lang \ast \emit \Type ;
4
+ use test \{Assert , Test };
5
+
6
+ class PHP85Test extends EmittingTest {
7
+
8
+ /** @return string */
9
+ protected function runtime () { return 'php:8.5.0 ' ; }
10
+
11
+ #[Test]
12
+ public function pipe_operator () {
13
+ Assert::equals (
14
+ '"test"|>strtoupper(...); ' ,
15
+ $ this ->emit ('"test" |> strtoupper(...); ' )
16
+ );
17
+ }
18
+
19
+ #[Test]
20
+ public function nullsafepipe_operator () {
21
+ Assert::equals (
22
+ 'null===($_0="test")?null:$_0|>strtoupper(...); ' ,
23
+ $ this ->emit ('"test" ?|> strtoupper(...); ' )
24
+ );
25
+ }
26
+ }
You can’t perform that action at this time.
0 commit comments