2020-11-03 23:48:43 +00:00
|
|
|
package yqlib
|
2020-10-17 11:10:47 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
var selectOperatorScenarios = []expressionScenario{
|
|
|
|
{
|
|
|
|
document: `[cat,goat,dog]`,
|
|
|
|
expression: `.[] | select(. == "*at")`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[0], (!!str)::cat\n",
|
|
|
|
"D0, P[1], (!!str)::goat\n",
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
document: `[hot, fot, dog]`,
|
|
|
|
expression: `.[] | select(. == "*at")`,
|
|
|
|
expected: []string{},
|
|
|
|
}, {
|
|
|
|
document: `a: [cat,goat,dog]`,
|
|
|
|
expression: `.a[] | select(. == "*at")`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[a 0], (!!str)::cat\n",
|
|
|
|
"D0, P[a 1], (!!str)::goat\n"},
|
|
|
|
}, {
|
|
|
|
document: `a: { things: cat, bob: goat, horse: dog }`,
|
|
|
|
expression: `.a[] | select(. == "*at")`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[a things], (!!str)::cat\n",
|
|
|
|
"D0, P[a bob], (!!str)::goat\n"},
|
|
|
|
}, {
|
|
|
|
document: `a: { things: {include: true}, notMe: {include: false}, andMe: {include: fold} }`,
|
|
|
|
expression: `.a[] | select(.include)`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[a things], (!!map)::{include: true}\n",
|
|
|
|
"D0, P[a andMe], (!!map)::{include: fold}\n",
|
|
|
|
},
|
2020-10-20 04:40:11 +00:00
|
|
|
}, {
|
|
|
|
document: `[cat,~,dog]`,
|
|
|
|
expression: `.[] | select(. == ~)`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[1], (!!null)::~\n",
|
|
|
|
},
|
2020-10-17 11:10:47 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSelectOperatorScenarios(t *testing.T) {
|
|
|
|
for _, tt := range selectOperatorScenarios {
|
|
|
|
testScenario(t, &tt)
|
|
|
|
}
|
|
|
|
}
|