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-28 02:00:26 +00:00
|
|
|
{
|
|
|
|
document: `{name: Mike}`,
|
|
|
|
expression: `"wrap": .`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (!!seq)::- wrap: {name: Mike}\n",
|
|
|
|
},
|
|
|
|
},
|
2020-10-21 01:54:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateMapOperatorScenarios(t *testing.T) {
|
|
|
|
for _, tt := range createMapOperatorScenarios {
|
|
|
|
testScenario(t, &tt)
|
|
|
|
}
|
|
|
|
}
|