Merge pull request #116 from quasilyte/quasilyte/fix/pretty_printer_array_item_unpack
printer: handle array item unpack in pretty printer
This commit is contained in:
commit
0cd26d7f4b
@ -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, " => ")
|
||||
|
@ -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("")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user