yq/pkg/yqlib/operator_split_document_test.go

43 lines
877 B
Go
Raw Normal View History

2021-01-14 03:25:31 +00:00
package yqlib
import (
"testing"
)
var splitDocOperatorScenarios = []expressionScenario{
{
description: "Split empty",
document: ``,
expression: `split_doc`,
2021-01-14 03:25:31 +00:00
expected: []string{
"D0, P[], (!!null)::\n",
},
},
{
description: "Split array",
document: `[{a: cat}, {b: dog}]`,
expression: `.[] | split_doc`,
2021-01-14 03:25:31 +00:00
expected: []string{
"D0, P[0], (!!map)::{a: cat}\n",
"D1, P[1], (!!map)::{b: dog}\n",
},
},
{
description: "Split splat",
skipDoc: true,
document: `[{a: cat}, {b: dog}]`,
expression: `.[] | split_doc[]`,
expected: []string{
"D0, P[0 a], (!!str)::cat\n",
"D1, P[1 b], (!!str)::dog\n",
},
},
2021-01-14 03:25:31 +00:00
}
func TestSplitDocOperatorScenarios(t *testing.T) {
for _, tt := range splitDocOperatorScenarios {
testScenario(t, &tt)
}
2021-12-21 04:02:07 +00:00
documentOperatorScenarios(t, "split-into-documents", splitDocOperatorScenarios)
2021-01-14 03:25:31 +00:00
}