mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-24 23:35:40 +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)
|
shouldDelete := fmt.Sprintf("%v", index) == fmt.Sprintf("%v", childPath)
|
||||||
|
|
||||||
if !shouldDelete {
|
if !shouldDelete {
|
||||||
|
value.Key.Value = fmt.Sprintf("%v", len(newContents))
|
||||||
newContents = append(newContents, value)
|
newContents = append(newContents, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,6 +179,15 @@ var deleteOperatorScenarios = []expressionScenario{
|
|||||||
"D0, P[], (!!map)::{a: {b: {age: 12}}}\n",
|
"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) {
|
func TestDeleteOperatorScenarios(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user