Skip to content

Commit dc8aa27

Browse files
committed
add not_in operator
1 parent 0f89952 commit dc8aa27

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

querybuilder/operator/not_in.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(NotIn)
5+
}
6+
7+
var NotIn = &Operator{
8+
Name: "not_in",
9+
Evaluate: func(input, value interface{}) bool {
10+
return !In.Evaluate(input, value)
11+
},
12+
}

querybuilder/operator/not_in_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package operator
2+
3+
import "testing"
4+
5+
func TestNotIn(t *testing.T) {
6+
var inputs = []struct {
7+
title string
8+
value interface{}
9+
input interface{}
10+
want bool
11+
}{
12+
{title: "in-1", value: 2, input: []int{1, 2, 3}, want: false},
13+
{title: "in-2", value: 2.5, input: []float64{2.0, 2.3, 2.5, 3}, want: false},
14+
{title: "in-3", value: "c", input: []string{"a", "b", "c"}, want: false},
15+
{title: "in-4", value: "d", input: []string{"a", "b", "c"}, want: true},
16+
{title: "in-5", value: "word to", input: "my word to match", want: true},
17+
}
18+
19+
for _, input := range inputs {
20+
t.Run(input.title, func(t *testing.T) {
21+
got := NotIn.Evaluate(input.input, input.value)
22+
if got != input.want {
23+
t.Errorf("%v not in %v got: %t, want: %t", input.input, input.value, got, input.want)
24+
}
25+
})
26+
}
27+
}

0 commit comments

Comments
 (0)