yq/pkg/yqlib/operator_booleans_test.go

56 lines
1.2 KiB
Go
Raw Normal View History

2020-11-03 23:48:43 +00:00
package yqlib
2020-10-17 11:10:47 +00:00
import (
"testing"
)
var booleanOperatorScenarios = []expressionScenario{
{
2020-11-20 03:35:34 +00:00
description: "OR example",
expression: `true or false`,
2020-10-17 11:10:47 +00:00
expected: []string{
"D0, P[], (!!bool)::true\n",
},
2020-11-20 03:35:34 +00:00
},
{
description: "AND example",
expression: `true and false`,
expected: []string{
"D0, P[], (!!bool)::false\n",
},
},
{
document: "[{a: bird, b: dog}, {a: frog, b: bird}, {a: cat, b: fly}]",
description: "Matching nodes with select, equals and or",
2020-11-20 04:33:21 +00:00
expression: `[.[] | select(.a == "cat" or .b == "dog")]`,
2020-11-20 03:35:34 +00:00
expected: []string{
2020-11-20 04:33:21 +00:00
"D0, P[], (!!seq)::- {a: bird, b: dog}\n- {a: cat, b: fly}\n",
2020-11-20 03:35:34 +00:00
},
},
{
skipDoc: true,
2020-10-17 11:10:47 +00:00
expression: `false or false`,
expected: []string{
"D0, P[], (!!bool)::false\n",
},
2020-11-20 03:35:34 +00:00
},
{
skipDoc: true,
2020-10-17 11:10:47 +00:00
document: `{a: true, b: false}`,
expression: `.[] or (false, true)`,
expected: []string{
2020-10-21 01:54:58 +00:00
"D0, P[a], (!!bool)::true\n",
2020-10-17 11:10:47 +00:00
"D0, P[a], (!!bool)::true\n",
"D0, P[b], (!!bool)::false\n",
"D0, P[b], (!!bool)::true\n",
},
},
}
func TestBooleanOperatorScenarios(t *testing.T) {
for _, tt := range booleanOperatorScenarios {
testScenario(t, &tt)
}
2020-11-20 04:31:49 +00:00
documentScenarios(t, "Boolean Operators", booleanOperatorScenarios)
2020-10-17 11:10:47 +00:00
}