mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 13:48:06 +00:00
Fixes with operation bug #1174
This commit is contained in:
parent
13a27e8b2d
commit
6f9f80cc48
@ -20,11 +20,15 @@ func withOperator(d *dataTreeNavigator, context Context, expressionNode *Express
|
||||
|
||||
updateExp := expressionNode.RHS.RHS
|
||||
|
||||
_, err = d.GetMatchingNodes(updateContext, updateExp)
|
||||
for el := updateContext.MatchingNodes.Front(); el != nil; el = el.Next() {
|
||||
candidate := el.Value.(*CandidateNode)
|
||||
_, err = d.GetMatchingNodes(updateContext.SingleChildContext(candidate), updateExp)
|
||||
if err != nil {
|
||||
return Context{}, err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return context, nil
|
||||
|
||||
}
|
||||
|
@ -28,6 +28,16 @@ var withOperatorScenarios = []expressionScenario{
|
||||
"D0, P[], (doc)::myArray: [{a: apple, b: apple yum}, {a: banana, b: banana yum}]\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "Update array elements relatively +=",
|
||||
skipDoc: true,
|
||||
subdescription: "The second expression runs with each element of the array as it's contextual root. This allows you to make updates relative to the element.",
|
||||
document: `myArray: [{a: apple},{a: banana}]`,
|
||||
expression: `with(.myArray[]; .a += .a)`,
|
||||
expected: []string{
|
||||
"D0, P[], (doc)::myArray: [{a: appleapple}, {a: bananabanana}]\n",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestWithOperatorScenarios(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user