yq/pkg/yqlib/treeops/operator_create_map_test.go

45 lines
998 B
Go
Raw Normal View History

2020-10-21 01:54:58 +00:00
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",
},
},
2020-10-21 02:54:51 +00:00
{
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",
},
},
2020-10-28 00:34:01 +00:00
{
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",
},
},
2020-10-21 01:54:58 +00:00
}
func TestCreateMapOperatorScenarios(t *testing.T) {
for _, tt := range createMapOperatorScenarios {
testScenario(t, &tt)
}
}