printer: handle array item unpack in pretty printer
Signed-off-by: Iskander Sharipov <quasilyte@gmail.com>
This commit is contained in:
parent
cbf185c8f4
commit
f8bd680ca0
@ -972,6 +972,10 @@ func (p *PrettyPrinter) printExprArrayDimFetch(n node.Node) {
|
|||||||
func (p *PrettyPrinter) printExprArrayItem(n node.Node) {
|
func (p *PrettyPrinter) printExprArrayItem(n node.Node) {
|
||||||
nn := n.(*expr.ArrayItem)
|
nn := n.(*expr.ArrayItem)
|
||||||
|
|
||||||
|
if nn.Unpack {
|
||||||
|
io.WriteString(p.w, "...")
|
||||||
|
}
|
||||||
|
|
||||||
if nn.Key != nil {
|
if nn.Key != nil {
|
||||||
p.Print(nn.Key)
|
p.Print(nn.Key)
|
||||||
io.WriteString(p.w, " => ")
|
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) {
|
func TestPrintExprArray(t *testing.T) {
|
||||||
o := bytes.NewBufferString("")
|
o := bytes.NewBufferString("")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user