yq/pkg/yqlib/treeops/operator_multiply_test.go
2020-10-30 12:40:44 +11:00

112 lines
2.5 KiB
Go

package treeops
import (
"testing"
)
var multiplyOperatorScenarios = []expressionScenario{
{
document: `{a: {also: [1]}, b: {also: me}}`,
expression: `. * {"a" : .b}`,
expected: []string{
"D0, P[], (!!map)::{a: {also: me}, b: {also: me}}\n",
},
},
{
document: `{a: {also: me}, b: {also: [1]}}`,
expression: `. * {"a":.b}`,
expected: []string{
"D0, P[], (!!map)::{a: {also: [1]}, b: {also: [1]}}\n",
},
},
{
document: `{a: {also: me}, b: {also: {g: wizz}}}`,
expression: `. * {"a":.b}`,
expected: []string{
"D0, P[], (!!map)::{a: {also: {g: wizz}}, b: {also: {g: wizz}}}\n",
},
},
{
document: `{a: {also: {g: wizz}}, b: {also: me}}`,
expression: `. * {"a":.b}`,
expected: []string{
"D0, P[], (!!map)::{a: {also: me}, b: {also: me}}\n",
},
},
{
document: `{a: {also: {g: wizz}}, b: {also: [1]}}`,
expression: `. * {"a":.b}`,
expected: []string{
"D0, P[], (!!map)::{a: {also: [1]}, b: {also: [1]}}\n",
},
},
{
document: `{a: {also: [1]}, b: {also: {g: wizz}}}`,
expression: `. * {"a":.b}`,
expected: []string{
"D0, P[], (!!map)::{a: {also: {g: wizz}}, b: {also: {g: wizz}}}\n",
},
},
{
document: `{a: {things: great}, b: {also: me}}`,
expression: `. * {"a":.b}`,
expected: []string{
"D0, P[], (!!map)::{a: {things: great, also: me}, b: {also: me}}\n",
},
},
{
document: `a: {things: great}
b:
also: "me"
`,
expression: `. * {"a":.b}`,
expected: []string{
`D0, P[], (!!map)::a: {things: great, also: "me"}
b:
also: "me"
`,
},
},
{
document: `{a: [1,2,3], b: [3,4,5]}`,
expression: `. * {"a":.b}`,
expected: []string{
"D0, P[], (!!map)::{a: [3, 4, 5], b: [3, 4, 5]}\n",
},
},
{
document: `{a: cat}`,
expression: `. * {"a": {"c": .a}}`,
expected: []string{
"D0, P[], (!!map)::{a: {c: cat}}\n",
},
},
{
document: `{a: &cat {c: frog}, b: {f: *cat}, c: {g: thongs}}`,
expression: `.c * .b`,
expected: []string{
"D0, P[c], (!!map)::{g: thongs, f: *cat}\n",
},
},
{
document: `{a: {c: &cat frog}, b: {f: *cat}, c: {g: thongs}}`,
expression: `.c * .a`,
expected: []string{
"D0, P[c], (!!map)::{g: thongs, c: frog}\n",
},
},
{
document: mergeDocSample,
expression: `.foobar * .foobarList`,
expected: []string{
"D0, P[foobar], (!!map)::c: foobarList_c\n<<: [*foo, *bar]\nthing: foobar_thing\nb: foobarList_b\n",
},
},
}
func TestMultiplyOperatorScenarios(t *testing.T) {
for _, tt := range multiplyOperatorScenarios {
testScenario(t, &tt)
}
}