1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-14 11:23:02 +02:00
ferret/pkg/compiler/compiler_array_test.go

332 lines
6.3 KiB
Go
Raw Normal View History

package compiler_test
import (
"context"
"github.com/MontFerret/ferret/pkg/compiler"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestArrayOperator(t *testing.T) {
Convey("ALL", t, func() {
Convey("[1,2,3] ALL IN [1,2,3] should return true", func() {
c := compiler.New()
prog, err := c.Compile(`
RETURN [1,2,3] ALL IN [1,2,3]
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `true`)
})
Convey("[1,2,4] ALL IN [1,2,3] should return false", func() {
c := compiler.New()
prog, err := c.Compile(`
RETURN [1,2,4] ALL IN [1,2,3]
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `false`)
})
Convey("[4,5,6] ALL NOT IN [1,2,3] should return true", func() {
c := compiler.New()
prog, err := c.Compile(`
RETURN [4,5,6] ALL NOT IN [1,2,3]
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `true`)
})
Convey("[1,2,3] ALL > 0 should return true", func() {
c := compiler.New()
prog, err := c.Compile(`
RETURN [1,2,3] ALL > 0
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `true`)
})
Convey("[1,2,3] ALL > 2 should return false", func() {
c := compiler.New()
prog, err := c.Compile(`
RETURN [1,2,3] ALL > 2
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `false`)
})
Convey("[1,2,3] ALL >= 3 should return false", func() {
c := compiler.New()
prog, err := c.Compile(`
RETURN [1,2,3] ALL >= 3
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `false`)
})
Convey("['foo','bar'] ALL != 'moo' should return true", func() {
c := compiler.New()
prog, err := c.Compile(`
RETURN ['foo', 'bar'] ALL != 'moo'
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `true`)
})
})
Convey("ANY", t, func() {
Convey("[1,2,3] ANY IN [1,2,3] should return true", func() {
c := compiler.New()
prog, err := c.Compile(`
RETURN [1,2,3] ANY IN [1,2,3]
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `true`)
})
Convey("[4,2,5] ANY IN [1,2,3] should return true", func() {
c := compiler.New()
prog, err := c.Compile(`
RETURN [4,2,5] ANY IN [1,2,3]
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `true`)
})
Convey("[4,5,6] ANY IN [1,2,3] should return false", func() {
c := compiler.New()
prog, err := c.Compile(`
RETURN [4,5,6] ANY IN [1,2,3]
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `false`)
})
Convey("[4,5,6] ANY NOT IN [1,2,3] should return true", func() {
c := compiler.New()
prog, err := c.Compile(`
RETURN [4,5,6] ANY NOT IN [1,2,3]
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `true`)
})
Convey("[1,2,3 ] ANY == 2 should return true", func() {
c := compiler.New()
prog, err := c.Compile(`
RETURN [1,2,3 ] ANY == 2
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `true`)
})
Convey("[1,2,3 ] ANY == 4 should return false", func() {
c := compiler.New()
prog, err := c.Compile(`
RETURN [1,2,3 ] ANY == 4
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `false`)
})
Convey("['foo','bar'] ANY == 'foo' should return true", func() {
c := compiler.New()
prog, err := c.Compile(`
RETURN ['foo', 'bar'] ANY == 'foo'
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `true`)
})
})
Convey("NONE", t, func() {
Convey("[1,2,3] NONE IN [1,2,3] should return false", func() {
c := compiler.New()
prog, err := c.Compile(`
RETURN [1,2,3] NONE IN [1,2,3]
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `false`)
})
Convey("[4,2,5] NONE IN [1,2,3] should return false", func() {
c := compiler.New()
prog, err := c.Compile(`
RETURN [4,2,5] NONE IN [1,2,3]
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `false`)
})
Convey("[4,5,6] NONE IN [1,2,3] should return true", func() {
c := compiler.New()
prog, err := c.Compile(`
RETURN [4,5,6] NONE IN [1,2,3]
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `true`)
})
Convey("[4,5,6] NONE NOT IN [1,2,3] should return false", func() {
c := compiler.New()
prog, err := c.Compile(`
RETURN [4,5,6] NONE NOT IN [1,2,3]
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `false`)
})
Convey("[1,2,3] NONE > 99 should return false", func() {
c := compiler.New()
prog, err := c.Compile(`
RETURN [1,2,3] NONE > 99
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `true`)
})
Convey("[1,2,3] NONE < 99 should return false", func() {
c := compiler.New()
prog, err := c.Compile(`
RETURN [1,2,3] NONE < 99
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `false`)
})
Convey("['foo','bar'] NONE == 'foo' should return false", func() {
c := compiler.New()
prog, err := c.Compile(`
RETURN ['foo','bar'] NONE == 'foo'
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `false`)
})
})
}