yq/pkg/yqlib/treeops/operator_create_map_test.go
2020-10-28 13:00:26 +11:00

52 lines
1.1 KiB
Go

package treeops
import (
"testing"
)
var createMapOperatorScenarios = []expressionScenario{
{
document: `{name: Mike, age: 32}`,
expression: `.name: .age`,
expected: []string{
"D0, P[], (!!seq)::- Mike: 32\n",
},
},
{
document: `{name: Mike, pets: [cat, dog]}`,
expression: `.name: .pets[]`,
expected: []string{
"D0, P[], (!!seq)::- Mike: cat\n- Mike: dog\n",
},
},
{
document: `{name: Mike, pets: [cat, dog], food: [hotdog, burger]}`,
expression: `.name: .pets[], "f":.food[]`,
expected: []string{
"D0, P[], (!!seq)::- Mike: cat\n- Mike: dog\n",
"D0, P[], (!!seq)::- f: hotdog\n- f: burger\n",
},
},
{
document: `{name: Mike, pets: {cows: [apl, bba]}}`,
expression: `"a":.name, "b":.pets`,
expected: []string{
"D0, P[], (!!seq)::- a: Mike\n",
"D0, P[], (!!seq)::- b: {cows: [apl, bba]}\n",
},
},
{
document: `{name: Mike}`,
expression: `"wrap": .`,
expected: []string{
"D0, P[], (!!seq)::- wrap: {name: Mike}\n",
},
},
}
func TestCreateMapOperatorScenarios(t *testing.T) {
for _, tt := range createMapOperatorScenarios {
testScenario(t, &tt)
}
}