2018-02-06 17:11:47 +00:00
|
|
|
package stmt_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-02-13 20:18:07 +00:00
|
|
|
"gotest.tools/assert"
|
|
|
|
|
2018-05-12 20:10:01 +00:00
|
|
|
"github.com/z7zmey/php-parser/node/name"
|
|
|
|
|
2018-02-08 21:10:56 +00:00
|
|
|
"github.com/z7zmey/php-parser/node/expr"
|
|
|
|
"github.com/z7zmey/php-parser/node/stmt"
|
|
|
|
|
2018-02-06 17:11:47 +00:00
|
|
|
"github.com/z7zmey/php-parser/node"
|
|
|
|
"github.com/z7zmey/php-parser/walker"
|
|
|
|
)
|
|
|
|
|
|
|
|
var nodesToTest = []struct {
|
|
|
|
node node.Node // node
|
|
|
|
expectedVisitedKeys []string // visited keys
|
|
|
|
expectedAttributes map[string]interface{}
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
&stmt.AltIf{
|
|
|
|
Cond: &stmt.Expression{},
|
|
|
|
Stmt: &stmt.StmtList{},
|
|
|
|
ElseIf: []node.Node{&stmt.ElseIf{}},
|
|
|
|
Else: &stmt.Else{},
|
|
|
|
},
|
|
|
|
[]string{"Cond", "Stmt", "ElseIf", "Else"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.AltElse{
|
2018-02-08 21:10:56 +00:00
|
|
|
Stmt: &stmt.StmtList{},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"Stmt"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.AltElseIf{
|
2018-02-08 21:10:56 +00:00
|
|
|
Cond: &stmt.Expression{},
|
|
|
|
Stmt: &stmt.StmtList{},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"Cond", "Stmt"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Break{
|
2018-02-08 21:10:56 +00:00
|
|
|
Expr: &stmt.Expression{},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"Expr"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Case{
|
2018-02-08 21:10:56 +00:00
|
|
|
Cond: &stmt.Expression{},
|
|
|
|
Stmts: []node.Node{&stmt.Expression{}},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"Cond", "Stmts"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Catch{
|
2018-02-08 21:10:56 +00:00
|
|
|
Types: []node.Node{&stmt.Expression{}},
|
2018-02-06 17:11:47 +00:00
|
|
|
Variable: &expr.Variable{},
|
2018-02-08 21:10:56 +00:00
|
|
|
Stmts: []node.Node{&stmt.Expression{}},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"Types", "Variable", "Stmts"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.ClassConstList{
|
2018-02-08 21:10:56 +00:00
|
|
|
Modifiers: []node.Node{&stmt.Expression{}},
|
|
|
|
Consts: []node.Node{&stmt.Expression{}},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"Modifiers", "Consts"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.ClassMethod{
|
|
|
|
ReturnsRef: true,
|
|
|
|
PhpDocComment: "/** */",
|
|
|
|
MethodName: &node.Identifier{},
|
2018-02-08 21:10:56 +00:00
|
|
|
Modifiers: []node.Node{&stmt.Expression{}},
|
|
|
|
Params: []node.Node{&stmt.Expression{}},
|
2018-02-06 17:11:47 +00:00
|
|
|
ReturnType: &node.Identifier{},
|
2018-06-03 06:35:44 +00:00
|
|
|
Stmt: &stmt.StmtList{},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
2018-06-03 06:35:44 +00:00
|
|
|
[]string{"MethodName", "Modifiers", "Params", "ReturnType", "Stmt"},
|
2018-02-06 17:11:47 +00:00
|
|
|
map[string]interface{}{"ReturnsRef": true, "PhpDocComment": "/** */"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Class{
|
|
|
|
PhpDocComment: "/** */",
|
|
|
|
ClassName: &node.Identifier{},
|
2018-02-08 21:10:56 +00:00
|
|
|
Modifiers: []node.Node{&stmt.Expression{}},
|
2018-04-29 19:34:24 +00:00
|
|
|
ArgumentList: &node.ArgumentList{},
|
2018-05-12 20:10:01 +00:00
|
|
|
Extends: &stmt.ClassExtends{},
|
|
|
|
Implements: &stmt.ClassImplements{},
|
2018-04-29 19:34:24 +00:00
|
|
|
Stmts: []node.Node{&stmt.Expression{}},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
[]string{"ClassName", "Modifiers", "ArgumentList", "Extends", "Implements", "Stmts"},
|
2018-02-06 17:11:47 +00:00
|
|
|
map[string]interface{}{"PhpDocComment": "/** */"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.ConstList{
|
2018-02-08 21:10:56 +00:00
|
|
|
Consts: []node.Node{&stmt.Expression{}},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"Consts"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Constant{
|
|
|
|
PhpDocComment: "/** */",
|
|
|
|
ConstantName: &node.Identifier{},
|
|
|
|
Expr: &stmt.Expression{},
|
|
|
|
},
|
|
|
|
[]string{"ConstantName", "Expr"},
|
|
|
|
map[string]interface{}{"PhpDocComment": "/** */"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Continue{
|
2018-02-08 21:10:56 +00:00
|
|
|
Expr: &stmt.Expression{},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"Expr"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Declare{
|
2018-02-08 21:10:56 +00:00
|
|
|
Consts: []node.Node{&stmt.Expression{}},
|
2018-02-06 17:11:47 +00:00
|
|
|
Stmt: &stmt.StmtList{},
|
|
|
|
},
|
|
|
|
[]string{"Consts", "Stmt"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Default{
|
2018-02-08 21:10:56 +00:00
|
|
|
Stmts: []node.Node{&stmt.Expression{}},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"Stmts"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Do{
|
|
|
|
Stmt: &stmt.StmtList{},
|
|
|
|
Cond: &expr.Variable{},
|
|
|
|
},
|
|
|
|
[]string{"Stmt", "Cond"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Do{
|
|
|
|
Stmt: &stmt.StmtList{},
|
|
|
|
Cond: &expr.Variable{},
|
|
|
|
},
|
|
|
|
[]string{"Stmt", "Cond"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Echo{
|
2018-02-08 21:10:56 +00:00
|
|
|
Exprs: []node.Node{&stmt.Expression{}},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"Exprs"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.If{
|
|
|
|
Cond: &stmt.Expression{},
|
|
|
|
Stmt: &stmt.StmtList{},
|
|
|
|
ElseIf: []node.Node{&stmt.ElseIf{}},
|
|
|
|
Else: &stmt.Else{},
|
|
|
|
},
|
|
|
|
[]string{"Cond", "Stmt", "ElseIf", "Else"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Else{
|
2018-02-08 21:10:56 +00:00
|
|
|
Stmt: &stmt.StmtList{},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"Stmt"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.ElseIf{
|
2018-02-08 21:10:56 +00:00
|
|
|
Cond: &stmt.Expression{},
|
|
|
|
Stmt: &stmt.StmtList{},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"Cond", "Stmt"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Expression{
|
2018-02-08 21:10:56 +00:00
|
|
|
Expr: &stmt.Expression{},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"Expr"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Finally{
|
2018-02-08 21:10:56 +00:00
|
|
|
Stmts: []node.Node{&stmt.Expression{}},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"Stmts"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.For{
|
2018-02-08 21:10:56 +00:00
|
|
|
Init: []node.Node{&stmt.Expression{}},
|
|
|
|
Cond: []node.Node{&stmt.Expression{}},
|
|
|
|
Loop: []node.Node{&stmt.Expression{}},
|
2018-02-06 17:11:47 +00:00
|
|
|
Stmt: &stmt.StmtList{},
|
|
|
|
},
|
|
|
|
[]string{"Init", "Cond", "Loop", "Stmt"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
2018-02-18 17:57:54 +00:00
|
|
|
{
|
|
|
|
&stmt.AltFor{
|
|
|
|
Init: []node.Node{&stmt.Expression{}},
|
|
|
|
Cond: []node.Node{&stmt.Expression{}},
|
|
|
|
Loop: []node.Node{&stmt.Expression{}},
|
|
|
|
Stmt: &stmt.StmtList{},
|
|
|
|
},
|
|
|
|
[]string{"Init", "Cond", "Loop", "Stmt"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-18 17:57:54 +00:00
|
|
|
},
|
2018-02-06 17:11:47 +00:00
|
|
|
{
|
|
|
|
&stmt.Foreach{
|
|
|
|
Expr: &stmt.Expression{},
|
|
|
|
Key: &expr.Variable{},
|
|
|
|
Variable: &expr.Variable{},
|
|
|
|
Stmt: &stmt.StmtList{},
|
|
|
|
},
|
|
|
|
[]string{"Expr", "Key", "Variable", "Stmt"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-18 18:29:33 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.AltForeach{
|
|
|
|
Expr: &stmt.Expression{},
|
|
|
|
Key: &expr.Variable{},
|
|
|
|
Variable: &expr.Variable{},
|
|
|
|
Stmt: &stmt.StmtList{},
|
|
|
|
},
|
|
|
|
[]string{"Expr", "Key", "Variable", "Stmt"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Function{
|
|
|
|
ReturnsRef: true,
|
2018-02-08 21:10:56 +00:00
|
|
|
PhpDocComment: "/** */",
|
2018-02-06 17:11:47 +00:00
|
|
|
FunctionName: &node.Identifier{},
|
2018-02-08 21:10:56 +00:00
|
|
|
Params: []node.Node{&stmt.Expression{}},
|
2018-02-06 17:11:47 +00:00
|
|
|
ReturnType: &node.Identifier{},
|
2018-02-08 21:10:56 +00:00
|
|
|
Stmts: []node.Node{&stmt.Expression{}},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"FunctionName", "Params", "ReturnType", "Stmts"},
|
|
|
|
map[string]interface{}{"ReturnsRef": true, "PhpDocComment": "/** */"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Global{
|
2018-02-08 21:10:56 +00:00
|
|
|
Vars: []node.Node{&stmt.Expression{}},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"Vars"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Goto{
|
|
|
|
Label: &node.Identifier{},
|
|
|
|
},
|
|
|
|
[]string{"Label"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.GroupUse{
|
|
|
|
UseType: &node.Identifier{},
|
|
|
|
Prefix: &node.Identifier{},
|
2018-02-08 21:10:56 +00:00
|
|
|
UseList: []node.Node{&stmt.Expression{}},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"UseType", "Prefix", "UseList"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.HaltCompiler{},
|
|
|
|
[]string{},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.InlineHtml{
|
2018-02-08 21:10:56 +00:00
|
|
|
Value: "hello",
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{},
|
|
|
|
map[string]interface{}{"Value": "hello"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Interface{
|
|
|
|
PhpDocComment: "/** */",
|
|
|
|
InterfaceName: &node.Identifier{},
|
2018-05-12 20:10:01 +00:00
|
|
|
Extends: &stmt.InterfaceExtends{},
|
2018-02-08 21:10:56 +00:00
|
|
|
Stmts: []node.Node{&stmt.Expression{}},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"InterfaceName", "Extends", "Stmts"},
|
|
|
|
map[string]interface{}{"PhpDocComment": "/** */"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Label{
|
|
|
|
LabelName: &node.Identifier{},
|
|
|
|
},
|
|
|
|
[]string{"LabelName"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Namespace{
|
|
|
|
NamespaceName: &node.Identifier{},
|
2018-02-08 21:10:56 +00:00
|
|
|
Stmts: []node.Node{&stmt.Expression{}},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"NamespaceName", "Stmts"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Nop{},
|
|
|
|
[]string{},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.PropertyList{
|
2018-02-08 21:10:56 +00:00
|
|
|
Modifiers: []node.Node{&stmt.Expression{}},
|
|
|
|
Properties: []node.Node{&stmt.Expression{}},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"Modifiers", "Properties"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Property{
|
2018-02-08 21:10:56 +00:00
|
|
|
PhpDocComment: "/** */",
|
2018-02-06 17:11:47 +00:00
|
|
|
Variable: &expr.Variable{},
|
|
|
|
Expr: &stmt.Expression{},
|
|
|
|
},
|
|
|
|
[]string{"Variable", "Expr"},
|
|
|
|
map[string]interface{}{"PhpDocComment": "/** */"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Return{
|
|
|
|
Expr: &stmt.Expression{},
|
|
|
|
},
|
|
|
|
[]string{"Expr"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.StaticVar{
|
|
|
|
Variable: &expr.Variable{},
|
|
|
|
Expr: &stmt.Expression{},
|
|
|
|
},
|
|
|
|
[]string{"Variable", "Expr"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Static{
|
2018-02-08 21:10:56 +00:00
|
|
|
Vars: []node.Node{&stmt.Expression{}},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"Vars"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Switch{
|
2018-06-03 06:35:44 +00:00
|
|
|
Cond: &expr.Variable{},
|
2018-04-29 20:10:56 +00:00
|
|
|
CaseList: &stmt.CaseList{},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
2018-04-29 20:10:56 +00:00
|
|
|
[]string{"Cond", "CaseList"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
2018-02-18 18:39:41 +00:00
|
|
|
{
|
|
|
|
&stmt.AltSwitch{
|
2018-04-29 20:10:56 +00:00
|
|
|
Cond: &expr.Variable{},
|
2018-06-18 20:29:52 +00:00
|
|
|
CaseList: &stmt.CaseList{},
|
2018-02-18 18:39:41 +00:00
|
|
|
},
|
2018-04-29 20:10:56 +00:00
|
|
|
[]string{"Cond", "CaseList"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-18 18:39:41 +00:00
|
|
|
},
|
2018-02-06 17:11:47 +00:00
|
|
|
{
|
|
|
|
&stmt.Throw{
|
|
|
|
Expr: &stmt.Expression{},
|
|
|
|
},
|
|
|
|
[]string{"Expr"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.TraitMethodRef{
|
|
|
|
Trait: &node.Identifier{},
|
|
|
|
Method: &node.Identifier{},
|
|
|
|
},
|
|
|
|
[]string{"Trait", "Method"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.TraitUseAlias{
|
|
|
|
Ref: &node.Identifier{},
|
|
|
|
Modifier: &node.Identifier{},
|
|
|
|
Alias: &node.Identifier{},
|
|
|
|
},
|
|
|
|
[]string{"Ref", "Modifier", "Alias"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.TraitUsePrecedence{
|
|
|
|
Ref: &node.Identifier{},
|
2018-02-09 12:48:10 +00:00
|
|
|
Insteadof: []node.Node{&node.Identifier{}},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"Ref", "Insteadof"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.TraitUse{
|
2018-04-29 19:34:24 +00:00
|
|
|
Traits: []node.Node{&stmt.Expression{}},
|
|
|
|
TraitAdaptationList: &stmt.TraitAdaptationList{},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
2018-04-29 19:34:24 +00:00
|
|
|
[]string{"Traits", "TraitAdaptationList"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Trait{
|
|
|
|
PhpDocComment: "/** */",
|
|
|
|
TraitName: &node.Identifier{},
|
2018-02-08 21:10:56 +00:00
|
|
|
Stmts: []node.Node{&stmt.Expression{}},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"TraitName", "Stmts"},
|
|
|
|
map[string]interface{}{"PhpDocComment": "/** */"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Try{
|
2018-02-08 21:10:56 +00:00
|
|
|
Stmts: []node.Node{&stmt.Expression{}},
|
|
|
|
Catches: []node.Node{&stmt.Expression{}},
|
2018-02-06 17:11:47 +00:00
|
|
|
Finally: &stmt.Finally{},
|
|
|
|
},
|
|
|
|
[]string{"Stmts", "Catches", "Finally"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Unset{
|
2018-02-08 21:10:56 +00:00
|
|
|
Vars: []node.Node{&stmt.Expression{}},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"Vars"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.UseList{
|
|
|
|
UseType: &node.Identifier{},
|
2018-02-08 21:10:56 +00:00
|
|
|
Uses: []node.Node{&stmt.Expression{}},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"UseType", "Uses"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.Use{
|
|
|
|
UseType: &node.Identifier{},
|
|
|
|
Use: &node.Identifier{},
|
|
|
|
Alias: &node.Identifier{},
|
|
|
|
},
|
|
|
|
[]string{"UseType", "Use", "Alias"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.While{
|
2018-02-08 21:10:56 +00:00
|
|
|
Cond: &expr.Variable{},
|
|
|
|
Stmt: &stmt.StmtList{},
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
|
|
|
[]string{"Cond", "Stmt"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-06 17:11:47 +00:00
|
|
|
},
|
2018-02-18 17:44:17 +00:00
|
|
|
{
|
|
|
|
&stmt.AltWhile{
|
|
|
|
Cond: &expr.Variable{},
|
|
|
|
Stmt: &stmt.StmtList{},
|
|
|
|
},
|
|
|
|
[]string{"Cond", "Stmt"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-18 17:44:17 +00:00
|
|
|
},
|
2018-02-09 12:11:08 +00:00
|
|
|
{
|
|
|
|
&stmt.StmtList{
|
|
|
|
Stmts: []node.Node{&stmt.Expression{}},
|
|
|
|
},
|
|
|
|
[]string{"Stmts"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-02-09 12:11:08 +00:00
|
|
|
},
|
2018-04-29 20:10:56 +00:00
|
|
|
{
|
|
|
|
&stmt.CaseList{
|
|
|
|
Cases: []node.Node{&stmt.Expression{}},
|
|
|
|
},
|
|
|
|
[]string{"Cases"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-04-29 20:10:56 +00:00
|
|
|
},
|
2018-04-29 19:34:24 +00:00
|
|
|
{
|
|
|
|
&stmt.TraitAdaptationList{
|
|
|
|
Adaptations: []node.Node{&stmt.TraitUsePrecedence{}},
|
|
|
|
},
|
|
|
|
[]string{"Adaptations"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-04-29 19:34:24 +00:00
|
|
|
},
|
2018-05-12 20:10:01 +00:00
|
|
|
{
|
|
|
|
&stmt.ClassExtends{
|
|
|
|
ClassName: &name.Name{},
|
|
|
|
},
|
|
|
|
[]string{"ClassName"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-05-12 20:10:01 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.ClassImplements{
|
|
|
|
InterfaceNames: []node.Node{
|
|
|
|
&name.Name{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[]string{"InterfaceNames"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-05-12 20:10:01 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&stmt.InterfaceExtends{
|
|
|
|
InterfaceNames: []node.Node{
|
|
|
|
&name.Name{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[]string{"InterfaceNames"},
|
2019-02-13 20:18:07 +00:00
|
|
|
nil,
|
2018-05-12 20:10:01 +00:00
|
|
|
},
|
2018-02-06 17:11:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type visitorMock struct {
|
|
|
|
visitChildren bool
|
|
|
|
visitedKeys []string
|
|
|
|
}
|
|
|
|
|
2018-02-20 17:52:07 +00:00
|
|
|
func (v *visitorMock) EnterNode(n walker.Walkable) bool { return v.visitChildren }
|
2018-06-18 20:29:52 +00:00
|
|
|
func (v *visitorMock) LeaveNode(n walker.Walkable) {}
|
|
|
|
func (v *visitorMock) EnterChildNode(key string, w walker.Walkable) {
|
|
|
|
v.visitedKeys = append(v.visitedKeys, key)
|
|
|
|
}
|
|
|
|
func (v *visitorMock) LeaveChildNode(key string, w walker.Walkable) {}
|
|
|
|
func (v *visitorMock) EnterChildList(key string, w walker.Walkable) {
|
2018-02-06 17:11:47 +00:00
|
|
|
v.visitedKeys = append(v.visitedKeys, key)
|
|
|
|
}
|
2018-06-18 20:29:52 +00:00
|
|
|
func (v *visitorMock) LeaveChildList(key string, w walker.Walkable) {}
|
2018-02-06 17:11:47 +00:00
|
|
|
|
|
|
|
func TestVisitorDisableChildren(t *testing.T) {
|
|
|
|
for _, tt := range nodesToTest {
|
2019-02-13 20:18:07 +00:00
|
|
|
v := &visitorMock{false, []string{}}
|
2018-02-06 17:11:47 +00:00
|
|
|
tt.node.Walk(v)
|
|
|
|
|
|
|
|
expected := []string{}
|
|
|
|
actual := v.visitedKeys
|
|
|
|
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-06 17:11:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestVisitor(t *testing.T) {
|
|
|
|
for _, tt := range nodesToTest {
|
2019-02-13 20:18:07 +00:00
|
|
|
v := &visitorMock{true, []string{}}
|
2018-02-06 17:11:47 +00:00
|
|
|
tt.node.Walk(v)
|
|
|
|
|
|
|
|
expected := tt.expectedVisitedKeys
|
|
|
|
actual := v.visitedKeys
|
|
|
|
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-06 17:11:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// test Attributes()
|
|
|
|
|
|
|
|
func TestNameAttributes(t *testing.T) {
|
|
|
|
for _, tt := range nodesToTest {
|
|
|
|
expected := tt.expectedAttributes
|
|
|
|
actual := tt.node.Attributes()
|
|
|
|
|
2019-02-13 20:18:07 +00:00
|
|
|
assert.DeepEqual(t, expected, actual)
|
2018-02-06 17:11:47 +00:00
|
|
|
}
|
|
|
|
}
|