1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2025-01-22 05:41:23 +01:00

Import some UVS tests

This commit is contained in:
Nikita Popov 2015-06-13 15:42:09 +02:00
parent f372a4c4ab
commit 602b9807eb
10 changed files with 1622 additions and 765 deletions

View File

@ -486,9 +486,7 @@ global_var_list:
;
global_var:
T_VARIABLE { $$ = Expr\Variable[parseVar($1)]; }
| '$' variable { $$ = Expr\Variable[$2]; }
| '$' '{' expr '}' { $$ = Expr\Variable[$3]; }
simple_variable { $$ = Expr\Variable[$1]; }
;
static_var_list:

File diff suppressed because it is too large Load Diff

View File

@ -42,7 +42,7 @@ abstract class CodeTestAbstract extends \PHPUnit_Framework_TestCase
private function extractMode($expected) {
$firstNewLine = strpos($expected, "\n");
if (false === $firstNewLine) {
return [$expected, null];
$firstNewLine = strlen($expected);
}
$firstLine = substr($expected, 0, $firstNewLine);
@ -50,7 +50,8 @@ abstract class CodeTestAbstract extends \PHPUnit_Framework_TestCase
return [$expected, null];
}
return [substr($expected, $firstNewLine + 1), substr($firstLine, 2)];
$expected = (string) substr($expected, $firstNewLine + 1);
return [$expected, substr($firstLine, 2)];
}
protected function canonicalize($str) {

View File

@ -22,16 +22,17 @@ class ParserTest extends CodeTestAbstract
'throwOnError' => false,
));
$output5 = $this->getParseOutput($parser5, $code);
$output7 = $this->getParseOutput($parser7, $code);
if ($mode === 'php5') {
$output5 = $this->getParseOutput($parser5, $code);
$this->assertSame($expected, $output5, $name);
$this->assertNotSame($expected, $output7, $name);
} else if ($mode === 'php7') {
$output7 = $this->getParseOutput($parser7, $code);
$this->assertNotSame($expected, $output5, $name);
$this->assertSame($expected, $output7, $name);
} else {
$output5 = $this->getParseOutput($parser5, $code);
$this->assertSame($expected, $output5, $name);
$output7 = $this->getParseOutput($parser7, $code);
$this->assertSame($expected, $output7, $name);
}
}

View File

@ -0,0 +1,16 @@
Non-simple variables are forbidden in PHP 7
-----
<?php
global $$foo->bar;
-----
!!php7
Syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' from 2:13 to 2:14
array(
0: Expr_ConstFetch(
name: Name(
parts: array(
0: bar
)
)
)
)

View File

