Fixes with operation bug #1174

This commit is contained in:
Mike Farah 2022-04-14 12:03:18 +10:00
parent 13a27e8b2d
commit 6f9f80cc48
2 changed files with 17 additions and 3 deletions

View File

@ -20,9 +20,13 @@ func withOperator(d *dataTreeNavigator, context Context, expressionNode *Express
updateExp := expressionNode.RHS.RHS updateExp := expressionNode.RHS.RHS
_, err = d.GetMatchingNodes(updateContext, updateExp) for el := updateContext.MatchingNodes.Front(); el != nil; el = el.Next() {
if err != nil { candidate := el.Value.(*CandidateNode)
return Context{}, err _, err = d.GetMatchingNodes(updateContext.SingleChildContext(candidate), updateExp)
if err != nil {
return Context{}, err
}
} }
return context, nil return context, nil

View File

@ -28,6 +28,16 @@ var withOperatorScenarios = []expressionScenario{
"D0, P[], (doc)::myArray: [{a: apple, b: apple yum}, {a: banana, b: banana yum}]\n", "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) { func TestWithOperatorScenarios(t *testing.T) {