yq/pkg/yqlib/operator_not_test.go

66 lines
1.2 KiB
Go
Raw Normal View History

2020-11-03 23:48:43 +00:00
package yqlib
2020-10-20 05:27:30 +00:00
import (
"testing"
)
var notOperatorScenarios = []expressionScenario{
{
2020-11-14 23:50:30 +00:00
description: "Not true is false",
expression: `true | not`,
expected: []string{
"D0, P[], (!!bool)::false\n",
},
},
{
description: "Not false is true",
expression: `false | not`,
expected: []string{
"D0, P[], (!!bool)::true\n",
},
},
{
description: "String values considered to be true",
expression: `"cat" | not`,
expected: []string{
"D0, P[], (!!bool)::false\n",
},
},
{
description: "Empty string value considered to be true",
expression: `"" | not`,
expected: []string{
"D0, P[], (!!bool)::false\n",
},
},
{
description: "Numbers are considered to be true",
expression: `1 | not`,
expected: []string{
"D0, P[], (!!bool)::false\n",
},
},
{
description: "Zero is considered to be true",
expression: `0 | not`,
expected: []string{
"D0, P[], (!!bool)::false\n",
},
},
{
description: "Null is considered to be false",
expression: `~ | not`,
2020-10-20 05:27:30 +00:00
expected: []string{
"D0, P[], (!!bool)::true\n",
},
},
}
func TestNotOperatorScenarios(t *testing.T) {
for _, tt := range notOperatorScenarios {
testScenario(t, &tt)
}
2020-11-14 23:50:30 +00:00
documentScenarios(t, "Not Operator", notOperatorScenarios)
2020-10-20 05:27:30 +00:00
}