@ -0,0 +1,481 @@
UVS indirect calls
-----
<?php
id('var_dump')(1);
id('id')('var_dump')(2);
id()()('var_dump')(4);
id(['udef', 'id'])[1]()('var_dump')(5);
(function($x) { return $x; })('id')('var_dump')(8);
($f = function($x = null) use (&$f) {
return $x ?: $f;
})()()()('var_dump')(9);
[$obj, 'id']()('id')($id)('var_dump')(10);
'id'()('id')('var_dump')(12);
('i' . 'd')()('var_dump')(13);
'\id'('var_dump')(14);
-----
!!php7
array(
0: Expr_FuncCall(
name: Expr_FuncCall(
name: Name(
parts: array(
0: id
)
)
args: array(
0: Arg(
value: Scalar_String(
value: var_dump
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_LNumber(
value: 1
)
byRef: false
unpack: false
)
)
)
1: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Name(
parts: array(
0: id
)
)
args: array(
0: Arg(
value: Scalar_String(
value: id
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_String(
value: var_dump
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_LNumber(
value: 2
)
byRef: false
unpack: false
)
)
)
2: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Name(
parts: array(
0: id
)
)
args: array(
)
)
args: array(
)
)
args: array(
0: Arg(
value: Scalar_String(
value: var_dump
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_LNumber(
value: 4
)
byRef: false
unpack: false
)
)
)
3: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_ArrayDimFetch(
var: Expr_FuncCall(
name: Name(
parts: array(
0: id
)
)
args: array(
0: Arg(
value: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Scalar_String(
value: udef
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Scalar_String(
value: id
)
byRef: false
)
)
)
byRef: false
unpack: false
)
)
)
dim: Scalar_LNumber(
value: 1
)
)
args: array(
)
)
args: array(
0: Arg(
value: Scalar_String(
value: var_dump
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_LNumber(
value: 5
)
byRef: false
unpack: false
)
)
)
4: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_Closure(
static: false
byRef: false
params: array(
0: Param(
type: null
byRef: false
variadic: false
name: x
default: null
)
)
uses: array(
)
returnType: null
stmts: array(
0: Stmt_Return(
expr: Expr_Variable(
name: x
)
)
)
)
args: array(
0: Arg(
value: Scalar_String(
value: id
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_String(
value: var_dump
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_LNumber(
value: 8
)
byRef: false
unpack: false
)
)
)
5: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_Assign(
var: Expr_Variable(
name: f
)
expr: Expr_Closure(
static: false
byRef: false
params: array(
0: Param(
type: null
byRef: false
variadic: false
name: x
default: Expr_ConstFetch(
name: Name(
parts: array(
0: null
)
)
)
)
)
uses: array(
0: Expr_ClosureUse(
var: f
byRef: true
)
)
returnType: null
stmts: array(
0: Stmt_Return(
expr: Expr_Ternary(
cond: Expr_Variable(
name: x
)
if: null
else: Expr_Variable(
name: f
)
)
)
)
)
)
args: array(
)
)
args: array(
)
)
args: array(
)
)
args: array(
0: Arg(
value: Scalar_String(
value: var_dump
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_LNumber(
value: 9
)
byRef: false
unpack: false
)
)
)
6: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: obj
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Scalar_String(
value: id
)
byRef: false
)
)
)
args: array(
)
)
args: array(
0: Arg(
value: Scalar_String(
value: id
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Expr_Variable(
name: id
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_String(
value: var_dump
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_LNumber(
value: 10
)
byRef: false
unpack: false
)
)
)
7: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Scalar_String(
value: id
)
args: array(
)
)
args: array(
0: Arg(
value: Scalar_String(
value: id
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_String(
value: var_dump
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_LNumber(
value: 12
)
byRef: false
unpack: false
)
)
)
8: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_BinaryOp_Concat(
left: Scalar_String(
value: i
)
right: Scalar_String(
value: d
)
)
args: array(
)
)
args: array(
0: Arg(
value: Scalar_String(
value: var_dump
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_LNumber(
value: 13
)
byRef: false
unpack: false
)
)
)
9: Expr_FuncCall(
name: Expr_FuncCall(
name: Scalar_String(
value: \id
)
args: array(
0: Arg(
value: Scalar_String(
value: var_dump
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_LNumber(
value: 14
)
byRef: false
unpack: false
)
)
)
)

View File

@ -0,0 +1,74 @@
UVS isset() on temporaries
-----
<?php
isset(([0, 1] + [])[0]);
isset(['a' => 'b']->a);
isset("str"->a);
-----
!!php7
array(
0: Expr_Isset(
vars: array(
0: Expr_ArrayDimFetch(
var: Expr_BinaryOp_Plus(
left: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 0
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 1
)
byRef: false
)
)
)
right: Expr_Array(
items: array(
)
)
)
dim: Scalar_LNumber(
value: 0
)
)
)
)
1: Expr_Isset(
vars: array(
0: Expr_PropertyFetch(
var: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: Scalar_String(
value: a
)
value: Scalar_String(
value: b
)
byRef: false
)
)
)
name: a
)
)
)
2: Expr_Isset(
vars: array(
0: Expr_PropertyFetch(
var: Scalar_String(
value: str
)
name: a
)
)
)
)

View File

