yq/pkg/yqlib/operator_collect_test.go

96 lines
1.7 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 collectOperatorScenarios = []expressionScenario{
{
skipDoc: true,
document: ``,
expression: `.a += [0]`,
expected: []string{
"D0, P[], ()::a:\n - 0\n",
},
},
2020-10-17 11:10:47 +00:00
{
2020-11-13 10:22:05 +00:00
description: "Collect empty",
document: ``,
expression: `[]`,
2020-11-22 02:50:32 +00:00
expected: []string{
"D0, P[], (!!seq)::[]\n",
},
2020-11-13 02:19:54 +00:00
},
2021-01-11 03:44:53 +00:00
{
2021-01-11 04:43:50 +00:00
skipDoc: true,
document: "{a: apple}\n---\n{b: frog}",
expression: `[.]`,
2021-01-11 03:44:53 +00:00
expected: []string{
"D0, P[], (!!seq)::- {a: apple}\n- {b: frog}\n",
},
},
{
skipDoc: true,
document: ``,
expression: `[3]`,
expected: []string{
"D0, P[], (!!seq)::- 3\n",
},
},
2020-11-13 02:19:54 +00:00
{
2020-11-13 10:22:05 +00:00
description: "Collect single",
document: ``,
expression: `["cat"]`,
2020-10-17 11:10:47 +00:00
expected: []string{
"D0, P[], (!!seq)::- cat\n",
},
2020-10-19 09:05:38 +00:00
}, {
2020-11-13 02:19:54 +00:00
document: ``,
2020-11-13 10:22:05 +00:00
skipDoc: true,
2020-10-19 09:05:38 +00:00
expression: `[true]`,
expected: []string{
"D0, P[], (!!seq)::- true\n",
},
2020-11-13 10:22:05 +00:00
},
{
description: "Collect many",
document: `{a: cat, b: dog}`,
expression: `[.a, .b]`,
2020-10-17 11:10:47 +00:00
expected: []string{
"D0, P[], (!!seq)::- cat\n- dog\n",
},
2020-11-13 10:22:05 +00:00
},
{
2020-11-13 02:19:54 +00:00
document: ``,
2020-11-13 10:22:05 +00:00
skipDoc: true,
2020-10-17 11:10:47 +00:00
expression: `1 | collect`,
expected: []string{
"D0, P[], (!!seq)::- 1\n",
},
2020-11-13 10:22:05 +00:00
},
{
2020-10-17 11:10:47 +00:00
document: `[1,2,3]`,
2020-11-13 10:22:05 +00:00
skipDoc: true,
2020-10-17 11:10:47 +00:00
expression: `[.[]]`,
expected: []string{
"D0, P[], (!!seq)::- 1\n- 2\n- 3\n",
},
2020-11-13 10:22:05 +00:00
},
{
2020-10-17 11:10:47 +00:00
document: `a: {b: [1,2,3]}`,
2020-11-22 02:50:32 +00:00
expression: `[.a.b.[]]`,
2020-11-13 10:22:05 +00:00
skipDoc: true,
2020-10-17 11:10:47 +00:00
expected: []string{
"D0, P[a b], (!!seq)::- 1\n- 2\n- 3\n",
},
},
}
func TestCollectOperatorScenarios(t *testing.T) {
for _, tt := range collectOperatorScenarios {
testScenario(t, &tt)
}
2021-11-03 04:00:58 +00:00
documentScenarios(t, "collect-into-array", collectOperatorScenarios)
2020-10-17 11:10:47 +00:00
}