yq/pkg/yqlib/operator_create_map_test.go

82 lines
2.1 KiB
Go
Raw Permalink Normal View History

2020-11-03 23:48:43 +00:00
package yqlib
2020-10-21 01:54:58 +00:00
import (
"testing"
)
var createMapOperatorScenarios = []expressionScenario{
2020-11-13 02:19:54 +00:00
{
document: ``,
expression: `"frog": "jumps"`,
expected: []string{
"D0, P[], (!!seq)::- [{frog: jumps}]\n",
},
},
2020-10-21 01:54:58 +00:00
{
document: `{name: Mike, age: 32}`,
expression: `.name: .age`,
expected: []string{
2020-11-13 02:19:54 +00:00
"D0, P[], (!!seq)::- [{Mike: 32}]\n",
2020-10-21 01:54:58 +00:00
},
},
{
document: `{name: Mike, pets: [cat, dog]}`,
2020-11-22 02:50:32 +00:00
expression: `.name: .pets.[]`,
2020-10-21 01:54:58 +00:00
expected: []string{
2020-11-13 02:19:54 +00:00
"D0, P[], (!!seq)::- [{Mike: cat}, {Mike: dog}]\n",
2020-10-21 01:54:58 +00:00
},
},
2020-10-21 02:54:51 +00:00
{
document: `{name: Mike, pets: [cat, dog], food: [hotdog, burger]}`,
2020-11-22 02:50:32 +00:00
expression: `.name: .pets.[], "f":.food.[]`,
2020-10-21 02:54:51 +00:00
expected: []string{
2020-11-13 02:19:54 +00:00
"D0, P[], (!!seq)::- [{Mike: cat}, {Mike: dog}]\n",
"D0, P[], (!!seq)::- [{f: hotdog}, {f: burger}]\n",
},
},
{
document: "{name: Mike, pets: [cat, dog], food: [hotdog, burger]}\n---\n{name: Fred, pets: [mouse], food: [pizza, onion, apple]}",
2020-11-22 02:50:32 +00:00
expression: `.name: .pets.[], "f":.food.[]`,
2020-11-13 02:19:54 +00:00
expected: []string{
"D0, P[], (!!seq)::- [{Mike: cat}, {Mike: dog}]\n- [{Fred: mouse}]\n",
"D0, P[], (!!seq)::- [{f: hotdog}, {f: burger}]\n- [{f: pizza}, {f: onion}, {f: apple}]\n",
2020-10-21 02:54:51 +00:00
},
},
2020-10-28 00:34:01 +00:00
{
document: `{name: Mike, pets: {cows: [apl, bba]}}`,
expression: `"a":.name, "b":.pets`,
expected: []string{
2020-11-13 02:19:54 +00:00
"D0, P[], (!!seq)::- [{a: Mike}]\n",
"D0, P[], (!!seq)::- [{b: {cows: [apl, bba]}}]\n",
2020-10-28 00:34:01 +00:00
},
},
2020-10-28 02:00:26 +00:00
{
document: `{name: Mike}`,
expression: `"wrap": .`,
expected: []string{
2020-11-13 02:19:54 +00:00
"D0, P[], (!!seq)::- [{wrap: {name: Mike}}]\n",
},
},
{
document: "{name: Mike}\n---\n{name: Bob}",
expression: `"wrap": .`,
expected: []string{
"D0, P[], (!!seq)::- [{wrap: {name: Mike}}]\n- [{wrap: {name: Bob}}]\n",
},
},
{
document: "{name: Mike}\n---\n{name: Bob}",
expression: `"wrap": ., .name: "great"`,
expected: []string{
"D0, P[], (!!seq)::- [{wrap: {name: Mike}}]\n- [{wrap: {name: Bob}}]\n",
"D0, P[], (!!seq)::- [{Mike: great}]\n- [{Bob: great}]\n",
2020-10-28 02:00:26 +00:00
},
},
2020-10-21 01:54:58 +00:00
}
func TestCreateMapOperatorScenarios(t *testing.T) {
for _, tt := range createMapOperatorScenarios {
testScenario(t, &tt)
}
}