mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 13:48:06 +00:00
52 lines
1.1 KiB
Go
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)
|
|
}
|
|
}
|