2021-01-14 03:25:31 +00:00
|
|
|
package yqlib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
var splitDocOperatorScenarios = []expressionScenario{
|
|
|
|
{
|
|
|
|
description: "Split empty",
|
|
|
|
document: ``,
|
2022-02-10 22:05:17 +00:00
|
|
|
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}]`,
|
2022-02-10 22:05:17 +00:00
|
|
|
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",
|
|
|
|
},
|
|
|
|
},
|
2024-06-16 00:48:01 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|