yq/pkg/yqlib/operator_with_test.go

38 lines
1.1 KiB
Go
Raw Normal View History

2021-09-12 11:52:02 +00:00
package yqlib
import "testing"
var withOperatorScenarios = []expressionScenario{
{
description: "Update and style",
document: `a: {deeply: {nested: value}}`,
2021-09-15 12:24:03 +00:00
expression: `with(.a.deeply.nested; . = "newValue" | . style="single")`,
2021-09-12 11:52:02 +00:00
expected: []string{
"D0, P[], (doc)::a: {deeply: {nested: 'newValue'}}\n",
},
},
2021-09-15 05:18:10 +00:00
{
description: "Update multiple deeply nested properties",
document: `a: {deeply: {nested: value, other: thing}}`,
2021-09-15 12:24:03 +00:00
expression: `with(.a.deeply; .nested = "newValue" | .other= "newThing")`,
2021-09-15 05:18:10 +00:00
expected: []string{
"D0, P[], (doc)::a: {deeply: {nested: newValue, other: newThing}}\n",
},
},
{
description: "Update array elements relatively",
document: `myArray: [{a: apple},{a: banana}]`,
2021-09-15 12:24:03 +00:00
expression: `with(.myArray[]; .b = .a + " yum")`,
2021-09-15 05:18:10 +00:00
expected: []string{
"D0, P[], (doc)::myArray: [{a: apple, b: apple yum}, {a: banana, b: banana yum}]\n",
},
},
2021-09-12 11:52:02 +00:00
}
func TestWithOperatorScenarios(t *testing.T) {
for _, tt := range withOperatorScenarios {
testScenario(t, &tt)
}
documentScenarios(t, "With", withOperatorScenarios)
}