mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-05 12:10:37 +00:00
Fixing running map against empty array bug #2359
This commit is contained in:
parent
734e2cd254
commit
22949df0fd
@ -41,6 +41,10 @@ func mapOperator(d *dataTreeNavigator, context Context, expressionNode *Expressi
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return Context{}, err
|
return Context{}, err
|
||||||
}
|
}
|
||||||
|
if splatted.MatchingNodes.Len() == 0 {
|
||||||
|
results.PushBack(candidate.Copy())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
result, err := d.GetMatchingNodes(splatted, expressionNode.RHS)
|
result, err := d.GetMatchingNodes(splatted, expressionNode.RHS)
|
||||||
log.Debug("expressionNode.Rhs %v", expressionNode.RHS.Operation.OperationType)
|
log.Debug("expressionNode.Rhs %v", expressionNode.RHS.Operation.OperationType)
|
||||||
|
|||||||
@ -15,6 +15,46 @@ var mapOperatorScenarios = []expressionScenario{
|
|||||||
"D0, P[], (!!seq)::[6, 7, 8]\n",
|
"D0, P[], (!!seq)::[6, 7, 8]\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "mapping against an empty array should do nothing",
|
||||||
|
skipDoc: true,
|
||||||
|
document: `[]`,
|
||||||
|
document2: `["cat"]`,
|
||||||
|
expression: `map(3)`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (!!seq)::[]\n",
|
||||||
|
"D0, P[], (!!seq)::[3]\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "mapping against an empty array should do nothing",
|
||||||
|
skipDoc: true,
|
||||||
|
document: `[[], [5]]`,
|
||||||
|
expression: `.[] |= map(3)`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (!!seq)::[[], [3]]\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "mapping against an empty array should do nothing #2",
|
||||||
|
skipDoc: true,
|
||||||
|
document: `[]`,
|
||||||
|
document2: `[5]`,
|
||||||
|
expression: `map(3 + .)`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (!!seq)::[]\n",
|
||||||
|
"D0, P[], (!!seq)::[8]\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "mapping against an empty array should do nothing",
|
||||||
|
skipDoc: true,
|
||||||
|
document: `[[], [5]]`,
|
||||||
|
expression: `.[] |= map(3 + .)`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (!!seq)::[[], [8]]\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
skipDoc: true,
|
skipDoc: true,
|
||||||
expression: `[] | map(. + 42)`,
|
expression: `[] | map(. + 42)`,
|
||||||
@ -39,6 +79,26 @@ var mapOperatorScenarios = []expressionScenario{
|
|||||||
"D0, P[], (!!seq)::[2, 3, 4]\n",
|
"D0, P[], (!!seq)::[2, 3, 4]\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
skipDoc: true,
|
||||||
|
document: `{}`,
|
||||||
|
document2: `{b: 12}`,
|
||||||
|
expression: `map_values(3)`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (!!map)::{}\n",
|
||||||
|
"D0, P[], (!!map)::{b: 3}\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
skipDoc: true,
|
||||||
|
document: `{}`,
|
||||||
|
document2: `{b: 12}`,
|
||||||
|
expression: `map_values(3 + .)`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (!!map)::{}\n",
|
||||||
|
"D0, P[], (!!map)::{b: 15}\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
skipDoc: true,
|
skipDoc: true,
|
||||||
document: `{a: 1, b: 2, c: 3}`,
|
document: `{a: 1, b: 2, c: 3}`,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user