2018-02-08 16:42:01 +00:00
|
|
|
package stmt_test
|
|
|
|
|
|
|
|
import (
|
2018-02-19 11:00:58 +00:00
|
|
|
"bytes"
|
2018-06-24 07:19:44 +00:00
|
|
|
"testing"
|
|
|
|
|
2018-02-08 16:42:01 +00:00
|
|
|
"github.com/z7zmey/php-parser/node/expr"
|
|
|
|
"github.com/z7zmey/php-parser/node/name"
|
2018-06-24 07:19:44 +00:00
|
|
|
"github.com/z7zmey/php-parser/position"
|
2018-02-08 16:42:01 +00:00
|
|
|
|
|
|
|
"github.com/z7zmey/php-parser/node"
|
|
|
|
"github.com/z7zmey/php-parser/node/stmt"
|
|
|
|
"github.com/z7zmey/php-parser/php5"
|
|
|
|
"github.com/z7zmey/php-parser/php7"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestTry(t *testing.T) {
|
|
|
|
src := `<?
|
|
|
|
try {}
|
|
|
|
`
|
|
|
|
|
2018-05-02 09:14:24 +00:00
|
|
|
expected := &node.Root{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: -1,
|
|
|
|
StartPos: 7,
|
|
|
|
EndPos: -1,
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.Try{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: -1,
|
|
|
|
StartPos: 7,
|
|
|
|
EndPos: -1,
|
|
|
|
},
|
2018-02-19 11:00:58 +00:00
|
|
|
Stmts: []node.Node{},
|
2018-02-08 16:42:01 +00:00
|
|
|
Catches: []node.Node{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php7parser.Parse()
|
|
|
|
actual := php7parser.GetRootNode()
|
2018-02-08 16:42:01 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php5parser.Parse()
|
|
|
|
actual = php5parser.GetRootNode()
|
2018-02-08 16:42:01 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTryCatch(t *testing.T) {
|
|
|
|
src := `<?
|
|
|
|
try {} catch (Exception $e) {}
|
|
|
|
`
|
|
|
|
|
2018-05-02 09:14:24 +00:00
|
|
|
expected := &node.Root{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 7,
|
|
|
|
EndPos: 36,
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.Try{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 7,
|
|
|
|
EndPos: 36,
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
Stmts: []node.Node{},
|
|
|
|
Catches: []node.Node{
|
|
|
|
&stmt.Catch{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 14,
|
|
|
|
EndPos: 36,
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
Types: []node.Node{
|
|
|
|
&name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 21,
|
|
|
|
EndPos: 29,
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 21,
|
|
|
|
EndPos: 29,
|
|
|
|
},
|
|
|
|
Value: "Exception",
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 31,
|
|
|
|
EndPos: 32,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 31,
|
|
|
|
EndPos: 32,
|
|
|
|
},
|
|
|
|
Value: "e",
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
},
|
|
|
|
Stmts: []node.Node{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php7parser.Parse()
|
|
|
|
actual := php7parser.GetRootNode()
|
2018-02-08 16:42:01 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php5parser.Parse()
|
|
|
|
actual = php5parser.GetRootNode()
|
2018-02-08 16:42:01 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhp7TryCatch(t *testing.T) {
|
|
|
|
src := `<?
|
|
|
|
try {} catch (Exception|RuntimeException $e) {}
|
|
|
|
`
|
|
|
|
|
2018-05-02 09:14:24 +00:00
|
|
|
expected := &node.Root{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 7,
|
|
|
|
EndPos: 53,
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.Try{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 7,
|
|
|
|
EndPos: 53,
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
Stmts: []node.Node{},
|
|
|
|
Catches: []node.Node{
|
|
|
|
&stmt.Catch{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 14,
|
|
|
|
EndPos: 53,
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
Types: []node.Node{
|
|
|
|
&name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 21,
|
|
|
|
EndPos: 29,
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 21,
|
|
|
|
EndPos: 29,
|
|
|
|
},
|
|
|
|
Value: "Exception",
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
&name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 31,
|
|
|
|
EndPos: 46,
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 31,
|
|
|
|
EndPos: 46,
|
|
|
|
},
|
|
|
|
Value: "RuntimeException",
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 48,
|
|
|
|
EndPos: 49,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 48,
|
|
|
|
EndPos: 49,
|
|
|
|
},
|
|
|
|
Value: "e",
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
},
|
|
|
|
Stmts: []node.Node{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php7parser.Parse()
|
|
|
|
actual := php7parser.GetRootNode()
|
2018-02-08 16:42:01 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTryCatchCatch(t *testing.T) {
|
|
|
|
src := `<?
|
|
|
|
try {} catch (Exception $e) {} catch (RuntimeException $e) {}
|
|
|
|
`
|
|
|
|
|
2018-05-02 09:14:24 +00:00
|
|
|
expected := &node.Root{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 7,
|
|
|
|
EndPos: 67,
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.Try{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 7,
|
|
|
|
EndPos: 67,
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
Stmts: []node.Node{},
|
|
|
|
Catches: []node.Node{
|
|
|
|
&stmt.Catch{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 14,
|
|
|
|
EndPos: 36,
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
Types: []node.Node{
|
|
|
|
&name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 21,
|
|
|
|
EndPos: 29,
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 21,
|
|
|
|
EndPos: 29,
|
|
|
|
},
|
|
|
|
Value: "Exception",
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 31,
|
|
|
|
EndPos: 32,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 31,
|
|
|
|
EndPos: 32,
|
|
|
|
},
|
|
|
|
Value: "e",
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
},
|
|
|
|
Stmts: []node.Node{},
|
|
|
|
},
|
|
|
|
&stmt.Catch{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 38,
|
|
|
|
EndPos: 67,
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
Types: []node.Node{
|
|
|
|
&name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 45,
|
|
|
|
EndPos: 60,
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 45,
|
|
|
|
EndPos: 60,
|
|
|
|
},
|
|
|
|
Value: "RuntimeException",
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 62,
|
|
|
|
EndPos: 63,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 62,
|
|
|
|
EndPos: 63,
|
|
|
|
},
|
|
|
|
Value: "e",
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
},
|
|
|
|
Stmts: []node.Node{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php7parser.Parse()
|
|
|
|
actual := php7parser.GetRootNode()
|
2018-02-08 16:42:01 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php5parser.Parse()
|
|
|
|
actual = php5parser.GetRootNode()
|
2018-02-08 16:42:01 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTryCatchFinally(t *testing.T) {
|
|
|
|
src := `<?
|
|
|
|
try {} catch (Exception $e) {} finally {}
|
|
|
|
`
|
|
|
|
|
2018-05-02 09:14:24 +00:00
|
|
|
expected := &node.Root{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 7,
|
|
|
|
EndPos: 47,
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.Try{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 7,
|
|
|
|
EndPos: 47,
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
Stmts: []node.Node{},
|
|
|
|
Catches: []node.Node{
|
|
|
|
&stmt.Catch{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 14,
|
|
|
|
EndPos: 36,
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
Types: []node.Node{
|
|
|
|
&name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 21,
|
|
|
|
EndPos: 29,
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 21,
|
|
|
|
EndPos: 29,
|
|
|
|
},
|
|
|
|
Value: "Exception",
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 31,
|
|
|
|
EndPos: 32,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 31,
|
|
|
|
EndPos: 32,
|
|
|
|
},
|
|
|
|
Value: "e",
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
},
|
|
|
|
Stmts: []node.Node{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Finally: &stmt.Finally{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 2,
|
|
|
|
EndLine: 2,
|
|
|
|
StartPos: 38,
|
|
|
|
EndPos: 47,
|
|
|
|
},
|
2018-02-08 16:42:01 +00:00
|
|
|
Stmts: []node.Node{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php7parser.Parse()
|
|
|
|
actual := php7parser.GetRootNode()
|
2018-02-08 16:42:01 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php5parser.Parse()
|
|
|
|
actual = php5parser.GetRootNode()
|
2018-02-08 16:42:01 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
}
|
2018-02-13 17:38:37 +00:00
|
|
|
|
|
|
|
func TestTryCatchCatchCatch(t *testing.T) {
|
|
|
|
src := `<? try {} catch (Exception $e) {} catch (\RuntimeException $e) {} catch (namespace\AdditionException $e) {}`
|
|
|
|
|
2018-05-02 09:14:24 +00:00
|
|
|
expected := &node.Root{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 4,
|
|
|
|
EndPos: 107,
|
|
|
|
},
|
2018-02-13 17:38:37 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.Try{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 4,
|
|
|
|
EndPos: 107,
|
|
|
|
},
|
2018-02-13 17:38:37 +00:00
|
|
|
Stmts: []node.Node{},
|
|
|
|
Catches: []node.Node{
|
|
|
|
&stmt.Catch{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 11,
|
|
|
|
EndPos: 33,
|
|
|
|
},
|
2018-02-13 17:38:37 +00:00
|
|
|
Types: []node.Node{
|
|
|
|
&name.Name{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 18,
|
|
|
|
EndPos: 26,
|
|
|
|
},
|
2018-02-13 17:38:37 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 18,
|
|
|
|
EndPos: 26,
|
|
|
|
},
|
|
|
|
Value: "Exception",
|
|
|
|
},
|
2018-02-13 17:38:37 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 28,
|
|
|
|
EndPos: 29,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 28,
|
|
|
|
EndPos: 29,
|
|
|
|
},
|
|
|
|
Value: "e",
|
|
|
|
},
|
2018-02-13 17:38:37 +00:00
|
|
|
},
|
|
|
|
Stmts: []node.Node{},
|
|
|
|
},
|
|
|
|
&stmt.Catch{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 35,
|
|
|
|
EndPos: 65,
|
|
|
|
},
|
2018-02-13 17:38:37 +00:00
|
|
|
Types: []node.Node{
|
|
|
|
&name.FullyQualified{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 42,
|
|
|
|
EndPos: 58,
|
|
|
|
},
|
2018-02-13 17:38:37 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 43,
|
|
|
|
EndPos: 58,
|
|
|
|
},
|
|
|
|
Value: "RuntimeException",
|
|
|
|
},
|
2018-02-13 17:38:37 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 60,
|
|
|
|
EndPos: 61,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 60,
|
|
|
|
EndPos: 61,
|
|
|
|
},
|
|
|
|
Value: "e",
|
|
|
|
},
|
2018-02-13 17:38:37 +00:00
|
|
|
},
|
|
|
|
Stmts: []node.Node{},
|
|
|
|
},
|
|
|
|
&stmt.Catch{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 67,
|
|
|
|
EndPos: 107,
|
|
|
|
},
|
2018-02-13 17:38:37 +00:00
|
|
|
Types: []node.Node{
|
|
|
|
&name.Relative{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 74,
|
|
|
|
EndPos: 100,
|
|
|
|
},
|
2018-02-13 17:38:37 +00:00
|
|
|
Parts: []node.Node{
|
2018-06-24 07:19:44 +00:00
|
|
|
&name.NamePart{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 84,
|
|
|
|
EndPos: 100,
|
|
|
|
},
|
|
|
|
Value: "AdditionException",
|
|
|
|
},
|
2018-02-13 17:38:37 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
2018-06-24 07:19:44 +00:00
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 102,
|
|
|
|
EndPos: 103,
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Position: &position.Position{
|
|
|
|
StartLine: 1,
|
|
|
|
EndLine: 1,
|
|
|
|
StartPos: 102,
|
|
|
|
EndPos: 103,
|
|
|
|
},
|
|
|
|
Value: "e",
|
|
|
|
},
|
2018-02-13 17:38:37 +00:00
|
|
|
},
|
|
|
|
Stmts: []node.Node{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php7parser.Parse()
|
|
|
|
actual := php7parser.GetRootNode()
|
2018-02-13 17:38:37 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
|
2018-04-10 12:23:13 +00:00
|
|
|
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
|
|
|
php5parser.Parse()
|
|
|
|
actual = php5parser.GetRootNode()
|
2018-02-13 17:38:37 +00:00
|
|
|
assertEqual(t, expected, actual)
|
|
|
|
}
|