refactoring: update php7 tests
This commit is contained in:
parent
7b8b1ce7b9
commit
fd984fea8f
File diff suppressed because it is too large
Load Diff
BIN
internal/php7/php7.go
generated
BIN
internal/php7/php7.go
generated
Binary file not shown.
@ -541,7 +541,9 @@ use_type:
|
||||
group_use_declaration:
|
||||
namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations possible_comma '}'
|
||||
{
|
||||
$4.(*ast.ParserSeparatedList).SeparatorTkns = append($4.(*ast.ParserSeparatedList).SeparatorTkns, $5)
|
||||
if $5 != nil {
|
||||
$4.(*ast.ParserSeparatedList).SeparatorTkns = append($4.(*ast.ParserSeparatedList).SeparatorTkns, $5)
|
||||
}
|
||||
|
||||
$$ = &ast.StmtGroupUse{
|
||||
Position: yylex.(*Parser).builder.NewNodeListTokenPosition($1.(*ast.ParserSeparatedList).Items, $6),
|
||||
@ -559,7 +561,9 @@ group_use_declaration:
|
||||
}
|
||||
| T_NS_SEPARATOR namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations possible_comma '}'
|
||||
{
|
||||
$5.(*ast.ParserSeparatedList).SeparatorTkns = append($5.(*ast.ParserSeparatedList).SeparatorTkns, $6)
|
||||
if $6 != nil {
|
||||
$5.(*ast.ParserSeparatedList).SeparatorTkns = append($5.(*ast.ParserSeparatedList).SeparatorTkns, $6)
|
||||
}
|
||||
|
||||
$$ = &ast.StmtGroupUse{
|
||||
Position: yylex.(*Parser).builder.NewTokensPosition($1, $7),
|
||||
|
@ -1,6 +1,7 @@
|
||||
package php7_test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
"github.com/z7zmey/php-parser/internal/php7"
|
||||
@ -8,381 +9,14 @@ import (
|
||||
)
|
||||
|
||||
func BenchmarkPhp7(b *testing.B) {
|
||||
src := `<?
|
||||
foo($a, ...$b);
|
||||
$foo($a, ...$b);
|
||||
$foo->bar($a, ...$b);
|
||||
foo::bar($a, ...$b);
|
||||
$foo::bar($a, ...$b);
|
||||
new foo($a, ...$b);
|
||||
/** anonymous class */
|
||||
new class ($a, ...$b) {};
|
||||
new class {};
|
||||
new $foo;
|
||||
new $foo[1];
|
||||
new $foo{$bar};
|
||||
new $foo->bar;
|
||||
new $foo::$bar;
|
||||
new static::$bar;
|
||||
src, err := ioutil.ReadFile("test.php")
|
||||
|
||||
function foo(?bar $bar=null, baz &...$baz) {}
|
||||
class foo {public function foo(?bar $bar=null, baz &...$baz) {}}
|
||||
function(?bar $bar=null, baz &...$baz) {};
|
||||
static function(?bar $bar=null, baz &...$baz) {};
|
||||
|
||||
"test";
|
||||
"\$test";
|
||||
"
|
||||
test
|
||||
";
|
||||
'$test';
|
||||
'
|
||||
$test
|
||||
';
|
||||
<<<CAD
|
||||
CAD;
|
||||
<<<CAD
|
||||
hello
|
||||
CAD;
|
||||
<<<"CAD"
|
||||
hello
|
||||
CAD;
|
||||
<<<"CAD"
|
||||
hello $world
|
||||
CAD;
|
||||
<<<'CAD'
|
||||
hello $world
|
||||
CAD;
|
||||
|
||||
1234567890123456789;
|
||||
12345678901234567890;
|
||||
0.;
|
||||
0b0111111111111111111111111111111111111111111111111111111111111111;
|
||||
0b1111111111111111111111111111111111111111111111111111111111111111;
|
||||
0x007111111111111111;
|
||||
0x8111111111111111;
|
||||
__CLASS__;
|
||||
__DIR__;
|
||||
__FILE__;
|
||||
__FUNCTION__;
|
||||
__LINE__;
|
||||
__NAMESPACE__;
|
||||
__METHOD__;
|
||||
__TRAIT__;
|
||||
|
||||
"test $var";
|
||||
"test $var[1]";
|
||||
"test $var[-1]";
|
||||
"test $var[1234567890123456789012345678901234567890]";
|
||||
"test $var[-1234567890123456789012345678901234567890]";
|
||||
"test $var[bar]";
|
||||
"test $var[$bar]";
|
||||
"$foo $bar";
|
||||
"test $foo->bar()";
|
||||
"test ${foo}";
|
||||
"test ${foo[0]}";
|
||||
"test ${$foo}";
|
||||
"test {$foo->bar()}";
|
||||
|
||||
if ($a) :
|
||||
endif;
|
||||
if ($a) :
|
||||
elseif ($b):
|
||||
endif;
|
||||
if ($a) :
|
||||
else:
|
||||
endif;
|
||||
if ($a) :
|
||||
elseif ($b):
|
||||
elseif ($c):
|
||||
else:
|
||||
endif;
|
||||
|
||||
while (1) { break; }
|
||||
while (1) { break 2; }
|
||||
while (1) : break(3); endwhile;
|
||||
class foo{ public const FOO = 1, BAR = 2; }
|
||||
class foo{ const FOO = 1, BAR = 2; }
|
||||
class foo{ function bar() {} }
|
||||
class foo{ public static function &bar() {} }
|
||||
class foo{ public static function &bar(): void {} }
|
||||
abstract class foo{ }
|
||||
final class foo extends bar { }
|
||||
final class foo implements bar { }
|
||||
final class foo implements bar, baz { }
|
||||
new class() extends foo implements bar, baz { };
|
||||
|
||||
const FOO = 1, BAR = 2;
|
||||
while (1) { continue; }
|
||||
while (1) { continue 2; }
|
||||
while (1) { continue(3); }
|
||||
declare(ticks=1);
|
||||
declare(ticks=1) {}
|
||||
declare(ticks=1): enddeclare;
|
||||
do {} while(1);
|
||||
echo $a, 1;
|
||||
echo($a);
|
||||
for($i = 0; $i < 10; $i++, $i++) {}
|
||||
for(; $i < 10; $i++, $i++) : endfor;
|
||||
foreach ($a as $v) {}
|
||||
foreach ($a as $v) : endforeach;
|
||||
foreach ($a as $k => $v) {}
|
||||
foreach ($a as $k => &$v) {}
|
||||
foreach ($a as $k => list($v)) {}
|
||||
foreach ($a as $k => [$v]) {}
|
||||
function foo() {}
|
||||
function foo() {return;}
|
||||
function &foo() {return 1;}
|
||||
function &foo(): void {}
|
||||
global $a, $b;
|
||||
a:
|
||||
goto a;
|
||||
__halt_compiler();
|
||||
if ($a) {}
|
||||
if ($a) {} elseif ($b) {}
|
||||
if ($a) {} else {}
|
||||
if ($a) {} elseif ($b) {} elseif ($c) {} else {}
|
||||
if ($a) {} elseif ($b) {} else if ($c) {} else {}
|
||||
?> <div></div> <?
|
||||
interface Foo {}
|
||||
interface Foo extends Bar {}
|
||||
interface Foo extends Bar, Baz {}
|
||||
namespace Foo;
|
||||
namespace Foo {}
|
||||
namespace {}
|
||||
class foo {var $a;}
|
||||
class foo {public static $a, $b = 1;}
|
||||
static $a, $b = 1;
|
||||
|
||||
switch (1) :
|
||||
case 1:
|
||||
default:
|
||||
case 2:
|
||||
endswitch;
|
||||
|
||||
switch (1) :;
|
||||
case 1;
|
||||
case 2;
|
||||
endswitch;
|
||||
|
||||
switch (1) {
|
||||
case 1: break;
|
||||
case 2: break;
|
||||
}
|
||||
|
||||
switch (1) {;
|
||||
case 1; break;
|
||||
case 2; break;
|
||||
}
|
||||
|
||||
throw $e;
|
||||
|
||||
trait Foo {}
|
||||
class Foo { use Bar; }
|
||||
class Foo { use Bar, Baz {} }
|
||||
class Foo { use Bar, Baz { one as include; } }
|
||||
class Foo { use Bar, Baz { one as public; } }
|
||||
class Foo { use Bar, Baz { one as public two; } }
|
||||
class Foo { use Bar, Baz { Bar::one insteadof Baz, Quux; Baz::one as two; } }
|
||||
|
||||
try {}
|
||||
try {} catch (Exception $e) {}
|
||||
try {} catch (Exception|RuntimeException $e) {}
|
||||
try {} catch (Exception $e) {} catch (RuntimeException $e) {}
|
||||
try {} catch (Exception $e) {} finally {}
|
||||
|
||||
unset($a, $b,);
|
||||
|
||||
use Foo;
|
||||
use \Foo;
|
||||
use \Foo as Bar;
|
||||
use Foo, Bar;
|
||||
use Foo, Bar as Baz;
|
||||
use function Foo, \Bar;
|
||||
use function Foo as foo, \Bar as bar;
|
||||
use const Foo, \Bar;
|
||||
use const Foo as foo, \Bar as bar;
|
||||
|
||||
use \Foo\{Bar, Baz};
|
||||
use Foo\{Bar, Baz as quux};
|
||||
use function Foo\{Bar, Baz};
|
||||
use const \Foo\{Bar, Baz};
|
||||
use Foo\{const Bar, function Baz};
|
||||
|
||||
$a[1];
|
||||
$a[1][2];
|
||||
array();
|
||||
array(1);
|
||||
array(1=>1, &$b,);
|
||||
~$a;
|
||||
!$a;
|
||||
|
||||
Foo::Bar;
|
||||
$foo::Bar;
|
||||
clone($a);
|
||||
clone $a;
|
||||
function(){};
|
||||
function($a, $b) use ($c, &$d) {};
|
||||
function(): void {};
|
||||
foo;
|
||||
namespace\foo;
|
||||
\foo;
|
||||
|
||||
empty($a);
|
||||
@$a;
|
||||
eval($a);
|
||||
exit;
|
||||
exit($a);
|
||||
die;
|
||||
die($a);
|
||||
foo();
|
||||
namespace\foo();
|
||||
\foo();
|
||||
$foo();
|
||||
|
||||
$a--;
|
||||
$a++;
|
||||
--$a;
|
||||
++$a;
|
||||
|
||||
include $a;
|
||||
include_once $a;
|
||||
require $a;
|
||||
require_once $a;
|
||||
|
||||
$a instanceof Foo;
|
||||
$a instanceof namespace\Foo;
|
||||
$a instanceof \Foo;
|
||||
|
||||
isset($a, $b);
|
||||
list($a) = $b;
|
||||
list($a[]) = $b;
|
||||
list(list($a)) = $b;
|
||||
|
||||
$a->foo();
|
||||
new Foo();
|
||||
new namespace\Foo();
|
||||
new \Foo();
|
||||
new class ($a, ...$b) {};
|
||||
print($a);
|
||||
$a->foo;
|
||||
` + "`cmd $a`;" + `
|
||||
` + "`cmd`;" + `
|
||||
` + "``;" + `
|
||||
[];
|
||||
[1];
|
||||
[1=>1, &$b,];
|
||||
|
||||
[$a] = $b;
|
||||
[$a[]] = $b;
|
||||
[list($a)] = $b;
|
||||
Foo::bar();
|
||||
namespace\Foo::bar();
|
||||
\Foo::bar();
|
||||
Foo::$bar;
|
||||
$foo::$bar;
|
||||
namespace\Foo::$bar;
|
||||
\Foo::$bar;
|
||||
$a ? $b : $c;
|
||||
$a ? : $c;
|
||||
$a ? $b ? $c : $d : $e;
|
||||
$a ? $b : $c ? $d : $e;
|
||||
-$a;
|
||||
+$a;
|
||||
$$a;
|
||||
yield;
|
||||
yield $a;
|
||||
yield $a => $b;
|
||||
yield from $a;
|
||||
|
||||
(array)$a;
|
||||
(boolean)$a;
|
||||
(bool)$a;
|
||||
(double)$a;
|
||||
(float)$a;
|
||||
(integer)$a;
|
||||
(int)$a;
|
||||
(object)$a;
|
||||
(string)$a;
|
||||
(unset)$a;
|
||||
|
||||
$a & $b;
|
||||
$a | $b;
|
||||
$a ^ $b;
|
||||
$a && $b;
|
||||
$a || $b;
|
||||
$a ?? $b;
|
||||
$a . $b;
|
||||
$a / $b;
|
||||
$a == $b;
|
||||
$a >= $b;
|
||||
$a > $b;
|
||||
$a === $b;
|
||||
$a and $b;
|
||||
$a or $b;
|
||||
$a xor $b;
|
||||
$a - $b;
|
||||
$a % $b;
|
||||
$a * $b;
|
||||
$a != $b;
|
||||
$a !== $b;
|
||||
$a + $b;
|
||||
$a ** $b;
|
||||
$a << $b;
|
||||
$a >> $b;
|
||||
$a <= $b;
|
||||
$a < $b;
|
||||
$a <=> $b;
|
||||
|
||||
$a =& $b;
|
||||
$a = $b;
|
||||
$a &= $b;
|
||||
$a |= $b;
|
||||
$a ^= $b;
|
||||
$a .= $b;
|
||||
$a /= $b;
|
||||
$a -= $b;
|
||||
$a %= $b;
|
||||
$a *= $b;
|
||||
$a += $b;
|
||||
$a **= $b;
|
||||
$a <<= $b;
|
||||
$a >>= $b;
|
||||
|
||||
class foo {public function class() {} }
|
||||
\foo\bar();
|
||||
|
||||
function foo(&$a, ...$b) {
|
||||
__halt_compiler();
|
||||
function bar() {}
|
||||
class Baz {}
|
||||
trait Quux{}
|
||||
interface Quuux {}
|
||||
}
|
||||
|
||||
function foo(&$a = 1, ...$b = 1, $c = 1) {}
|
||||
function foo(array $a, callable $b) {}
|
||||
abstract final class foo { abstract protected static function bar(); final private function baz() {} }
|
||||
|
||||
(new Foo)->bar;
|
||||
(new Foo)();
|
||||
[$foo][0]();
|
||||
foo[1]();
|
||||
"foo"();
|
||||
[1]{$foo}();
|
||||
${foo()};
|
||||
|
||||
Foo::$bar();
|
||||
Foo::{$bar[0]}();
|
||||
|
||||
$foo->$bar;
|
||||
$foo->{$bar[0]};
|
||||
|
||||
[1=>&$a, 2=>list($b)];
|
||||
`
|
||||
if err != nil {
|
||||
b.Fatal("can not read test.php: " + err.Error())
|
||||
}
|
||||
|
||||
for n := 0; n < b.N; n++ {
|
||||
lexer := scanner.NewLexer([]byte(src), "7.4", nil)
|
||||
lexer := scanner.NewLexer(src, "7.4", nil)
|
||||
php7parser := php7.NewParser(lexer, nil)
|
||||
php7parser.Parse()
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user