yq/pkg/yqlib/operator_union_test.go

57 lines
1.1 KiB
Go
Raw Normal View History

2020-11-03 23:48:43 +00:00
package yqlib
2020-10-17 11:10:47 +00:00
import (
"testing"
)
var unionOperatorScenarios = []expressionScenario{
2021-09-05 01:07:40 +00:00
{
skipDoc: true,
document: "{}",
expression: `(.a, .b.c) as $x | .`,
2021-09-05 01:07:40 +00:00
expected: []string{
2023-06-05 22:27:59 +00:00
"D0, P[], (!!map)::{}\n",
2021-09-05 01:07:40 +00:00
},
},
2022-01-14 03:55:25 +00:00
{
skipDoc: true,
description: "clone test",
expression: `"abc" as $a | [$a, "cat"]`,
expected: []string{
"D0, P[], (!!seq)::- abc\n- cat\n",
},
},
2021-09-05 01:07:40 +00:00
{
skipDoc: true,
expression: `(.foo = "bar"), (.toe = "jam")`,
expected: []string{
"D0, P[], ()::foo: bar\ntoe: jam\n",
},
},
2020-10-17 11:10:47 +00:00
{
2020-11-17 23:32:30 +00:00
description: "Combine scalars",
expression: `1, true, "cat"`,
2020-10-17 11:10:47 +00:00
expected: []string{
"D0, P[], (!!int)::1\n",
"D0, P[], (!!bool)::true\n",
"D0, P[], (!!str)::cat\n",
2020-11-17 23:32:30 +00:00
},
},
{
description: "Combine selected paths",
document: `{a: fieldA, b: fieldB, c: fieldC}`,
expression: `.a, .c`,
expected: []string{
"D0, P[a], (!!str)::fieldA\n",
"D0, P[c], (!!str)::fieldC\n",
2020-10-17 11:10:47 +00:00
},
},
}
func TestUnionOperatorScenarios(t *testing.T) {
for _, tt := range unionOperatorScenarios {
testScenario(t, &tt)
}
2021-12-21 04:02:07 +00:00
documentOperatorScenarios(t, "union", unionOperatorScenarios)
2020-10-17 11:10:47 +00:00
}