Skip to content

Commit f8cef2a

Browse files
tpuntnikic
authored andcommitted
Added tests
1 parent da3e071 commit f8cef2a

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

ast.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static void ast_to_zval(zval *zv, zend_ast *ast, zend_long version) {
210210
}
211211
}
212212

213-
if (version >= 30) { // assumes 30 will be next version bump
213+
if (version >= 30) {
214214
switch (ast->kind) {
215215
case ZEND_AST_SILENCE:
216216
ast->kind = ZEND_AST_UNARY_OP;
@@ -300,7 +300,7 @@ static void ast_to_zval(zval *zv, zend_ast *ast, zend_long version) {
300300
}
301301

302302
static int ast_check_version(zend_long version) {
303-
if (version == 10 || version == 20 || version == 30) { // next version assumption
303+
if (version == 10 || version == 20 || version == 30) {
304304
return SUCCESS;
305305
}
306306

tests/unary_ops.phpt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
Convert unary ops AST_(SILENCE|UNARY_(PLUS|MINUS)) to flags of ZEND_AST_UNARY_OP
3+
--FILE--
4+
<?php
5+
6+
require __DIR__ . '/../util.php';
7+
8+
$code = <<<'PHP'
9+
<?php
10+
@$a;
11+
+1;
12+
-1;
13+
PHP;
14+
15+
echo ast_dump(ast\parse_code($code, $version=20)), "\n";
16+
echo ast_dump(ast\parse_code($code, $version=30)), "\n";
17+
18+
?>
19+
--EXPECT--
20+
AST_STMT_LIST
21+
0: AST_SILENCE
22+
0: AST_VAR
23+
0: "a"
24+
1: AST_UNARY_PLUS
25+
0: 1
26+
2: AST_UNARY_MINUS
27+
0: 1
28+
AST_STMT_LIST
29+
0: AST_UNARY_OP
30+
flags: 258
31+
0: AST_VAR
32+
0: "a"
33+
1: AST_UNARY_OP
34+
flags: 259
35+
0: 1
36+
2: AST_UNARY_OP
37+
flags: 260
38+
0: 1

0 commit comments

Comments
 (0)