Merge branch 'master' into refactoring
This commit is contained in:
@@ -411,11 +411,12 @@ func (p *PrettyPrinter) printNode(n ast.Vertex) {
|
||||
// node
|
||||
|
||||
func (p *PrettyPrinter) printNodeRoot(n ast.Vertex) {
|
||||
var stmts []ast.Vertex
|
||||
v := n.(*ast.Root)
|
||||
|
||||
if len(v.Stmts) > 0 {
|
||||
firstStmt := v.Stmts[0]
|
||||
v.Stmts = v.Stmts[1:]
|
||||
stmts = v.Stmts[1:]
|
||||
|
||||
switch fs := firstStmt.(type) {
|
||||
case *ast.StmtInlineHtml:
|
||||
@@ -429,7 +430,7 @@ func (p *PrettyPrinter) printNodeRoot(n ast.Vertex) {
|
||||
}
|
||||
}
|
||||
p.indentDepth--
|
||||
p.printNodes(v.Stmts)
|
||||
p.printNodes(stmts)
|
||||
io.WriteString(p.w, "\n")
|
||||
}
|
||||
|
||||
|
||||
@@ -9,10 +9,17 @@ import (
|
||||
)
|
||||
|
||||
func TestPrintFile(t *testing.T) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
p := printer.NewPrettyPrinter(o, "\t")
|
||||
p.Print(&ast.Root{
|
||||
expected := `<?php
|
||||
namespace Foo;
|
||||
abstract class Bar extends Baz
|
||||
{
|
||||
public function greet()
|
||||
{
|
||||
echo 'Hello world';
|
||||
}
|
||||
}
|
||||
`
|
||||
rootNode := &ast.Root{
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtNamespace{
|
||||
NamespaceName: &ast.NameName{
|
||||
@@ -52,22 +59,20 @@ func TestPrintFile(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expected := `<?php
|
||||
namespace Foo;
|
||||
abstract class Bar extends Baz
|
||||
{
|
||||
public function greet()
|
||||
{
|
||||
echo 'Hello world';
|
||||
}
|
||||
}
|
||||
`
|
||||
actual := o.String()
|
||||
|
||||
if expected != actual {
|
||||
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
||||
o1 := bytes.NewBufferString("")
|
||||
p1 := printer.NewPrettyPrinter(o1, "\t")
|
||||
p1.Print(rootNode)
|
||||
if actual := o1.String(); expected != actual {
|
||||
t.Errorf("\nPrint the 1st time\nexpected: %s\ngot: %s\n", expected, actual)
|
||||
}
|
||||
|
||||
o2 := bytes.NewBufferString("")
|
||||
p2 := printer.NewPrettyPrinter(o2, "\t")
|
||||
p2.Print(rootNode)
|
||||
if actual := o2.String(); expected != actual {
|
||||
t.Errorf("\nPrint the 2nd time\nexpected: %s\ngot: %s\n", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2925,7 +2925,7 @@ func TestPrinterPrintStmtClassMethod(t *testing.T) {
|
||||
MethodName: &ast.Identifier{Value: []byte("foo")},
|
||||
Params: []ast.Vertex{
|
||||
&ast.Parameter{
|
||||
Type: &ast.Nullable{Expr: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("int")}}}},
|
||||
Type: &ast.Nullable{Expr: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("int")}}}},
|
||||
Var: &ast.Reference{
|
||||
Var: &ast.ExprVariable{
|
||||
VarName: &ast.Identifier{Value: []byte("$a")},
|
||||
@@ -2974,7 +2974,7 @@ func TestPrinterPrintStmtAbstractClassMethod(t *testing.T) {
|
||||
MethodName: &ast.Identifier{Value: []byte("foo")},
|
||||
Params: []ast.Vertex{
|
||||
&ast.Parameter{
|
||||
Type: &ast.Nullable{Expr: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("int")}}}},
|
||||
Type: &ast.Nullable{Expr: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("int")}}}},
|
||||
Var: &ast.Reference{
|
||||
Var: &ast.ExprVariable{
|
||||
VarName: &ast.Identifier{Value: []byte("$a")},
|
||||
|
||||
Reference in New Issue
Block a user