diff --git a/node/expr/n_array_item.go b/node/expr/n_array_item.go index 1ac202f..5f5a07a 100644 --- a/node/expr/n_array_item.go +++ b/node/expr/n_array_item.go @@ -13,14 +13,16 @@ type ArrayItem struct { Position *position.Position Key node.Node Val node.Node + Unpack bool } // NewArrayItem node constructor -func NewArrayItem(Key node.Node, Val node.Node) *ArrayItem { +func NewArrayItem(Key node.Node, Val node.Node, Unpack bool) *ArrayItem { return &ArrayItem{ FreeFloating: nil, Key: Key, Val: Val, + Unpack: Unpack, } } @@ -40,7 +42,9 @@ func (n *ArrayItem) GetFreeFloating() *freefloating.Collection { // Attributes returns node attributes as map func (n *ArrayItem) Attributes() map[string]interface{} { - return nil + return map[string]interface{}{ + "Unpack": n.Unpack, + } } // Walk traverses nodes diff --git a/node/expr/t_array_test.go b/node/expr/t_array_test.go index 0776e84..559fca8 100644 --- a/node/expr/t_array_test.go +++ b/node/expr/t_array_test.go @@ -218,3 +218,67 @@ func TestArrayItems(t *testing.T) { actual = php5parser.GetRootNode() assert.DeepEqual(t, expected, actual) } + +func TestArrayItemUnpack(t *testing.T) { + src := ` $world , + ... $unpack ] ; ` diff --git a/printer/printer_test.go b/printer/printer_test.go index 8bf928f..331de66 100644 --- a/printer/printer_test.go +++ b/printer/printer_test.go @@ -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("")