mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-13 22:38:04 +00:00
Fixed += with multiple matches #1145
This commit is contained in:
parent
99cd9e8aae
commit
0ffee92175
@ -161,15 +161,13 @@ func addSequences(target *CandidateNode, lhs *CandidateNode, rhs *CandidateNode)
|
||||
target.Node.Style = lhs.Node.Style
|
||||
}
|
||||
target.Node.Tag = lhs.Node.Tag
|
||||
target.Node.Content = make([]*yaml.Node, len(lhs.Node.Content))
|
||||
copy(target.Node.Content, lhs.Node.Content)
|
||||
|
||||
extraNodes, err := toNodes(rhs, lhs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
target.Node.Content = append(target.Node.Content, extraNodes...)
|
||||
target.Node.Content = append(deepCloneContent(lhs.Node.Content), extraNodes...)
|
||||
return nil
|
||||
|
||||
}
|
||||
|
@ -14,6 +14,15 @@ var addOperatorScenarios = []expressionScenario{
|
||||
"D0, P[1 a], (!!int)::3\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
document: `[[c], [b]]`,
|
||||
expression: `.[] | . += "a"`,
|
||||
expected: []string{
|
||||
"D0, P[0], (!!seq)::[c, a]\n",
|
||||
"D0, P[1], (!!seq)::[b, a]\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
document: `{}`,
|
||||
|
@ -93,6 +93,15 @@ var multiplyOperatorScenarios = []expressionScenario{
|
||||
"D0, P[], (!!map)::sample:\n - &a\n - !!merge <<: *a\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
document: `[[c], [b]]`,
|
||||
expression: `.[] | . *+ ["a"]`,
|
||||
expected: []string{
|
||||
"D0, P[0], (!!seq)::[c, a]\n",
|
||||
"D0, P[1], (!!seq)::[b, a]\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
document: docWithHeader,
|
||||
|
@ -19,14 +19,18 @@ func compoundAssignFunction(d *dataTreeNavigator, context Context, expressionNod
|
||||
}
|
||||
|
||||
assignmentOp := &Operation{OperationType: assignOpType, Preferences: expressionNode.Operation.Preferences}
|
||||
valueOp := &Operation{OperationType: valueOpType}
|
||||
|
||||
for el := lhs.MatchingNodes.Front(); el != nil; el = el.Next() {
|
||||
candidate := el.Value.(*CandidateNode)
|
||||
valueOp.CandidateNode = candidate
|
||||
valueExpression := &ExpressionNode{Operation: valueOp}
|
||||
clone, err := candidate.Copy()
|
||||
if err != nil {
|
||||
return Context{}, err
|
||||
}
|
||||
valueCopyExp := &ExpressionNode{Operation: &Operation{OperationType: valueOpType, CandidateNode: clone}}
|
||||
|
||||
assignmentOpNode := &ExpressionNode{Operation: assignmentOp, LHS: valueExpression, RHS: calculation(valueExpression, expressionNode.RHS)}
|
||||
valueExpression := &ExpressionNode{Operation: &Operation{OperationType: valueOpType, CandidateNode: candidate}}
|
||||
|
||||
assignmentOpNode := &ExpressionNode{Operation: assignmentOp, LHS: valueExpression, RHS: calculation(valueCopyExp, expressionNode.RHS)}
|
||||
|
||||
_, err = d.GetMatchingNodes(context, assignmentOpNode)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user