php-parser/pkg/visitor/dumper/dumper_test.go

82 lines
1.4 KiB
Go
Raw Normal View History

2020-12-28 19:13:08 +00:00
package dumper_test
2020-03-12 22:20:48 +00:00
import (
2020-12-11 11:28:16 +00:00
"bytes"
"testing"
2023-12-09 21:36:19 +00:00
"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"
2023-12-09 21:36:19 +00:00
"git.maride.cc/maride/php-parser/pkg/ast"
2020-03-12 22:20:48 +00:00
)
2020-12-11 11:28:16 +00:00
func TestDumper_root(t *testing.T) {
o := bytes.NewBufferString("")
2020-12-28 19:13:08 +00:00
p := dumper.NewDumper(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,
StartCol: 0,
EndCol: 0,
2020-12-11 11:28:16 +00:00
StartPos: 3,
EndPos: 4,
},
Stmts: []ast.Vertex{
&ast.StmtNop{
},
},
EndTkn: &token.Token{
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
2020-12-28 21:01:02 +00:00
Val: []byte(" "),
2020-12-11 11:28:16 +00:00
Position: &position.Position{
StartLine: 1,
EndLine: 2,
StartCol: 0,
EndCol: 0,
2020-12-11 11:28:16 +00:00
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
}