2020-11-03 23:48:43 +00:00
|
|
|
package yqlib
|
2020-10-17 11:10:47 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
var equalsOperatorScenarios = []expressionScenario{
|
2020-10-21 01:54:58 +00:00
|
|
|
{
|
|
|
|
document: `[cat,goat,dog]`,
|
|
|
|
expression: `.[] | (. == "*at")`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[0], (!!bool)::true\n",
|
|
|
|
"D0, P[1], (!!bool)::true\n",
|
|
|
|
"D0, P[2], (!!bool)::false\n",
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
document: `[3, 4, 5]`,
|
|
|
|
expression: `.[] | (. == 4)`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[0], (!!bool)::false\n",
|
|
|
|
"D0, P[1], (!!bool)::true\n",
|
|
|
|
"D0, P[2], (!!bool)::false\n",
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
document: `a: { cat: {b: apple, c: whatever}, pat: {b: banana} }`,
|
|
|
|
expression: `.a | (.[].b == "apple")`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[a cat b], (!!bool)::true\n",
|
|
|
|
"D0, P[a pat b], (!!bool)::false\n",
|
|
|
|
},
|
|
|
|
},
|
2020-10-17 11:10:47 +00:00
|
|
|
{
|
2020-10-20 05:27:30 +00:00
|
|
|
document: ``,
|
|
|
|
expression: `null == null`,
|
2020-10-17 11:10:47 +00:00
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (!!bool)::true\n",
|
|
|
|
},
|
|
|
|
},
|
2020-10-21 01:54:58 +00:00
|
|
|
{
|
|
|
|
document: ``,
|
|
|
|
expression: `null == ~`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (!!bool)::true\n",
|
|
|
|
},
|
|
|
|
},
|
2020-10-17 11:10:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEqualOperatorScenarios(t *testing.T) {
|
|
|
|
for _, tt := range equalsOperatorScenarios {
|
|
|
|
testScenario(t, &tt)
|
|
|
|
}
|
2020-11-06 00:23:26 +00:00
|
|
|
documentScenarios(t, "Equals Operator", equalsOperatorScenarios)
|
2020-10-17 11:10:47 +00:00
|
|
|
}
|