mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-11-27 04:24:43 +01:00
Rename abc1.test to basic.test
And split off fixup.test.
This commit is contained in:
parent
dc3ace55c3
commit
04feb90d79
@ -1,268 +0,0 @@
|
||||
abc1
|
||||
-----
|
||||
<?php
|
||||
echo
|
||||
1
|
||||
+
|
||||
2
|
||||
+
|
||||
3;
|
||||
-----
|
||||
$stmts[0]->exprs[0]->left->right->value = 42;
|
||||
-----
|
||||
<?php
|
||||
echo
|
||||
1
|
||||
+
|
||||
42
|
||||
+
|
||||
3;
|
||||
-----
|
||||
<?php
|
||||
function foo($a)
|
||||
{ return $a; }
|
||||
-----
|
||||
$stmts[0]->name = new Node\Identifier('bar');
|
||||
-----
|
||||
<?php
|
||||
function bar($a)
|
||||
{ return $a; }
|
||||
-----
|
||||
<?php
|
||||
function
|
||||
foo() {
|
||||
call(
|
||||
$bar
|
||||
);
|
||||
}
|
||||
-----
|
||||
// This triggers a fallback
|
||||
$stmts[0]->byRef = true;
|
||||
-----
|
||||
<?php
|
||||
function &foo()
|
||||
{
|
||||
call(
|
||||
$bar
|
||||
);
|
||||
}
|
||||
-----
|
||||
<?php
|
||||
function
|
||||
foo() {
|
||||
echo "Start
|
||||
End";
|
||||
}
|
||||
-----
|
||||
// This triggers a fallback
|
||||
$stmts[0]->byRef = true;
|
||||
-----
|
||||
<?php
|
||||
function &foo()
|
||||
{
|
||||
echo "Start
|
||||
End";
|
||||
}
|
||||
-----
|
||||
<?php
|
||||
function test() {
|
||||
call1(
|
||||
$bar
|
||||
);
|
||||
}
|
||||
call2(
|
||||
$foo
|
||||
);
|
||||
-----
|
||||
$tmp = $stmts[0]->stmts[0];
|
||||
$stmts[0]->stmts[0] = $stmts[1];
|
||||
$stmts[1] = $tmp;
|
||||
-----
|
||||
<?php
|
||||
function test() {
|
||||
call2(
|
||||
$foo
|
||||
);
|
||||
}
|
||||
call1(
|
||||
$bar
|
||||
);
|
||||
-----
|
||||
<?php
|
||||
x;
|
||||
function test() {
|
||||
call1(
|
||||
$bar
|
||||
);
|
||||
}
|
||||
call2(
|
||||
$foo
|
||||
);
|
||||
-----
|
||||
$tmp = $stmts[1]->stmts[0];
|
||||
$stmts[1]->stmts[0] = $stmts[2];
|
||||
$stmts[2] = $tmp;
|
||||
// Same test, but also removing first statement, triggering fallback
|
||||
array_splice($stmts, 0, 1, []);
|
||||
-----
|
||||
<?php
|
||||
|
||||
function test() {
|
||||
call2(
|
||||
$foo
|
||||
);
|
||||
}
|
||||
call1(
|
||||
$bar
|
||||
);
|
||||
-----
|
||||
<?php
|
||||
echo 1;
|
||||
-----
|
||||
$stmts[0] = new Stmt\Expression(
|
||||
new Expr\Assign(new Expr\Variable('a'), new Expr\Variable('b')));
|
||||
-----
|
||||
<?php
|
||||
$a = $b;
|
||||
-----
|
||||
<?php
|
||||
echo$a;
|
||||
-----
|
||||
$stmts[0]->exprs[0] = new Expr\ConstFetch(new Node\Name('C'));
|
||||
-----
|
||||
<?php
|
||||
echo C;
|
||||
-----
|
||||
<?php
|
||||
$a ** $b * $c;
|
||||
$a + $b * $c;
|
||||
$a * $b + $c;
|
||||
$a ? $b : $c;
|
||||
($a ** $b) * $c;
|
||||
( $a ** $b ) * $c;
|
||||
!$a = $b;
|
||||
-----
|
||||
// Parens necessary
|
||||
$stmts[0]->expr->left = new Expr\BinaryOp\Plus(new Expr\Variable('a'), new Expr\Variable('b'));
|
||||
// The parens here are "correct", because add is left assoc
|
||||
$stmts[1]->expr->right = new Expr\BinaryOp\Plus(new Expr\Variable('b'), new Expr\Variable('c'));
|
||||
// No parens necessary
|
||||
$stmts[2]->expr->left = new Expr\BinaryOp\Plus(new Expr\Variable('a'), new Expr\Variable('b'));
|
||||
// Parens for RHS not strictly necessary due to assign speciality
|
||||
$stmts[3]->expr->cond = new Expr\Assign(new Expr\Variable('a'), new Expr\Variable('b'));
|
||||
$stmts[3]->expr->if = new Expr\Assign(new Expr\Variable('a'), new Expr\Variable('b'));
|
||||
$stmts[3]->expr->else = new Expr\Assign(new Expr\Variable('a'), new Expr\Variable('b'));
|
||||
// Already has parens
|
||||
$stmts[4]->expr->left = new Expr\BinaryOp\Plus(new Expr\Variable('a'), new Expr\Variable('b'));
|
||||
$stmts[5]->expr->left = new Expr\BinaryOp\Plus(new Expr\Variable('a'), new Expr\Variable('b'));
|
||||
-----
|
||||
<?php
|
||||
($a + $b) * $c;
|
||||
$a + ($b + $c);
|
||||
$a + $b + $c;
|
||||
($a = $b) ? $a = $b : ($a = $b);
|
||||
($a + $b) * $c;
|
||||
( $a + $b ) * $c;
|
||||
!$a = $b;
|
||||
-----
|
||||
<?php
|
||||
namespace Foo;
|
||||
|
||||
class Bar {}
|
||||
-----
|
||||
/* Nothing */
|
||||
-----
|
||||
<?php
|
||||
namespace Foo;
|
||||
|
||||
class Bar {}
|
||||
-----
|
||||
<?php
|
||||
foo ();
|
||||
foo ();
|
||||
$foo -> bar;
|
||||
$foo -> bar;
|
||||
$foo -> bar;
|
||||
$foo -> bar;
|
||||
$foo -> bar;
|
||||
self :: $foo;
|
||||
self :: $foo;
|
||||
-----
|
||||
$stmts[0]->expr->name = new Expr\Variable('a');
|
||||
$stmts[1]->expr->name = new Expr\BinaryOp\Concat(new Expr\Variable('a'), new Expr\Variable('b'));
|
||||
$stmts[2]->expr->var = new Expr\Variable('bar');
|
||||
$stmts[3]->expr->var = new Expr\BinaryOp\Concat(new Expr\Variable('a'), new Expr\Variable('b'));
|
||||
$stmts[4]->expr->name = new Node\Identifier('foo');
|
||||
// In this case the braces are not strictly necessary. However, on PHP 5 they may be required
|
||||
// depending on where the property fetch node itself occurs.
|
||||
$stmts[5]->expr->name = new Expr\Variable('bar');
|
||||
$stmts[6]->expr->name = new Expr\BinaryOp\Concat(new Expr\Variable('a'), new Expr\Variable('b'));
|
||||
$stmts[7]->expr->name = new Node\VarLikeIdentifier('bar');
|
||||
$stmts[8]->expr->name = new Expr\BinaryOp\Concat(new Expr\Variable('a'), new Expr\Variable('b'));
|
||||
-----
|
||||
<?php
|
||||
$a ();
|
||||
($a . $b) ();
|
||||
$bar -> bar;
|
||||
($a . $b) -> bar;
|
||||
$foo -> foo;
|
||||
$foo -> {$bar};
|
||||
$foo -> {$a . $b};
|
||||
self :: $bar;
|
||||
self :: ${$a . $b};
|
||||
-----
|
||||
<?php
|
||||
function foo() {
|
||||
foo();
|
||||
/*
|
||||
* bar
|
||||
*/
|
||||
baz();
|
||||
}
|
||||
|
||||
{
|
||||
$x;
|
||||
}
|
||||
-----
|
||||
$tmp = $stmts[0];
|
||||
$stmts[0] = $stmts[1];
|
||||
$stmts[1] = $tmp;
|
||||
/* TODO This used to do two replacement operations, but with the node list diffing this is a
|
||||
* remove, keep, add (which probably makes more sense). As such, this currently triggers a
|
||||
* fallback. */
|
||||
-----
|
||||
<?php
|
||||
|
||||
$x;
|
||||
function foo() {
|
||||
foo();
|
||||
/*
|
||||
* bar
|
||||
*/
|
||||
baz();
|
||||
}
|
||||
-----
|
||||
<?php
|
||||
echo "${foo}bar";
|
||||
echo "${foo['baz']}bar";
|
||||
-----
|
||||
$stmts[0]->exprs[0]->parts[0] = new Expr\Variable('bar');
|
||||
$stmts[1]->exprs[0]->parts[0] = new Expr\Variable('bar');
|
||||
-----
|
||||
<?php
|
||||
echo "{$bar}bar";
|
||||
echo "{$bar}bar";
|
||||
-----
|
||||
<?php
|
||||
[$a
|
||||
,$b
|
||||
,
|
||||
,] = $b;
|
||||
-----
|
||||
/* Nothing */
|
||||
-----
|
||||
<?php
|
||||
[$a
|
||||
,$b
|
||||
,
|
||||
,] = $b;
|
190
test/code/formatPreservation/basic.test
Normal file
190
test/code/formatPreservation/basic.test
Normal file
@ -0,0 +1,190 @@
|
||||
abc1
|
||||
-----
|
||||
<?php
|
||||
echo
|
||||
1
|
||||
+
|
||||
2
|
||||
+
|
||||
3;
|
||||
-----
|
||||
$stmts[0]->exprs[0]->left->right->value = 42;
|
||||
-----
|
||||
<?php
|
||||
echo
|
||||
1
|
||||
+
|
||||
42
|
||||
+
|
||||
3;
|
||||
-----
|
||||
<?php
|
||||
function foo($a)
|
||||
{ return $a; }
|
||||
-----
|
||||
$stmts[0]->name = new Node\Identifier('bar');
|
||||
-----
|
||||
<?php
|
||||
function bar($a)
|
||||
{ return $a; }
|
||||
-----
|
||||
<?php
|
||||
function
|
||||
foo() {
|
||||
call(
|
||||
$bar
|
||||
);
|
||||
}
|
||||
-----
|
||||
// This triggers a fallback
|
||||
$stmts[0]->byRef = true;
|
||||
-----
|
||||
<?php
|
||||
function &foo()
|
||||
{
|
||||
call(
|
||||
$bar
|
||||
);
|
||||
}
|
||||
-----
|
||||
<?php
|
||||
function
|
||||
foo() {
|
||||
echo "Start
|
||||
End";
|
||||
}
|
||||
-----
|
||||
// This triggers a fallback
|
||||
$stmts[0]->byRef = true;
|
||||
-----
|
||||
<?php
|
||||
function &foo()
|
||||
{
|
||||
echo "Start
|
||||
End";
|
||||
}
|
||||
-----
|
||||
<?php
|
||||
function test() {
|
||||
call1(
|
||||
$bar
|
||||
);
|
||||
}
|
||||
call2(
|
||||
$foo
|
||||
);
|
||||
-----
|
||||
$tmp = $stmts[0]->stmts[0];
|
||||
$stmts[0]->stmts[0] = $stmts[1];
|
||||
$stmts[1] = $tmp;
|
||||
-----
|
||||
<?php
|
||||
function test() {
|
||||
call2(
|
||||
$foo
|
||||
);
|
||||
}
|
||||
call1(
|
||||
$bar
|
||||
);
|
||||
-----
|
||||
<?php
|
||||
x;
|
||||
function test() {
|
||||
call1(
|
||||
$bar
|
||||
);
|
||||
}
|
||||
call2(
|
||||
$foo
|
||||
);
|
||||
-----
|
||||
$tmp = $stmts[1]->stmts[0];
|
||||
$stmts[1]->stmts[0] = $stmts[2];
|
||||
$stmts[2] = $tmp;
|
||||
// Same test, but also removing first statement, triggering fallback
|
||||
array_splice($stmts, 0, 1, []);
|
||||
-----
|
||||
<?php
|
||||
|
||||
function test() {
|
||||
call2(
|
||||
$foo
|
||||
);
|
||||
}
|
||||
call1(
|
||||
$bar
|
||||
);
|
||||
-----
|
||||
<?php
|
||||
echo 1;
|
||||
-----
|
||||
$stmts[0] = new Stmt\Expression(
|
||||
new Expr\Assign(new Expr\Variable('a'), new Expr\Variable('b')));
|
||||
-----
|
||||
<?php
|
||||
$a = $b;
|
||||
-----
|
||||
<?php
|
||||
echo$a;
|
||||
-----
|
||||
$stmts[0]->exprs[0] = new Expr\ConstFetch(new Node\Name('C'));
|
||||
-----
|
||||
<?php
|
||||
echo C;
|
||||
-----
|
||||
<?php
|
||||
function foo() {
|
||||
foo();
|
||||
/*
|
||||
* bar
|
||||
*/
|
||||
baz();
|
||||
}
|
||||
|
||||
{
|
||||
$x;
|
||||
}
|
||||
-----
|
||||
$tmp = $stmts[0];
|
||||
$stmts[0] = $stmts[1];
|
||||
$stmts[1] = $tmp;
|
||||
/* TODO This used to do two replacement operations, but with the node list diffing this is a
|
||||
* remove, keep, add (which probably makes more sense). As such, this currently triggers a
|
||||
* fallback. */
|
||||
-----
|
||||
<?php
|
||||
|
||||
$x;
|
||||
function foo() {
|
||||
foo();
|
||||
/*
|
||||
* bar
|
||||
*/
|
||||
baz();
|
||||
}
|
||||
-----
|
||||
<?php
|
||||
echo "${foo}bar";
|
||||
echo "${foo['baz']}bar";
|
||||
-----
|
||||
$stmts[0]->exprs[0]->parts[0] = new Expr\Variable('bar');
|
||||
$stmts[1]->exprs[0]->parts[0] = new Expr\Variable('bar');
|
||||
-----
|
||||
<?php
|
||||
echo "{$bar}bar";
|
||||
echo "{$bar}bar";
|
||||
-----
|
||||
<?php
|
||||
[$a
|
||||
,$b
|
||||
,
|
||||
,] = $b;
|
||||
-----
|
||||
/* Nothing */
|
||||
-----
|
||||
<?php
|
||||
[$a
|
||||
,$b
|
||||
,
|
||||
,] = $b;
|
67
test/code/formatPreservation/fixup.test
Normal file
67
test/code/formatPreservation/fixup.test
Normal file
@ -0,0 +1,67 @@
|
||||
Fixup for precedence and some special syntax
|
||||
-----
|
||||
<?php
|
||||
$a ** $b * $c;
|
||||
$a + $b * $c;
|
||||
$a * $b + $c;
|
||||
$a ? $b : $c;
|
||||
($a ** $b) * $c;
|
||||
( $a ** $b ) * $c;
|
||||
!$a = $b;
|
||||
-----
|
||||
// Parens necessary
|
||||
$stmts[0]->expr->left = new Expr\BinaryOp\Plus(new Expr\Variable('a'), new Expr\Variable('b'));
|
||||
// The parens here are "correct", because add is left assoc
|
||||
$stmts[1]->expr->right = new Expr\BinaryOp\Plus(new Expr\Variable('b'), new Expr\Variable('c'));
|
||||
// No parens necessary
|
||||
$stmts[2]->expr->left = new Expr\BinaryOp\Plus(new Expr\Variable('a'), new Expr\Variable('b'));
|
||||
// Parens for RHS not strictly necessary due to assign speciality
|
||||
$stmts[3]->expr->cond = new Expr\Assign(new Expr\Variable('a'), new Expr\Variable('b'));
|
||||
$stmts[3]->expr->if = new Expr\Assign(new Expr\Variable('a'), new Expr\Variable('b'));
|
||||
$stmts[3]->expr->else = new Expr\Assign(new Expr\Variable('a'), new Expr\Variable('b'));
|
||||
// Already has parens
|
||||
$stmts[4]->expr->left = new Expr\BinaryOp\Plus(new Expr\Variable('a'), new Expr\Variable('b'));
|
||||
$stmts[5]->expr->left = new Expr\BinaryOp\Plus(new Expr\Variable('a'), new Expr\Variable('b'));
|
||||
-----
|
||||
<?php
|
||||
($a + $b) * $c;
|
||||
$a + ($b + $c);
|
||||
$a + $b + $c;
|
||||
($a = $b) ? $a = $b : ($a = $b);
|
||||
($a + $b) * $c;
|
||||
( $a + $b ) * $c;
|
||||
!$a = $b;
|
||||
-----
|
||||
<?php
|
||||
foo ();
|
||||
foo ();
|
||||
$foo -> bar;
|
||||
$foo -> bar;
|
||||
$foo -> bar;
|
||||
$foo -> bar;
|
||||
$foo -> bar;
|
||||
self :: $foo;
|
||||
self :: $foo;
|
||||
-----
|
||||
$stmts[0]->expr->name = new Expr\Variable('a');
|
||||
$stmts[1]->expr->name = new Expr\BinaryOp\Concat(new Expr\Variable('a'), new Expr\Variable('b'));
|
||||
$stmts[2]->expr->var = new Expr\Variable('bar');
|
||||
$stmts[3]->expr->var = new Expr\BinaryOp\Concat(new Expr\Variable('a'), new Expr\Variable('b'));
|
||||
$stmts[4]->expr->name = new Node\Identifier('foo');
|
||||
// In this case the braces are not strictly necessary. However, on PHP 5 they may be required
|
||||
// depending on where the property fetch node itself occurs.
|
||||
$stmts[5]->expr->name = new Expr\Variable('bar');
|
||||
$stmts[6]->expr->name = new Expr\BinaryOp\Concat(new Expr\Variable('a'), new Expr\Variable('b'));
|
||||
$stmts[7]->expr->name = new Node\VarLikeIdentifier('bar');
|
||||
$stmts[8]->expr->name = new Expr\BinaryOp\Concat(new Expr\Variable('a'), new Expr\Variable('b'));
|
||||
-----
|
||||
<?php
|
||||
$a ();
|
||||
($a . $b) ();
|
||||
$bar -> bar;
|
||||
($a . $b) -> bar;
|
||||
$foo -> foo;
|
||||
$foo -> {$bar};
|
||||
$foo -> {$a . $b};
|
||||
self :: $bar;
|
||||
self :: ${$a . $b};
|
Loading…
Reference in New Issue
Block a user