mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Fixes update-assign with collect object issue #830
This commit is contained in:
parent
af283315f2
commit
48eeb2a9df
@ -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")
|
log.Debugf("-- collectObjectOperation")
|
||||||
|
|
||||||
|
context := originalContext.Clone()
|
||||||
|
context.DontAutoCreate = false
|
||||||
|
|
||||||
if context.MatchingNodes.Len() == 0 {
|
if context.MatchingNodes.Len() == 0 {
|
||||||
node := &yaml.Node{Kind: yaml.MappingNode, Tag: "!!map", Value: "{}"}
|
node := &yaml.Node{Kind: yaml.MappingNode, Tag: "!!map", Value: "{}"}
|
||||||
candidate := &CandidateNode{Node: node}
|
candidate := &CandidateNode{Node: node}
|
||||||
|
@ -5,6 +5,30 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var collectObjectOperatorScenarios = []expressionScenario{
|
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`,
|
description: `Collect empty object`,
|
||||||
document: ``,
|
document: ``,
|
||||||
|
@ -5,6 +5,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var collectOperatorScenarios = []expressionScenario{
|
var collectOperatorScenarios = []expressionScenario{
|
||||||
|
{
|
||||||
|
skipDoc: true,
|
||||||
|
document: ``,
|
||||||
|
expression: `.a += [0]`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], ()::a:\n - 0\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "Collect empty",
|
description: "Collect empty",
|
||||||
document: ``,
|
document: ``,
|
||||||
|
Loading…
Reference in New Issue
Block a user