Fixes update-assign with collect object issue #830

This commit is contained in:
Mike Farah 2021-05-22 08:22:45 +10:00
parent af283315f2
commit 48eeb2a9df
3 changed files with 36 additions and 1 deletions

View File

@ -17,9 +17,12 @@ import (
...
*/
func collectObjectOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
func collectObjectOperator(d *dataTreeNavigator, originalContext Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("-- collectObjectOperation")
context := originalContext.Clone()
context.DontAutoCreate = false
if context.MatchingNodes.Len() == 0 {
node := &yaml.Node{Kind: yaml.MappingNode, Tag: "!!map", Value: "{}"}
candidate := &CandidateNode{Node: node}

View File

@ -5,6 +5,30 @@ import (
)
var collectObjectOperatorScenarios = []expressionScenario{
{
skipDoc: true,
document: "a: []",
expression: `.a += [{"key": "att2", "value": "val2"}]`,
expected: []string{
"D0, P[], (doc)::a: [{key: att2, value: val2}]\n",
},
},
{
skipDoc: true,
document: "",
expression: `.a += {"key": "att2", "value": "val2"}`,
expected: []string{
"D0, P[], ()::a:\n key: att2\n value: val2\n",
},
},
{
skipDoc: true,
document: "",
expression: `.a += [0]`,
expected: []string{
"D0, P[], ()::a:\n - 0\n",
},
},
{
description: `Collect empty object`,
document: ``,

View File

@ -5,6 +5,14 @@ import (
)
var collectOperatorScenarios = []expressionScenario{
{
skipDoc: true,
document: ``,
expression: `.a += [0]`,
expected: []string{
"D0, P[], ()::a:\n - 0\n",
},
},
{
description: "Collect empty",
document: ``,