@ -0,0 +1,109 @@
Uniform variable syntax in PHP 7 (misc)
-----
<?php
A::A[0];
A::A[0][1][2];
"string"->length();
(clone $obj)->b[0](1);
[0, 1][0] = 1;
-----
!!php7
array(
0: Expr_ArrayDimFetch(
var: Expr_ClassConstFetch(
class: Name(
parts: array(
0: A
)
)
name: A
)
dim: Scalar_LNumber(
value: 0
)
)
1: Expr_ArrayDimFetch(
var: Expr_ArrayDimFetch(
var: Expr_ArrayDimFetch(
var: Expr_ClassConstFetch(
class: Name(
parts: array(
0: A
)
)
name: A
)
dim: Scalar_LNumber(
value: 0
)
)
dim: Scalar_LNumber(
value: 1
)
)
dim: Scalar_LNumber(
value: 2
)
)
2: Expr_MethodCall(
var: Scalar_String(
value: string
)
name: length
args: array(
)
)
3: Expr_FuncCall(
name: Expr_ArrayDimFetch(
var: Expr_PropertyFetch(
var: Expr_Clone(
expr: Expr_Variable(
name: obj
)
)
name: b
)
dim: Scalar_LNumber(
value: 0
)
)
args: array(
0: Arg(
value: Scalar_LNumber(
value: 1
)
byRef: false
unpack: false
)
)
)
4: Expr_Assign(
var: Expr_ArrayDimFetch(
var: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 0
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 1
)
byRef: false
)
)
)
dim: Scalar_LNumber(
value: 0
)
)
expr: Scalar_LNumber(
value: 1
)
)
)

View File

@ -0,0 +1,95 @@
UVS new expressions
-----
<?php
new $className;
new $array['className'];
new $array{'className'};
new $obj->className;
new Test::$className;
new $test::$className;
new $weird[0]->foo::$className;
-----
!!php7
array(
0: Expr_New(
class: Expr_Variable(
name: className
)
args: array(
)
)
1: Expr_New(
class: Expr_ArrayDimFetch(
var: Expr_Variable(
name: array
)
dim: Scalar_String(
value: className
)
)
args: array(
)
)
2: Expr_New(
class: Expr_ArrayDimFetch(
var: Expr_Variable(
name: array
)
dim: Scalar_String(
value: className
)
)
args: array(
)
)
3: Expr_New(
class: Expr_PropertyFetch(
var: Expr_Variable(
name: obj
)
name: className
)
args: array(
)
)
4: Expr_New(
class: Expr_StaticPropertyFetch(
class: Name(
parts: array(
0: Test
)
)
name: className
)
args: array(
)
)
5: Expr_New(
class: Expr_StaticPropertyFetch(
class: Expr_Variable(
name: test
)
name: className
)
args: array(
)
)
6: Expr_New(
class: Expr_StaticPropertyFetch(
class: Expr_PropertyFetch(
var: Expr_ArrayDimFetch(
var: Expr_Variable(
name: weird
)
dim: Scalar_LNumber(
value: 0
)
)
name: foo
)
name: className
)
args: array(
)
)
)

View File

@ -0,0 +1,93 @@
UVS static access
-----
<?php
A::$b;
$A::$b;
'A'::$b;
('A' . '')::$b;
'A'[0]::$b;
A::$$b;
A::$$c[1];
A::$A::$b;
-----
!!php7
array(
0: Expr_StaticPropertyFetch(
class: Name(
parts: array(
0: A
)
)
name: b
)
1: Expr_StaticPropertyFetch(
class: Expr_Variable(
name: A
)
name: b
)
2: Expr_StaticPropertyFetch(
class: Scalar_String(
value: A
)
name: b
)
3: Expr_StaticPropertyFetch(
class: Expr_BinaryOp_Concat(
left: Scalar_String(
value: A
)
right: Scalar_String(
value:
)
)
name: b
)
4: Expr_StaticPropertyFetch(
class: Expr_ArrayDimFetch(
var: Scalar_String(
value: A
)
dim: Scalar_LNumber(
value: 0
)
)
name: b
)
5: Expr_StaticPropertyFetch(
class: Name(
parts: array(
0: A
)
)
name: Expr_Variable(
name: b
)
)
6: Expr_ArrayDimFetch(
var: Expr_StaticPropertyFetch(
class: Name(
parts: array(
0: A
)
)
name: Expr_Variable(
name: c
)
)
dim: Scalar_LNumber(
value: 1
)
)
7: Expr_StaticPropertyFetch(
class: Expr_StaticPropertyFetch(
class: Name(
parts: array(
0: A
)
)
name: A
)
name: b
)
)