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

View File

@ -26,7 +26,6 @@ func TestResolveStaticCall(t *testing.T) {
&ast.ExprStaticCall{
Class: nameBC,
Call: &ast.Identifier{Value: []byte("foo")},
ArgumentList: &ast.ArgumentList{},
},
},
}
@ -119,7 +118,6 @@ func TestResolveNew(t *testing.T) {
},
&ast.ExprNew{
Class: nameBC,
ArgumentList: &ast.ArgumentList{},
},
},
}
@ -230,7 +228,6 @@ func TestResolveFunctionCall(t *testing.T) {
},
&ast.ExprFunctionCall{
Function: nameB,
ArgumentList: &ast.ArgumentList{},
},
},
}
@ -313,11 +310,9 @@ func TestResolveGroupUse(t *testing.T) {
},
&ast.ExprFunctionCall{
Function: nameF,
ArgumentList: &ast.ArgumentList{},
},
&ast.ExprFunctionCall{
Function: nameE,
ArgumentList: &ast.ArgumentList{},
},
},
}
@ -359,7 +354,7 @@ func TestResolveTraitUse(t *testing.T) {
nameB,
relativeNameB,
},
TraitAdaptationList: &ast.StmtTraitAdaptationList{
Adaptations: &ast.StmtTraitAdaptationList{
Adaptations: []ast.Vertex{
&ast.StmtTraitUsePrecedence{
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")}}}
functionNode := &ast.StmtFunction{
ReturnsRef: false,
FunctionName: &ast.Identifier{Value: []byte("A")},
Params: []ast.Vertex{
&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")}}}
methodNode := &ast.StmtClassMethod{
ReturnsRef: false,
MethodName: &ast.Identifier{Value: []byte("A")},
Params: []ast.Vertex{
&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")}}}
closureNode := &ast.ExprClosure{
ReturnsRef: false,
Static: false,
Params: []ast.Vertex{
&ast.Parameter{
Type: nameAB,
@ -660,7 +651,6 @@ func TestResolveNamespaces(t *testing.T) {
&ast.ExprStaticCall{
Class: nameFG,
Call: &ast.Identifier{Value: []byte("foo")},
ArgumentList: &ast.ArgumentList{},
},
&ast.StmtNamespace{
Stmts: []ast.Vertex{},
@ -678,12 +668,10 @@ func TestResolveNamespaces(t *testing.T) {
&ast.ExprStaticCall{
Class: relativeNameCE,
Call: &ast.Identifier{Value: []byte("foo")},
ArgumentList: &ast.ArgumentList{},
},
&ast.ExprStaticCall{
Class: nameCF,
Call: &ast.Identifier{Value: []byte("foo")},
ArgumentList: &ast.ArgumentList{},
},
},
},
@ -711,7 +699,6 @@ func TestResolveStaticCallDinamicClassName(t *testing.T) {
&ast.ExprStaticCall{
Class: &ast.ExprVariable{VarName: &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{
Class: nameSelf,
Call: &ast.Identifier{Value: []byte("func")},
ArgumentList: &ast.ArgumentList{},
},
},
&ast.StmtExpression{
Expr: &ast.ExprStaticCall{
Class: nameStatic,
Call: &ast.Identifier{Value: []byte("func")},
ArgumentList: &ast.ArgumentList{},
},
},
&ast.StmtExpression{
Expr: &ast.ExprStaticCall{
Class: nameParent,
Call: &ast.Identifier{Value: []byte("func")},
ArgumentList: &ast.ArgumentList{},
},
},
},