php-parser/pkg/ast/visitor/dump_test.go

77 lines
1.3 KiB
Go
Raw Normal View History

2020-03-12 22:20:48 +00:00
package visitor_test
import (
2020-12-11 11:28:16 +00:00
"bytes"
"github.com/z7zmey/php-parser/pkg/position"
"github.com/z7zmey/php-parser/pkg/token"
"testing"
2020-03-12 22:20:48 +00:00
"github.com/z7zmey/php-parser/pkg/ast"
"github.com/z7zmey/php-parser/pkg/ast/visitor"
)
2020-12-11 11:28:16 +00:00
func TestDumper_root(t *testing.T) {
o := bytes.NewBufferString("")
2020-12-11 15:29:22 +00:00
p := visitor.NewDump(o).WithTokens().WithPositions()
2020-12-11 11:28:16 +00:00
n := &ast.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 2,
StartPos: 3,
EndPos: 4,
},
2020-03-12 22:20:48 +00:00
Stmts: []ast.Vertex{
2020-12-11 11:28:16 +00:00
&ast.StmtNop{},
2020-03-12 22:20:48 +00:00
},
EndTkn: &token.Token{
2020-12-11 11:28:16 +00:00
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 2,
StartPos: 3,
EndPos: 4,
},
},
},
},
2020-03-12 22:20:48 +00:00
}
2020-12-11 11:28:16 +00:00
n.Accept(p)
2020-03-12 22:20:48 +00:00
2020-12-11 11:28:16 +00:00
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()
2020-03-12 22:20:48 +00:00
2020-12-11 11:28:16 +00:00
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
2020-03-12 22:20:48 +00:00
}