pretty printer: print Finally
This commit is contained in:
parent
94ffbdfe59
commit
5cc62dd8ee
@ -312,11 +312,13 @@ func getPrintFuncByNode(n node.Node) func(o io.Writer, n node.Node) {
|
|||||||
return printStmtElseif
|
return printStmtElseif
|
||||||
case *stmt.Else:
|
case *stmt.Else:
|
||||||
return printStmtElse
|
return printStmtElse
|
||||||
|
case *stmt.Expression:
|
||||||
|
return printStmtExpression
|
||||||
|
case *stmt.Finally:
|
||||||
|
return printStmtFinally
|
||||||
|
|
||||||
case *stmt.StmtList:
|
case *stmt.StmtList:
|
||||||
return printStmtStmtList
|
return printStmtStmtList
|
||||||
case *stmt.Expression:
|
|
||||||
return printStmtExpression
|
|
||||||
case *stmt.Nop:
|
case *stmt.Nop:
|
||||||
return printStmtNop
|
return printStmtNop
|
||||||
}
|
}
|
||||||
@ -1537,12 +1539,6 @@ func printStmtElse(o io.Writer, n node.Node) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func printStmtStmtList(o io.Writer, n node.Node) {
|
|
||||||
nn := n.(*stmt.StmtList)
|
|
||||||
|
|
||||||
printNodes(o, nn.Stmts)
|
|
||||||
}
|
|
||||||
|
|
||||||
func printStmtExpression(o io.Writer, n node.Node) {
|
func printStmtExpression(o io.Writer, n node.Node) {
|
||||||
nn := n.(*stmt.Expression)
|
nn := n.(*stmt.Expression)
|
||||||
|
|
||||||
@ -1551,6 +1547,20 @@ func printStmtExpression(o io.Writer, n node.Node) {
|
|||||||
io.WriteString(o, ";\n")
|
io.WriteString(o, ";\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printStmtFinally(o io.Writer, n node.Node) {
|
||||||
|
nn := n.(*stmt.Finally)
|
||||||
|
|
||||||
|
io.WriteString(o, "finally {\n")
|
||||||
|
printNodes(o, nn.Stmts)
|
||||||
|
io.WriteString(o, "}\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func printStmtStmtList(o io.Writer, n node.Node) {
|
||||||
|
nn := n.(*stmt.StmtList)
|
||||||
|
|
||||||
|
printNodes(o, nn.Stmts)
|
||||||
|
}
|
||||||
|
|
||||||
func printStmtNop(o io.Writer, n node.Node) {
|
func printStmtNop(o io.Writer, n node.Node) {
|
||||||
io.WriteString(o, ";\n")
|
io.WriteString(o, ";\n")
|
||||||
}
|
}
|
||||||
|
@ -2500,6 +2500,36 @@ func TestPrintStmtElseNop(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPrintExpression(t *testing.T) {
|
||||||
|
o := bytes.NewBufferString("")
|
||||||
|
|
||||||
|
printer.Print(o, &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}})
|
||||||
|
|
||||||
|
expected := "$a;\n"
|
||||||
|
actual := o.String()
|
||||||
|
|
||||||
|
if expected != actual {
|
||||||
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPrintStmtFinally(t *testing.T) {
|
||||||
|
o := bytes.NewBufferString("")
|
||||||
|
|
||||||
|
printer.Print(o, &stmt.Finally{
|
||||||
|
Stmts: []node.Node{
|
||||||
|
&stmt.Nop{},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
expected := "finally {\n;\n}\n"
|
||||||
|
actual := o.String()
|
||||||
|
|
||||||
|
if expected != actual {
|
||||||
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestPrintStmtList(t *testing.T) {
|
func TestPrintStmtList(t *testing.T) {
|
||||||
o := bytes.NewBufferString("")
|
o := bytes.NewBufferString("")
|
||||||
|
|
||||||
@ -2518,19 +2548,6 @@ func TestPrintStmtList(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrintExpression(t *testing.T) {
|
|
||||||
o := bytes.NewBufferString("")
|
|
||||||
|
|
||||||
printer.Print(o, &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}})
|
|
||||||
|
|
||||||
expected := "$a;\n"
|
|
||||||
actual := o.String()
|
|
||||||
|
|
||||||
if expected != actual {
|
|
||||||
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPrintNop(t *testing.T) {
|
func TestPrintNop(t *testing.T) {
|
||||||
o := bytes.NewBufferString("")
|
o := bytes.NewBufferString("")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user