[refactoring] fix namespaceResolver tests

This commit is contained in:
Vadym Slizov 2020-12-11 10:05:02 +02:00
parent 497e7f82ee
commit 60433615a9
No known key found for this signature in database
GPG Key ID: AEA2A9388EF42A4A
2 changed files with 9 additions and 31 deletions

View File

@ -1,26 +1,16 @@
package visitor_test package visitor_test
import ( import (
"os"
"github.com/z7zmey/php-parser/pkg/ast" "github.com/z7zmey/php-parser/pkg/ast"
"github.com/z7zmey/php-parser/pkg/ast/traverser" "github.com/z7zmey/php-parser/pkg/ast/traverser"
"github.com/z7zmey/php-parser/pkg/ast/visitor" "github.com/z7zmey/php-parser/pkg/ast/visitor"
"github.com/z7zmey/php-parser/pkg/position"
"github.com/z7zmey/php-parser/pkg/token" "github.com/z7zmey/php-parser/pkg/token"
"os"
) )
func ExampleDump() { func ExampleDump() {
stxTree := &ast.Root{ stxTree := &ast.Root{
Node: ast.Node{
Tokens: token.Collection{
token.Start: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
},
},
},
},
Stmts: []ast.Vertex{ Stmts: []ast.Vertex{
&ast.Identifier{}, &ast.Identifier{},
&ast.Parameter{ &ast.Parameter{
@ -30,6 +20,10 @@ func ExampleDump() {
Value: []byte("foo"), Value: []byte("foo"),
}, },
}, },
EndTkn: &token.Token{
ID: token.T_WHITESPACE,
Value: []byte(" "),
},
} }
traverser.NewDFS(visitor.NewDump(os.Stdout)).Traverse(stxTree) traverser.NewDFS(visitor.NewDump(os.Stdout)).Traverse(stxTree)

View File

@ -24,9 +24,8 @@ func TestResolveStaticCall(t *testing.T) {
}, },
}, },
&ast.ExprStaticCall{ &ast.ExprStaticCall{
Class: nameBC, Class: nameBC,
Call: &ast.Identifier{Value: []byte("foo")}, Call: &ast.Identifier{Value: []byte("foo")},
ArgumentList: &ast.ArgumentList{},
}, },
}, },
} }
@ -119,7 +118,6 @@ func TestResolveNew(t *testing.T) {
}, },
&ast.ExprNew{ &ast.ExprNew{
Class: nameBC, Class: nameBC,
ArgumentList: &ast.ArgumentList{},
}, },
}, },
} }
@ -230,7 +228,6 @@ func TestResolveFunctionCall(t *testing.T) {
}, },
&ast.ExprFunctionCall{ &ast.ExprFunctionCall{
Function: nameB, Function: nameB,
ArgumentList: &ast.ArgumentList{},
}, },
}, },
} }
@ -313,11 +310,9 @@ func TestResolveGroupUse(t *testing.T) {
}, },
&ast.ExprFunctionCall{ &ast.ExprFunctionCall{
Function: nameF, Function: nameF,
ArgumentList: &ast.ArgumentList{},
}, },
&ast.ExprFunctionCall{ &ast.ExprFunctionCall{
Function: nameE, Function: nameE,
ArgumentList: &ast.ArgumentList{},
}, },
}, },
} }
@ -359,7 +354,7 @@ func TestResolveTraitUse(t *testing.T) {
nameB, nameB,
relativeNameB, relativeNameB,
}, },
TraitAdaptationList: &ast.StmtTraitAdaptationList{ Adaptations: &ast.StmtTraitAdaptationList{
Adaptations: []ast.Vertex{ Adaptations: []ast.Vertex{
&ast.StmtTraitUsePrecedence{ &ast.StmtTraitUsePrecedence{
Ref: &ast.StmtTraitMethodRef{ Ref: &ast.StmtTraitMethodRef{
@ -498,7 +493,6 @@ func TestResolveFunctionName(t *testing.T) {
nameBC := &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("B")}, &ast.NameNamePart{Value: []byte("C")}}} nameBC := &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("B")}, &ast.NameNamePart{Value: []byte("C")}}}
functionNode := &ast.StmtFunction{ functionNode := &ast.StmtFunction{
ReturnsRef: false,
FunctionName: &ast.Identifier{Value: []byte("A")}, FunctionName: &ast.Identifier{Value: []byte("A")},
Params: []ast.Vertex{ Params: []ast.Vertex{
&ast.Parameter{ &ast.Parameter{
@ -534,7 +528,6 @@ func TestResolveMethodName(t *testing.T) {
nameBC := &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("B")}, &ast.NameNamePart{Value: []byte("C")}}} nameBC := &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("B")}, &ast.NameNamePart{Value: []byte("C")}}}
methodNode := &ast.StmtClassMethod{ methodNode := &ast.StmtClassMethod{
ReturnsRef: false,
MethodName: &ast.Identifier{Value: []byte("A")}, MethodName: &ast.Identifier{Value: []byte("A")},
Params: []ast.Vertex{ Params: []ast.Vertex{
&ast.Parameter{ &ast.Parameter{
@ -565,8 +558,6 @@ func TestResolveClosureName(t *testing.T) {
nameBC := &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("B")}, &ast.NameNamePart{Value: []byte("C")}}} nameBC := &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("B")}, &ast.NameNamePart{Value: []byte("C")}}}
closureNode := &ast.ExprClosure{ closureNode := &ast.ExprClosure{
ReturnsRef: false,
Static: false,
Params: []ast.Vertex{ Params: []ast.Vertex{
&ast.Parameter{ &ast.Parameter{
Type: nameAB, Type: nameAB,
@ -660,7 +651,6 @@ func TestResolveNamespaces(t *testing.T) {
&ast.ExprStaticCall{ &ast.ExprStaticCall{
Class: nameFG, Class: nameFG,
Call: &ast.Identifier{Value: []byte("foo")}, Call: &ast.Identifier{Value: []byte("foo")},
ArgumentList: &ast.ArgumentList{},
}, },
&ast.StmtNamespace{ &ast.StmtNamespace{
Stmts: []ast.Vertex{}, Stmts: []ast.Vertex{},
@ -678,12 +668,10 @@ func TestResolveNamespaces(t *testing.T) {
&ast.ExprStaticCall{ &ast.ExprStaticCall{
Class: relativeNameCE, Class: relativeNameCE,
Call: &ast.Identifier{Value: []byte("foo")}, Call: &ast.Identifier{Value: []byte("foo")},
ArgumentList: &ast.ArgumentList{},
}, },
&ast.ExprStaticCall{ &ast.ExprStaticCall{
Class: nameCF, Class: nameCF,
Call: &ast.Identifier{Value: []byte("foo")}, Call: &ast.Identifier{Value: []byte("foo")},
ArgumentList: &ast.ArgumentList{},
}, },
}, },
}, },
@ -711,7 +699,6 @@ func TestResolveStaticCallDinamicClassName(t *testing.T) {
&ast.ExprStaticCall{ &ast.ExprStaticCall{
Class: &ast.ExprVariable{VarName: &ast.Identifier{Value: []byte("foo")}}, Class: &ast.ExprVariable{VarName: &ast.Identifier{Value: []byte("foo")}},
Call: &ast.Identifier{Value: []byte("foo")}, Call: &ast.Identifier{Value: []byte("foo")},
ArgumentList: &ast.ArgumentList{},
}, },
}, },
} }
@ -932,21 +919,18 @@ func TestDoNotResolveReservedSpecialNames(t *testing.T) {
Expr: &ast.ExprStaticCall{ Expr: &ast.ExprStaticCall{
Class: nameSelf, Class: nameSelf,
Call: &ast.Identifier{Value: []byte("func")}, Call: &ast.Identifier{Value: []byte("func")},
ArgumentList: &ast.ArgumentList{},
}, },
}, },
&ast.StmtExpression{ &ast.StmtExpression{
Expr: &ast.ExprStaticCall{ Expr: &ast.ExprStaticCall{
Class: nameStatic, Class: nameStatic,
Call: &ast.Identifier{Value: []byte("func")}, Call: &ast.Identifier{Value: []byte("func")},
ArgumentList: &ast.ArgumentList{},
}, },
}, },
&ast.StmtExpression{ &ast.StmtExpression{
Expr: &ast.ExprStaticCall{ Expr: &ast.ExprStaticCall{
Class: nameParent, Class: nameParent,
Call: &ast.Identifier{Value: []byte("func")}, Call: &ast.Identifier{Value: []byte("func")},
ArgumentList: &ast.ArgumentList{},
}, },
}, },
}, },