#44: do not trim last nil if array item list ends by a comma
This commit is contained in:
@@ -81,6 +81,7 @@ func TestArrayItems(t *testing.T) {
|
||||
&expr.ArrayItem{
|
||||
Val: &expr.Reference{Variable: &expr.Variable{VarName: &node.Identifier{Value: "b"}}},
|
||||
},
|
||||
nil,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -173,3 +173,37 @@ func TestListEmptyItem(t *testing.T) {
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestListEmptyItems(t *testing.T) {
|
||||
src := `<? list(, , $a, ) = $b;`
|
||||
|
||||
expected := &node.Root{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &assign.Assign{
|
||||
Variable: &expr.List{
|
||||
Items: []node.Node{
|
||||
nil,
|
||||
nil,
|
||||
&expr.ArrayItem{
|
||||
Val: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
},
|
||||
nil,
|
||||
},
|
||||
},
|
||||
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
@@ -81,6 +81,7 @@ func TestShortArrayItems(t *testing.T) {
|
||||
&expr.ArrayItem{
|
||||
Val: &expr.Reference{Variable: &expr.Variable{VarName: &node.Identifier{Value: "b"}}},
|
||||
},
|
||||
nil,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user