mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Fixed delete bug
This commit is contained in:
parent
3a464272d4
commit
10600dd29a
@ -13,8 +13,8 @@ func deleteChildOperator(d *dataTreeNavigator, context Context, expressionNode *
|
||||
if err != nil {
|
||||
return Context{}, err
|
||||
}
|
||||
|
||||
for el := nodesToDelete.MatchingNodes.Front(); el != nil; el = el.Next() {
|
||||
//need to iterate backwards to ensure correct indices when deleting multiple
|
||||
for el := nodesToDelete.MatchingNodes.Back(); el != nil; el = el.Prev() {
|
||||
candidate := el.Value.(*CandidateNode)
|
||||
|
||||
deleteImmediateChildOp := &Operation{
|
||||
|
@ -37,6 +37,22 @@ var deleteOperatorScenarios = []expressionScenario{
|
||||
"D0, P[], (doc)::[1, 3]\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
document: `a: [1,2,3]`,
|
||||
expression: `del(.a[])`,
|
||||
expected: []string{
|
||||
"D0, P[], (doc)::a: []\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
document: `a: [10,x,10, 10, x, 10]`,
|
||||
expression: `del(.a[] | select(. == 10))`,
|
||||
expected: []string{
|
||||
"D0, P[], (doc)::a: [x, x]\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "Delete nested entry in array",
|
||||
document: `[{a: cat, b: dog}]`,
|
||||
|
Loading…
Reference in New Issue
Block a user