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

77 lines
1.3 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"
"github.com/z7zmey/php-parser/pkg/position"
"github.com/z7zmey/php-parser/pkg/token"
2020-12-28 19:13:08 +00:00
"github.com/z7zmey/php-parser/pkg/visitor/dumper"
2020-12-11 11:28:16 +00:00
"testing"
2020-03-12 22:20:48 +00:00
"github.com/z7zmey/php-parser/pkg/ast"
)
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,
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,
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
}