mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-02 10:31:40 +00:00
Fixing add when there is no node match #2325
This commit is contained in:
parent
1395d6e230
commit
337960a6d1
@ -39,13 +39,19 @@ func toNodes(candidate *CandidateNode, lhs *CandidateNode) []*CandidateNode {
|
||||
func addOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
|
||||
log.Debugf("Add operator")
|
||||
|
||||
return crossFunction(d, context.ReadOnlyClone(), expressionNode, add, false)
|
||||
return crossFunction(d, context.ReadOnlyClone(), expressionNode, add, true)
|
||||
}
|
||||
|
||||
func add(_ *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) {
|
||||
lhsNode := lhs
|
||||
|
||||
if lhsNode.Tag == "!!null" {
|
||||
if lhs == nil && rhs == nil {
|
||||
return nil, nil
|
||||
} else if lhs == nil {
|
||||
return rhs.Copy(), nil
|
||||
} else if rhs == nil {
|
||||
return lhs.Copy(), nil
|
||||
} else if lhsNode.Tag == "!!null" {
|
||||
return lhs.CopyAsReplacement(rhs), nil
|
||||
}
|
||||
|
||||
|
||||
@ -310,6 +310,15 @@ var addOperatorScenarios = []expressionScenario{
|
||||
"D0, P[], (!!map)::a: !cat Saturday, 15-Dec-01 at 6:00AM GMT\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
description: "Add to empty",
|
||||
subdescription: "should behave like null",
|
||||
expression: `.nada + "cat"`,
|
||||
expected: []string{
|
||||
"D0, P[], (!!str)::cat\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "Add to null",
|
||||
subdescription: "Adding to null simply returns the rhs",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user