mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-24 14:45:39 +00:00
Make sure to update the key when deleting array elements
This commit is contained in:
parent
3bca3a23c0
commit
c16b1800a0
@ -81,6 +81,7 @@ func deleteFromArray(node *CandidateNode, childPath interface{}) {
|
||||
shouldDelete := fmt.Sprintf("%v", index) == fmt.Sprintf("%v", childPath)
|
||||
|
||||
if !shouldDelete {
|
||||
value.Key.Value = fmt.Sprintf("%v", len(newContents))
|
||||
newContents = append(newContents, value)
|
||||
}
|
||||
}
|
||||
|
@ -179,6 +179,15 @@ var deleteOperatorScenarios = []expressionScenario{
|
||||
"D0, P[], (!!map)::{a: {b: {age: 12}}}\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
description: "Repeatedly delete the first element of a list",
|
||||
document: `a: [0, 1, 2, 3]`,
|
||||
expression: `del(.a[0]) | del(.a[0])`,
|
||||
expected: []string{
|
||||
"D0, P[], (!!map)::a: [2, 3]\n",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestDeleteOperatorScenarios(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user