yq/pkg/yqlib/operator_collect_test.go

58 lines
1.0 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{
{
2020-11-13 02:19:54 +00:00
document: ``,
expression: `[]`,
expected: []string{},
},
{
document: ``,
2020-10-17 11:10:47 +00:00
expression: `["cat"]`,
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-10-19 09:05:38 +00:00
expression: `[true]`,
expected: []string{
"D0, P[], (!!seq)::- true\n",
},
2020-10-17 11:10:47 +00:00
}, {
2020-11-13 02:19:54 +00:00
document: ``,
2020-10-17 11:10:47 +00:00
expression: `["cat", "dog"]`,
expected: []string{
"D0, P[], (!!seq)::- cat\n- dog\n",
},
}, {
2020-11-13 02:19:54 +00:00
document: ``,
2020-10-17 11:10:47 +00:00
expression: `1 | collect`,
expected: []string{
"D0, P[], (!!seq)::- 1\n",
},
}, {
document: `[1,2,3]`,
expression: `[.[]]`,
expected: []string{
"D0, P[], (!!seq)::- 1\n- 2\n- 3\n",
},
}, {
document: `a: {b: [1,2,3]}`,
expression: `[.a.b[]]`,
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)
}
2020-11-13 02:19:54 +00:00
documentScenarios(t, "Collect into Array", collectOperatorScenarios)
2020-10-17 11:10:47 +00:00
}