diff --git a/printer/pretty_printer.go b/printer/pretty_printer.go index bfe6660..980b597 100644 --- a/printer/pretty_printer.go +++ b/printer/pretty_printer.go @@ -972,6 +972,10 @@ func (p *PrettyPrinter) printExprArrayDimFetch(n node.Node) { func (p *PrettyPrinter) printExprArrayItem(n node.Node) { nn := n.(*expr.ArrayItem) + if nn.Unpack { + io.WriteString(p.w, "...") + } + if nn.Key != nil { p.Print(nn.Key) io.WriteString(p.w, " => ") diff --git a/printer/pretty_printer_test.go b/printer/pretty_printer_test.go index e45f5e6..7e903c4 100644 --- a/printer/pretty_printer_test.go +++ b/printer/pretty_printer_test.go @@ -1278,6 +1278,25 @@ func TestPrintExprArrayItem(t *testing.T) { } } +func TestPrintExprArrayItemUnpack(t *testing.T) { + o := bytes.NewBufferString("") + + p := printer.NewPrettyPrinter(o, " ") + p.Print(&expr.ArrayItem{ + Unpack: true, + Val: &expr.Variable{ + VarName: &node.Identifier{Value: "world"}, + }, + }) + + expected := `...$world` + actual := o.String() + + if expected != actual { + t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + func TestPrintExprArray(t *testing.T) { o := bytes.NewBufferString("")