Skip to content

Commit 0f89952

Browse files
committed
add not_contains operator
1 parent 149152d commit 0f89952

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

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

0 commit comments

Comments
 (0)