[#82] array item unpack
This commit is contained in:
@@ -1304,6 +1304,10 @@ func (p *Printer) printExprArrayItem(n node.Node) {
|
||||
nn := n.(*expr.ArrayItem)
|
||||
p.printFreeFloating(nn, freefloating.Start)
|
||||
|
||||
if nn.Unpack {
|
||||
io.WriteString(p.w, "...")
|
||||
}
|
||||
|
||||
if nn.Key != nil {
|
||||
p.Print(nn.Key)
|
||||
p.printFreeFloating(nn, freefloating.Expr)
|
||||
|
||||
@@ -384,6 +384,7 @@ func TestParseAndPrintArrayItem(t *testing.T) {
|
||||
$world ,
|
||||
& $world ,
|
||||
'Hello' => $world ,
|
||||
... $unpack
|
||||
] ;
|
||||
`
|
||||
|
||||
|
||||
@@ -1551,6 +1551,25 @@ func TestPrinterPrintExprArrayItem(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrinterPrintExprArrayItemUnpack(t *testing.T) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
p := printer.NewPrinter(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 TestPrinterPrintExprArray(t *testing.T) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user