pretty printer: print Continue
This commit is contained in:
parent
cbc46cb612
commit
685b7b25bd
@ -290,15 +290,17 @@ func getPrintFuncByNode(n node.Node) func(o io.Writer, n node.Node) {
|
||||
return printStmtCase
|
||||
case *stmt.Catch:
|
||||
return printStmtCatch
|
||||
case *stmt.ClassConstList:
|
||||
return printStmtClassConstList
|
||||
case *stmt.ClassMethod:
|
||||
return printStmtClassMethod
|
||||
case *stmt.Class:
|
||||
return printStmtClass
|
||||
|
||||
case *stmt.ClassConstList:
|
||||
return printStmtClassConstList
|
||||
case *stmt.Constant:
|
||||
return printStmtConstant
|
||||
case *stmt.Continue:
|
||||
return printStmtContinue
|
||||
|
||||
case *stmt.StmtList:
|
||||
return printStmtStmtList
|
||||
case *stmt.Expression:
|
||||
@ -1326,20 +1328,6 @@ func printStmtCatch(o io.Writer, n node.Node) {
|
||||
io.WriteString(o, "}\n")
|
||||
}
|
||||
|
||||
func printStmtClassConstList(o io.Writer, n node.Node) {
|
||||
nn := n.(*stmt.ClassConstList)
|
||||
|
||||
if nn.Modifiers != nil {
|
||||
joinPrint(" ", o, nn.Modifiers)
|
||||
io.WriteString(o, " ")
|
||||
}
|
||||
io.WriteString(o, "const ")
|
||||
|
||||
joinPrint(", ", o, nn.Consts)
|
||||
|
||||
io.WriteString(o, ";\n")
|
||||
}
|
||||
|
||||
func printStmtClassMethod(o io.Writer, n node.Node) {
|
||||
nn := n.(*stmt.ClassMethod)
|
||||
|
||||
@ -1403,6 +1391,20 @@ func printStmtClass(o io.Writer, n node.Node) {
|
||||
io.WriteString(o, "}\n") // TODO: handle indentation
|
||||
}
|
||||
|
||||
func printStmtClassConstList(o io.Writer, n node.Node) {
|
||||
nn := n.(*stmt.ClassConstList)
|
||||
|
||||
if nn.Modifiers != nil {
|
||||
joinPrint(" ", o, nn.Modifiers)
|
||||
io.WriteString(o, " ")
|
||||
}
|
||||
io.WriteString(o, "const ")
|
||||
|
||||
joinPrint(", ", o, nn.Consts)
|
||||
|
||||
io.WriteString(o, ";\n")
|
||||
}
|
||||
|
||||
func printStmtConstant(o io.Writer, n node.Node) {
|
||||
nn := n.(*stmt.Constant)
|
||||
|
||||
@ -1411,6 +1413,18 @@ func printStmtConstant(o io.Writer, n node.Node) {
|
||||
Print(o, nn.Expr)
|
||||
}
|
||||
|
||||
func printStmtContinue(o io.Writer, n node.Node) {
|
||||
nn := n.(*stmt.Continue)
|
||||
|
||||
io.WriteString(o, "continue")
|
||||
if nn.Expr != nil {
|
||||
io.WriteString(o, " ")
|
||||
Print(o, nn.Expr)
|
||||
}
|
||||
|
||||
io.WriteString(o, ";\n")
|
||||
}
|
||||
|
||||
func printStmtStmtList(o io.Writer, n node.Node) {
|
||||
nn := n.(*stmt.StmtList)
|
||||
|
||||
|
@ -2087,31 +2087,6 @@ $a;
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrintStmtClassConstList(t *testing.T) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
printer.Print(o, &stmt.ClassConstList{
|
||||
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
||||
Consts: []node.Node{
|
||||
&stmt.Constant{
|
||||
ConstantName: &node.Identifier{Value: "FOO"},
|
||||
Expr: &scalar.String{Value: "a"},
|
||||
},
|
||||
&stmt.Constant{
|
||||
ConstantName: &node.Identifier{Value: "BAR"},
|
||||
Expr: &scalar.String{Value: "b"},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expected := "public const FOO = 'a', BAR = 'b';\n"
|
||||
actual := o.String()
|
||||
|
||||
if expected != actual {
|
||||
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrintStmtClassMethod(t *testing.T) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
@ -2228,6 +2203,31 @@ public const FOO = 'bar';
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrintStmtClassConstList(t *testing.T) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
printer.Print(o, &stmt.ClassConstList{
|
||||
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
||||
Consts: []node.Node{
|
||||
&stmt.Constant{
|
||||
ConstantName: &node.Identifier{Value: "FOO"},
|
||||
Expr: &scalar.String{Value: "a"},
|
||||
},
|
||||
&stmt.Constant{
|
||||
ConstantName: &node.Identifier{Value: "BAR"},
|
||||
Expr: &scalar.String{Value: "b"},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expected := "public const FOO = 'a', BAR = 'b';\n"
|
||||
actual := o.String()
|
||||
|
||||
if expected != actual {
|
||||
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrintStmtConstant(t *testing.T) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
@ -2244,6 +2244,21 @@ func TestPrintStmtConstant(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrintStmtContinue(t *testing.T) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
printer.Print(o, &stmt.Continue{
|
||||
Expr: &scalar.Lnumber{Value: "1"},
|
||||
})
|
||||
|
||||
expected := "continue 1;\n"
|
||||
actual := o.String()
|
||||
|
||||
if expected != actual {
|
||||
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrintStmtList(t *testing.T) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user