added match logic and query error checking
This commit is contained in:
parent
e309b478f5
commit
5a8e1e6cf6
4 changed files with 315 additions and 70 deletions
156
filter_test.go
156
filter_test.go
|
|
@ -54,9 +54,25 @@ var (
|
|||
}
|
||||
)
|
||||
|
||||
func TestNewQuery(t *testing.T) {
|
||||
_, err := NewQuery("String:1 String:2", AND)
|
||||
if err == nil {
|
||||
t.Error("multiple AND fields")
|
||||
}
|
||||
|
||||
_, err = NewQuery("String:1 sdcs Int:1", AND)
|
||||
if err == nil {
|
||||
t.Error("invalid match")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilter(t *testing.T) {
|
||||
f1 := makefilter(data)
|
||||
NewQuery("String:*st* Bool:true").Filter(&f1)
|
||||
q1, err := NewQuery("String:*st* Bool:true", AND)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
q1.Filter(&f1)
|
||||
if len(f1) != 2 {
|
||||
t.Error("f1 len is:", len(f1))
|
||||
}
|
||||
|
|
@ -66,22 +82,47 @@ func TestFilter(t *testing.T) {
|
|||
if f1[1] != data[1] {
|
||||
t.Error("f1[1] != data[1]")
|
||||
}
|
||||
|
||||
f2 := makefilter(data)
|
||||
NewQuery("Struct.Struct.Int:3").Filter(&f2)
|
||||
if len(f2) != 1 {
|
||||
q2, err := NewQuery("Struct.Struct.Int:2 Struct.Struct.Int:3", OR)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
q2.Filter(&f2)
|
||||
if len(f2) != 2 {
|
||||
t.Error("f2 len is:", len(f2))
|
||||
}
|
||||
if f2[0] != data[2] {
|
||||
t.Error("f1[0] != data[2]")
|
||||
if f2[0] != data[1] {
|
||||
t.Error("f2[0] != data[1]")
|
||||
}
|
||||
if f2[1] != data[2] {
|
||||
t.Error("f2[1] != data[2]")
|
||||
}
|
||||
|
||||
f3 := makefilter(data)
|
||||
q3, err := NewQuery("Struct.Struct.Int:2 Struct.Struct.Int:3", NOT)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
q3.Filter(&f3)
|
||||
if len(f3) != 1 {
|
||||
t.Error("f3 len is:", len(f3))
|
||||
}
|
||||
if f3[0] != data[0] {
|
||||
t.Error("f3[0] != data[0]")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenericFilter(t *testing.T) {
|
||||
i1 := NewQuery("String:*st* Bool:true").GenericFilter(data)
|
||||
if i1 == nil {
|
||||
t.Error("i1 is nil")
|
||||
q1, err := NewQuery("String:*st* Bool:true", AND)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
f1 := i1.(filter)
|
||||
a1 := q1.GenericFilter(data)
|
||||
if a1 == nil {
|
||||
t.Error("a1 is nil")
|
||||
}
|
||||
f1 := a1.(filter)
|
||||
if len(f1) != 2 {
|
||||
t.Error("f1 len is:", len(f1))
|
||||
}
|
||||
|
|
@ -91,22 +132,73 @@ func TestGenericFilter(t *testing.T) {
|
|||
if f1[1] != data[1] {
|
||||
t.Error("f1[1] != data[1]")
|
||||
}
|
||||
i2 := NewQuery("Struct.Struct.Int:3").GenericFilter(data)
|
||||
if i2 == nil {
|
||||
t.Error("i2 is nil")
|
||||
|
||||
q2, err := NewQuery("Struct.Struct.Int:2 Struct.Struct.Int:3", OR)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
f2 := i2.(filter)
|
||||
if len(f2) != 1 {
|
||||
a2 := q2.GenericFilter(data)
|
||||
if a2 == nil {
|
||||
t.Error("a2 is nil")
|
||||
}
|
||||
f2 := a2.(filter)
|
||||
if len(f2) != 2 {
|
||||
t.Error("f2 len is:", len(f2))
|
||||
}
|
||||
if f2[0] != data[2] {
|
||||
t.Error("f1[0] != data[2]")
|
||||
if f2[0] != data[1] {
|
||||
t.Error("f2[0] != data[1]")
|
||||
}
|
||||
if f2[1] != data[2] {
|
||||
t.Error("f2[1] != data[2]")
|
||||
}
|
||||
|
||||
q3, err := NewQuery("Struct.Struct.Int:2 Struct.Struct.Int:3", NOT)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
a3 := q3.GenericFilter(data)
|
||||
if a3 == nil {
|
||||
t.Error("a3 is nil")
|
||||
}
|
||||
f3 := a3.(filter)
|
||||
if len(f3) != 1 {
|
||||
t.Error("f3 len is:", len(f3))
|
||||
}
|
||||
if f3[0] != data[0] {
|
||||
t.Error("f3[0] != data[0]")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkFilterSimple(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
q := NewQuery("Bool:true")
|
||||
q, err := NewQuery("Bool:true", OR)
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
fd := makefilter(benchData)
|
||||
for i := 0; i < b.N; i++ {
|
||||
q.Filter(&fd)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkFilterComplex(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
q, err := NewQuery("String:*st* Bool:false Struct.Struct.Int:1", AND)
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
fd := makefilter(benchData)
|
||||
for i := 0; i < b.N; i++ {
|
||||
q.Filter(&fd)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkFilterComplexOr(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
q, err := NewQuery("Int:47 Bool:false Struct.String:s1*", OR)
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
fd := makefilter(benchData)
|
||||
for i := 0; i < b.N; i++ {
|
||||
q.Filter(&fd)
|
||||
|
|
@ -115,24 +207,32 @@ func BenchmarkFilterSimple(b *testing.B) {
|
|||
|
||||
func BenchmarkGenericFilterSimple(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
q := NewQuery("Bool:true")
|
||||
q, err := NewQuery("Bool:true", OR)
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
for i := 0; i < b.N; i++ {
|
||||
q.GenericFilter(benchData)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkFilterComplex(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
q := NewQuery("String:*st* Bool:false Struct.Struct.Int:1")
|
||||
fd := makefilter(benchData)
|
||||
for i := 0; i < b.N; i++ {
|
||||
q.Filter(&fd)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkGenericFilterComplex(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
q := NewQuery("String:*st* Bool:false Struct.Struct.Int:1")
|
||||
q, err := NewQuery("String:*st* Bool:false Struct.Struct.Int:1", AND)
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
for i := 0; i < b.N; i++ {
|
||||
q.GenericFilter(benchData)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkGenericFilterComplexOr(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
q, err := NewQuery("Int:47 Bool:false Struct.String:s1*", OR)
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
for i := 0; i < b.N; i++ {
|
||||
q.GenericFilter(benchData)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue