[#82] array item unpack

This commit is contained in:
z7zmey
2019-12-29 22:42:52 +02:00
parent dc7aa7302d
commit d552681a7d
10 changed files with 982 additions and 863 deletions

View File

@@ -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)

View File

@@ -384,6 +384,7 @@ func TestParseAndPrintArrayItem(t *testing.T) {
$world ,
& $world ,
'Hello' => $world ,
... $unpack
] ;
`

View File

@@ -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("")