php-parser/pkg/visitor/dumper/dumper_test.go
2023-12-10 00:36:22 +01:00

82 lines
1.4 KiB
Go

package dumper_test
import (
"bytes"
"testing"
"git.maride.cc/maride/php-parser/pkg/position"
"git.maride.cc/maride/php-parser/pkg/token"
"git.maride.cc/maride/php-parser/pkg/visitor/dumper"
"git.maride.cc/maride/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,
StartCol: 0,
EndCol: 0,
StartPos: 3,
EndPos: 4,
},
Stmts: []ast.Vertex{
&ast.StmtNop{
},
},
EndTkn: &token.Token{
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Val: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 2,
StartCol: 0,
EndCol: 0,
StartPos: 3,
EndPos: 4,
},
},
},
},
},
`
actual := o.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}