#44: do not trim last nil if array item list ends by a comma

This commit is contained in:
z7zmey
2018-06-26 12:22:51 +03:00
parent 10c63a30ae
commit 290645f3c9
9 changed files with 91 additions and 43 deletions

View File

@@ -81,6 +81,7 @@ func TestArrayItems(t *testing.T) {
&expr.ArrayItem{
Val: &expr.Reference{Variable: &expr.Variable{VarName: &node.Identifier{Value: "b"}}},
},
nil,
},
},
},

View File

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

View File

@@ -81,6 +81,7 @@ func TestShortArrayItems(t *testing.T) {
&expr.ArrayItem{
Val: &expr.Reference{Variable: &expr.Variable{VarName: &node.Identifier{Value: "b"}}},
},
nil,
},
},
},