stmt visitor tests
This commit is contained in:
parent
f34a939fee
commit
cc1f13ffbd
@ -1,14 +1,15 @@
|
|||||||
package stmt_test
|
package stmt_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/z7zmey/php-parser/node/expr"
|
|
||||||
"github.com/z7zmey/php-parser/node/stmt"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/z7zmey/php-parser/node/expr"
|
||||||
|
"github.com/z7zmey/php-parser/node/stmt"
|
||||||
|
|
||||||
|
"github.com/kylelemons/godebug/pretty"
|
||||||
"github.com/z7zmey/php-parser/node"
|
"github.com/z7zmey/php-parser/node"
|
||||||
"github.com/z7zmey/php-parser/walker"
|
"github.com/z7zmey/php-parser/walker"
|
||||||
"github.com/kylelemons/godebug/pretty"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var nodesToTest = []struct {
|
var nodesToTest = []struct {
|
||||||
@ -28,47 +29,47 @@ var nodesToTest = []struct {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.AltElse{
|
&stmt.AltElse{
|
||||||
Stmt: &stmt.StmtList{},
|
Stmt: &stmt.StmtList{},
|
||||||
},
|
},
|
||||||
[]string{"Stmt"},
|
[]string{"Stmt"},
|
||||||
map[string]interface{}{},
|
map[string]interface{}{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.AltElseIf{
|
&stmt.AltElseIf{
|
||||||
Cond: &stmt.Expression{},
|
Cond: &stmt.Expression{},
|
||||||
Stmt: &stmt.StmtList{},
|
Stmt: &stmt.StmtList{},
|
||||||
},
|
},
|
||||||
[]string{"Cond", "Stmt"},
|
[]string{"Cond", "Stmt"},
|
||||||
map[string]interface{}{},
|
map[string]interface{}{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.Break{
|
&stmt.Break{
|
||||||
Expr: &stmt.Expression{},
|
Expr: &stmt.Expression{},
|
||||||
},
|
},
|
||||||
[]string{"Expr"},
|
[]string{"Expr"},
|
||||||
map[string]interface{}{},
|
map[string]interface{}{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.Case{
|
&stmt.Case{
|
||||||
Cond: &stmt.Expression{},
|
Cond: &stmt.Expression{},
|
||||||
Stmts: []node.Node{},
|
Stmts: []node.Node{&stmt.Expression{}},
|
||||||
},
|
},
|
||||||
[]string{"Cond", "Stmts"},
|
[]string{"Cond", "Stmts"},
|
||||||
map[string]interface{}{},
|
map[string]interface{}{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.Catch{
|
&stmt.Catch{
|
||||||
Types: []node.Node{},
|
Types: []node.Node{&stmt.Expression{}},
|
||||||
Variable: &expr.Variable{},
|
Variable: &expr.Variable{},
|
||||||
Stmts: []node.Node{},
|
Stmts: []node.Node{&stmt.Expression{}},
|
||||||
},
|
},
|
||||||
[]string{"Types", "Variable", "Stmts"},
|
[]string{"Types", "Variable", "Stmts"},
|
||||||
map[string]interface{}{},
|
map[string]interface{}{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.ClassConstList{
|
&stmt.ClassConstList{
|
||||||
Modifiers: []node.Node{},
|
Modifiers: []node.Node{&stmt.Expression{}},
|
||||||
Consts: []node.Node{},
|
Consts: []node.Node{&stmt.Expression{}},
|
||||||
},
|
},
|
||||||
[]string{"Modifiers", "Consts"},
|
[]string{"Modifiers", "Consts"},
|
||||||
map[string]interface{}{},
|
map[string]interface{}{},
|
||||||
@ -78,10 +79,10 @@ var nodesToTest = []struct {
|
|||||||
ReturnsRef: true,
|
ReturnsRef: true,
|
||||||
PhpDocComment: "/** */",
|
PhpDocComment: "/** */",
|
||||||
MethodName: &node.Identifier{},
|
MethodName: &node.Identifier{},
|
||||||
Modifiers: []node.Node{},
|
Modifiers: []node.Node{&stmt.Expression{}},
|
||||||
Params: []node.Node{},
|
Params: []node.Node{&stmt.Expression{}},
|
||||||
ReturnType: &node.Identifier{},
|
ReturnType: &node.Identifier{},
|
||||||
Stmts: []node.Node{},
|
Stmts: []node.Node{&stmt.Expression{}},
|
||||||
},
|
},
|
||||||
[]string{"MethodName", "Modifiers", "Params", "ReturnType", "Stmts"},
|
[]string{"MethodName", "Modifiers", "Params", "ReturnType", "Stmts"},
|
||||||
map[string]interface{}{"ReturnsRef": true, "PhpDocComment": "/** */"},
|
map[string]interface{}{"ReturnsRef": true, "PhpDocComment": "/** */"},
|
||||||
@ -90,18 +91,18 @@ var nodesToTest = []struct {
|
|||||||
&stmt.Class{
|
&stmt.Class{
|
||||||
PhpDocComment: "/** */",
|
PhpDocComment: "/** */",
|
||||||
ClassName: &node.Identifier{},
|
ClassName: &node.Identifier{},
|
||||||
Modifiers: []node.Node{},
|
Modifiers: []node.Node{&stmt.Expression{}},
|
||||||
Args: []node.Node{},
|
Args: []node.Node{&stmt.Expression{}},
|
||||||
Extends: &node.Identifier{},
|
Extends: &node.Identifier{},
|
||||||
Implements: []node.Node{},
|
Implements: []node.Node{&stmt.Expression{}},
|
||||||
Stmts: []node.Node{},
|
Stmts: []node.Node{&stmt.Expression{}},
|
||||||
},
|
},
|
||||||
[]string{"ClassName", "Modifiers", "Args", "Extends", "Implements", "Stmts"},
|
[]string{"ClassName", "Modifiers", "Args", "Extends", "Implements", "Stmts"},
|
||||||
map[string]interface{}{"PhpDocComment": "/** */"},
|
map[string]interface{}{"PhpDocComment": "/** */"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.ConstList{
|
&stmt.ConstList{
|
||||||
Consts: []node.Node{},
|
Consts: []node.Node{&stmt.Expression{}},
|
||||||
},
|
},
|
||||||
[]string{"Consts"},
|
[]string{"Consts"},
|
||||||
map[string]interface{}{},
|
map[string]interface{}{},
|
||||||
@ -117,14 +118,14 @@ var nodesToTest = []struct {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.Continue{
|
&stmt.Continue{
|
||||||
Expr: &stmt.Expression{},
|
Expr: &stmt.Expression{},
|
||||||
},
|
},
|
||||||
[]string{"Expr"},
|
[]string{"Expr"},
|
||||||
map[string]interface{}{},
|
map[string]interface{}{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.Declare{
|
&stmt.Declare{
|
||||||
Consts: []node.Node{},
|
Consts: []node.Node{&stmt.Expression{}},
|
||||||
Stmt: &stmt.StmtList{},
|
Stmt: &stmt.StmtList{},
|
||||||
},
|
},
|
||||||
[]string{"Consts", "Stmt"},
|
[]string{"Consts", "Stmt"},
|
||||||
@ -132,7 +133,7 @@ var nodesToTest = []struct {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.Default{
|
&stmt.Default{
|
||||||
Stmts: []node.Node{},
|
Stmts: []node.Node{&stmt.Expression{}},
|
||||||
},
|
},
|
||||||
[]string{"Stmts"},
|
[]string{"Stmts"},
|
||||||
map[string]interface{}{},
|
map[string]interface{}{},
|
||||||
@ -155,7 +156,7 @@ var nodesToTest = []struct {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.Echo{
|
&stmt.Echo{
|
||||||
Exprs: []node.Node{},
|
Exprs: []node.Node{&stmt.Expression{}},
|
||||||
},
|
},
|
||||||
[]string{"Exprs"},
|
[]string{"Exprs"},
|
||||||
map[string]interface{}{},
|
map[string]interface{}{},
|
||||||
@ -172,38 +173,38 @@ var nodesToTest = []struct {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.Else{
|
&stmt.Else{
|
||||||
Stmt: &stmt.StmtList{},
|
Stmt: &stmt.StmtList{},
|
||||||
},
|
},
|
||||||
[]string{"Stmt"},
|
[]string{"Stmt"},
|
||||||
map[string]interface{}{},
|
map[string]interface{}{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.ElseIf{
|
&stmt.ElseIf{
|
||||||
Cond: &stmt.Expression{},
|
Cond: &stmt.Expression{},
|
||||||
Stmt: &stmt.StmtList{},
|
Stmt: &stmt.StmtList{},
|
||||||
},
|
},
|
||||||
[]string{"Cond", "Stmt"},
|
[]string{"Cond", "Stmt"},
|
||||||
map[string]interface{}{},
|
map[string]interface{}{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.Expression{
|
&stmt.Expression{
|
||||||
Expr: &stmt.Expression{},
|
Expr: &stmt.Expression{},
|
||||||
},
|
},
|
||||||
[]string{"Expr"},
|
[]string{"Expr"},
|
||||||
map[string]interface{}{},
|
map[string]interface{}{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.Finally{
|
&stmt.Finally{
|
||||||
Stmts: []node.Node{},
|
Stmts: []node.Node{&stmt.Expression{}},
|
||||||
},
|
},
|
||||||
[]string{"Stmts"},
|
[]string{"Stmts"},
|
||||||
map[string]interface{}{},
|
map[string]interface{}{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.For{
|
&stmt.For{
|
||||||
Init: []node.Node{},
|
Init: []node.Node{&stmt.Expression{}},
|
||||||
Cond: []node.Node{},
|
Cond: []node.Node{&stmt.Expression{}},
|
||||||
Loop: []node.Node{},
|
Loop: []node.Node{&stmt.Expression{}},
|
||||||
Stmt: &stmt.StmtList{},
|
Stmt: &stmt.StmtList{},
|
||||||
},
|
},
|
||||||
[]string{"Init", "Cond", "Loop", "Stmt"},
|
[]string{"Init", "Cond", "Loop", "Stmt"},
|
||||||
@ -223,18 +224,18 @@ var nodesToTest = []struct {
|
|||||||
{
|
{
|
||||||
&stmt.Function{
|
&stmt.Function{
|
||||||
ReturnsRef: true,
|
ReturnsRef: true,
|
||||||
PhpDocComment: "/** */",
|
PhpDocComment: "/** */",
|
||||||
FunctionName: &node.Identifier{},
|
FunctionName: &node.Identifier{},
|
||||||
Params: []node.Node{},
|
Params: []node.Node{&stmt.Expression{}},
|
||||||
ReturnType: &node.Identifier{},
|
ReturnType: &node.Identifier{},
|
||||||
Stmts: []node.Node{},
|
Stmts: []node.Node{&stmt.Expression{}},
|
||||||
},
|
},
|
||||||
[]string{"FunctionName", "Params", "ReturnType", "Stmts"},
|
[]string{"FunctionName", "Params", "ReturnType", "Stmts"},
|
||||||
map[string]interface{}{"ReturnsRef": true, "PhpDocComment": "/** */"},
|
map[string]interface{}{"ReturnsRef": true, "PhpDocComment": "/** */"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.Global{
|
&stmt.Global{
|
||||||
Vars: []node.Node{},
|
Vars: []node.Node{&stmt.Expression{}},
|
||||||
},
|
},
|
||||||
[]string{"Vars"},
|
[]string{"Vars"},
|
||||||
map[string]interface{}{},
|
map[string]interface{}{},
|
||||||
@ -250,7 +251,7 @@ var nodesToTest = []struct {
|
|||||||
&stmt.GroupUse{
|
&stmt.GroupUse{
|
||||||
UseType: &node.Identifier{},
|
UseType: &node.Identifier{},
|
||||||
Prefix: &node.Identifier{},
|
Prefix: &node.Identifier{},
|
||||||
UseList: []node.Node{},
|
UseList: []node.Node{&stmt.Expression{}},
|
||||||
},
|
},
|
||||||
[]string{"UseType", "Prefix", "UseList"},
|
[]string{"UseType", "Prefix", "UseList"},
|
||||||
map[string]interface{}{},
|
map[string]interface{}{},
|
||||||
@ -262,7 +263,7 @@ var nodesToTest = []struct {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.InlineHtml{
|
&stmt.InlineHtml{
|
||||||
Value: "hello",
|
Value: "hello",
|
||||||
},
|
},
|
||||||
[]string{},
|
[]string{},
|
||||||
map[string]interface{}{"Value": "hello"},
|
map[string]interface{}{"Value": "hello"},
|
||||||
@ -271,8 +272,8 @@ var nodesToTest = []struct {
|
|||||||
&stmt.Interface{
|
&stmt.Interface{
|
||||||
PhpDocComment: "/** */",
|
PhpDocComment: "/** */",
|
||||||
InterfaceName: &node.Identifier{},
|
InterfaceName: &node.Identifier{},
|
||||||
Extends: []node.Node{},
|
Extends: []node.Node{&stmt.Expression{}},
|
||||||
Stmts: []node.Node{},
|
Stmts: []node.Node{&stmt.Expression{}},
|
||||||
},
|
},
|
||||||
[]string{"InterfaceName", "Extends", "Stmts"},
|
[]string{"InterfaceName", "Extends", "Stmts"},
|
||||||
map[string]interface{}{"PhpDocComment": "/** */"},
|
map[string]interface{}{"PhpDocComment": "/** */"},
|
||||||
@ -287,7 +288,7 @@ var nodesToTest = []struct {
|
|||||||
{
|
{
|
||||||
&stmt.Namespace{
|
&stmt.Namespace{
|
||||||
NamespaceName: &node.Identifier{},
|
NamespaceName: &node.Identifier{},
|
||||||
Stmts: []node.Node{},
|
Stmts: []node.Node{&stmt.Expression{}},
|
||||||
},
|
},
|
||||||
[]string{"NamespaceName", "Stmts"},
|
[]string{"NamespaceName", "Stmts"},
|
||||||
map[string]interface{}{},
|
map[string]interface{}{},
|
||||||
@ -299,15 +300,15 @@ var nodesToTest = []struct {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.PropertyList{
|
&stmt.PropertyList{
|
||||||
Modifiers: []node.Node{},
|
Modifiers: []node.Node{&stmt.Expression{}},
|
||||||
Properties: []node.Node{},
|
Properties: []node.Node{&stmt.Expression{}},
|
||||||
},
|
},
|
||||||
[]string{"Modifiers", "Properties"},
|
[]string{"Modifiers", "Properties"},
|
||||||
map[string]interface{}{},
|
map[string]interface{}{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.Property{
|
&stmt.Property{
|
||||||
PhpDocComment: "/** */",
|
PhpDocComment: "/** */",
|
||||||
Variable: &expr.Variable{},
|
Variable: &expr.Variable{},
|
||||||
Expr: &stmt.Expression{},
|
Expr: &stmt.Expression{},
|
||||||
},
|
},
|
||||||
@ -331,7 +332,7 @@ var nodesToTest = []struct {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.Static{
|
&stmt.Static{
|
||||||
Vars: []node.Node{},
|
Vars: []node.Node{&stmt.Expression{}},
|
||||||
},
|
},
|
||||||
[]string{"Vars"},
|
[]string{"Vars"},
|
||||||
map[string]interface{}{},
|
map[string]interface{}{},
|
||||||
@ -339,7 +340,7 @@ var nodesToTest = []struct {
|
|||||||
{
|
{
|
||||||
&stmt.Switch{
|
&stmt.Switch{
|
||||||
Cond: &expr.Variable{},
|
Cond: &expr.Variable{},
|
||||||
Cases: []node.Node{},
|
Cases: []node.Node{&stmt.Expression{}},
|
||||||
},
|
},
|
||||||
[]string{"Cond", "Cases"},
|
[]string{"Cond", "Cases"},
|
||||||
map[string]interface{}{},
|
map[string]interface{}{},
|
||||||
@ -378,8 +379,8 @@ var nodesToTest = []struct {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.TraitUse{
|
&stmt.TraitUse{
|
||||||
Traits: []node.Node{},
|
Traits: []node.Node{&stmt.Expression{}},
|
||||||
Adaptations: []node.Node{},
|
Adaptations: []node.Node{&stmt.Expression{}},
|
||||||
},
|
},
|
||||||
[]string{"Traits", "Adaptations"},
|
[]string{"Traits", "Adaptations"},
|
||||||
map[string]interface{}{},
|
map[string]interface{}{},
|
||||||
@ -388,15 +389,15 @@ var nodesToTest = []struct {
|
|||||||
&stmt.Trait{
|
&stmt.Trait{
|
||||||
PhpDocComment: "/** */",
|
PhpDocComment: "/** */",
|
||||||
TraitName: &node.Identifier{},
|
TraitName: &node.Identifier{},
|
||||||
Stmts: []node.Node{},
|
Stmts: []node.Node{&stmt.Expression{}},
|
||||||
},
|
},
|
||||||
[]string{"TraitName", "Stmts"},
|
[]string{"TraitName", "Stmts"},
|
||||||
map[string]interface{}{"PhpDocComment": "/** */"},
|
map[string]interface{}{"PhpDocComment": "/** */"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.Try{
|
&stmt.Try{
|
||||||
Stmts: []node.Node{},
|
Stmts: []node.Node{&stmt.Expression{}},
|
||||||
Catches: []node.Node{},
|
Catches: []node.Node{&stmt.Expression{}},
|
||||||
Finally: &stmt.Finally{},
|
Finally: &stmt.Finally{},
|
||||||
},
|
},
|
||||||
[]string{"Stmts", "Catches", "Finally"},
|
[]string{"Stmts", "Catches", "Finally"},
|
||||||
@ -404,7 +405,7 @@ var nodesToTest = []struct {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.Unset{
|
&stmt.Unset{
|
||||||
Vars: []node.Node{},
|
Vars: []node.Node{&stmt.Expression{}},
|
||||||
},
|
},
|
||||||
[]string{"Vars"},
|
[]string{"Vars"},
|
||||||
map[string]interface{}{},
|
map[string]interface{}{},
|
||||||
@ -412,7 +413,7 @@ var nodesToTest = []struct {
|
|||||||
{
|
{
|
||||||
&stmt.UseList{
|
&stmt.UseList{
|
||||||
UseType: &node.Identifier{},
|
UseType: &node.Identifier{},
|
||||||
Uses: []node.Node{},
|
Uses: []node.Node{&stmt.Expression{}},
|
||||||
},
|
},
|
||||||
[]string{"UseType", "Uses"},
|
[]string{"UseType", "Uses"},
|
||||||
map[string]interface{}{},
|
map[string]interface{}{},
|
||||||
@ -428,8 +429,8 @@ var nodesToTest = []struct {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.While{
|
&stmt.While{
|
||||||
Cond: &expr.Variable{},
|
Cond: &expr.Variable{},
|
||||||
Stmt: &stmt.StmtList{},
|
Stmt: &stmt.StmtList{},
|
||||||
},
|
},
|
||||||
[]string{"Cond", "Stmt"},
|
[]string{"Cond", "Stmt"},
|
||||||
map[string]interface{}{},
|
map[string]interface{}{},
|
||||||
|
Loading…
Reference in New Issue
Block a user