refactoring: update traverser
This commit is contained in:
2345
pkg/visitor/dumper/dumper.go
Normal file
2345
pkg/visitor/dumper/dumper.go
Normal file
File diff suppressed because it is too large
Load Diff
76
pkg/visitor/dumper/dumper_test.go
Normal file
76
pkg/visitor/dumper/dumper_test.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package dumper_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/z7zmey/php-parser/pkg/position"
|
||||
"github.com/z7zmey/php-parser/pkg/token"
|
||||
"github.com/z7zmey/php-parser/pkg/visitor/dumper"
|
||||
"testing"
|
||||
|
||||
"github.com/z7zmey/php-parser/pkg/ast"
|
||||
)
|
||||
|
||||
func TestDumper_root(t *testing.T) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
p := dumper.NewDumper(o).WithTokens().WithPositions()
|
||||
n := &ast.Root{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 2,
|
||||
StartPos: 3,
|
||||
EndPos: 4,
|
||||
},
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtNop{},
|
||||
},
|
||||
EndTkn: &token.Token{
|
||||
FreeFloating: []*token.Token{
|
||||
{
|
||||
ID: token.T_WHITESPACE,
|
||||
Value: []byte(" "),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 2,
|
||||
StartPos: 3,
|
||||
EndPos: 4,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
n.Accept(p)
|
||||
|
||||
expected := `&ast.Root{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 2,
|
||||
StartPos: 3,
|
||||
EndPos: 4,
|
||||
},
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtNop{
|
||||
},
|
||||
},
|
||||
EndTkn: &token.Token{
|
||||
FreeFloating: []*token.Token{
|
||||
{
|
||||
ID: token.T_WHITESPACE,
|
||||
Value: []byte(" "),
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 2,
|
||||
StartPos: 3,
|
||||
EndPos: 4,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
`
|
||||
actual := o.String()
|
||||
|
||||
if expected != actual {
|
||||
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user