2018-10-16 00:50:55 +02:00
|
|
|
package compiler_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"github.com/MontFerret/ferret/pkg/compiler"
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestInOperator(t *testing.T) {
|
|
|
|
Convey("1 IN [1,2,3] should return true", t, func() {
|
|
|
|
c := compiler.New()
|
|
|
|
|
2018-10-25 01:40:57 +02:00
|
|
|
p, err := c.Compile(`
|
2018-10-16 00:50:55 +02:00
|
|
|
RETURN 1 IN [1,2,3]
|
|
|
|
`)
|
|
|
|
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2018-10-25 01:40:57 +02:00
|
|
|
out, err := p.Run(context.Background())
|
2018-10-16 00:50:55 +02:00
|
|
|
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(string(out), ShouldEqual, `true`)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("4 IN [1,2,3] should return false", t, func() {
|
|
|
|
c := compiler.New()
|
|
|
|
|
2018-10-25 01:40:57 +02:00
|
|
|
p, err := c.Compile(`
|
2018-10-16 00:50:55 +02:00
|
|
|
RETURN 4 IN [1,2,3]
|
|
|
|
`)
|
|
|
|
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2018-10-25 01:40:57 +02:00
|
|
|
out, err := p.Run(context.Background())
|
2018-10-16 00:50:55 +02:00
|
|
|
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(string(out), ShouldEqual, `false`)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("4 NOT IN [1,2,3] should return true", t, func() {
|
|
|
|
c := compiler.New()
|
|
|
|
|
2018-10-25 01:40:57 +02:00
|
|
|
p, err := c.Compile(`
|
2018-10-16 00:50:55 +02:00
|
|
|
RETURN 4 NOT IN [1,2,3]
|
|
|
|
`)
|
|
|
|
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2018-10-25 01:40:57 +02:00
|
|
|
out, err := p.Run(context.Background())
|
2018-10-16 00:50:55 +02:00
|
|
|
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(string(out), ShouldEqual, `true`)
|
|
|
|
})
|
|
|
|
}
|
2018-10-25 01:40:57 +02:00
|
|
|
|
|
|
|
func BenchmarkInOperator(b *testing.B) {
|
|
|
|
p := compiler.New().MustCompile(`
|
|
|
|
RETURN 1 IN [1,2,3]
|
|
|
|
`)
|
|
|
|
|
|
|
|
for n := 0; n < b.N; n++ {
|
|
|
|
p.Run(context.Background())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkInOperatorNot(b *testing.B) {
|
|
|
|
p := compiler.New().MustCompile(`
|
|
|
|
RETURN 4 NOT IN [1,2,3]
|
|
|
|
`)
|
|
|
|
|
|
|
|
for n := 0; n < b.N; n++ {
|
|
|
|
p.Run(context.Background())
|
|
|
|
}
|
|
|
|
}
|