Skip to content

Commit e414850

Browse files
committed
add in_not_nil operator
1 parent 09fafa0 commit e414850

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

querybuilder/operator/is_not_nil.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package operator
2+
3+
func init() {
4+
AddOperator(IsNotNil)
5+
}
6+
7+
var IsNotNil = &Operator{
8+
Name: "is_not_nil",
9+
Evaluate: func(input, value interface{}) bool {
10+
return !IsNil.Evaluate(input, value)
11+
},
12+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package operator
2+
3+
import "testing"
4+
5+
func TestIsNotNil(t *testing.T) {
6+
var typeNil interface{}
7+
8+
var inputs = []struct {
9+
title string
10+
value interface{}
11+
input interface{}
12+
want bool
13+
}{
14+
{title: "is_not_nil-1", value: nil, input: "", want: true},
15+
{title: "is_not_nil-2", value: nil, input: typeNil, want: false},
16+
{title: "is_not_nil-3", value: nil, input: []int{}, want: true},
17+
{title: "is_not_nil-5", value: nil, input: nil, want: false},
18+
}
19+
20+
for _, input := range inputs {
21+
t.Run(input.title, func(t *testing.T) {
22+
got := IsNotNil.Evaluate(input.input, input.value)
23+
if got != input.want {
24+
t.Errorf("%v is not nil %v got: %t, want: %t", input.input, input.value, got, input.want)
25+
}
26+
})
27+
}
28+
}

0 commit comments

Comments
 (0)