1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-03-21 21:47:43 +02:00
ferret/pkg/compiler/compiler_like_test.go
Tim Voronov 742bdae0ae
Feature/#263 waitfor event (#590)
* Added new WAITFOR syntax

* Added support of event options

* Added support of options

* Added support of using WAITFOR EVENT in variable assignment
2021-07-13 21:34:22 -04:00

116 lines
2.4 KiB
Go

package compiler_test
import (
"context"
"github.com/MontFerret/ferret/pkg/compiler"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestLikeOperator(t *testing.T) {
Convey("RETURN \"foo\" LIKE \"f*\" ", t, func() {
c := compiler.New()
out1, err := c.MustCompile(`
RETURN "foo" LIKE "f*"
`).Run(context.Background())
So(err, ShouldBeNil)
So(string(out1), ShouldEqual, `true`)
})
Convey("RETURN LIKE('foo', 'f*')", t, func() {
c := compiler.New()
out1, err := c.MustCompile(`
RETURN LIKE('foo', 'f*')
`).Run(context.Background())
So(err, ShouldBeNil)
So(string(out1), ShouldEqual, `true`)
})
Convey("RETURN \"foo\" NOT LIKE \"b*\" ", t, func() {
c := compiler.New()
out1, err := c.MustCompile(`
RETURN "foo" NOT LIKE "b*"
`).Run(context.Background())
So(err, ShouldBeNil)
So(string(out1), ShouldEqual, `true`)
})
Convey("LET t = \"foo\" LIKE \"f*\" ", t, func() {
c := compiler.New()
out1, err := c.MustCompile(`
LET res = "foo" LIKE "f*"
RETURN res
`).Run(context.Background())
So(err, ShouldBeNil)
So(string(out1), ShouldEqual, `true`)
})
Convey("FOR IN LIKE", t, func() {
c := compiler.New()
out1, err := c.MustCompile(`
FOR str IN ["foo", "bar", "qaz"]
FILTER str LIKE "*a*"
RETURN str
`).Run(context.Background())
So(err, ShouldBeNil)
So(string(out1), ShouldEqual, `["bar","qaz"]`)
})
Convey("FOR IN LIKE 2", t, func() {
c := compiler.New()
out1, err := c.MustCompile(`
FOR str IN ["foo", "bar", "qaz"]
FILTER str LIKE "*a*"
RETURN str
`).Run(context.Background())
So(err, ShouldBeNil)
So(string(out1), ShouldEqual, `["bar","qaz"]`)
})
Convey("LIKE ternary", t, func() {
c := compiler.New()
out1, err := c.MustCompile(`
RETURN ("foo" NOT LIKE "b*") ? "foo" : "bar"
`).Run(context.Background())
So(err, ShouldBeNil)
So(string(out1), ShouldEqual, `"foo"`)
})
Convey("LIKE ternary 2", t, func() {
c := compiler.New()
out1, err := c.MustCompile(`
RETURN true ? ("foo" NOT LIKE "b*") : false
`).Run(context.Background())
So(err, ShouldBeNil)
So(string(out1), ShouldEqual, `true`)
})
Convey("LIKE ternary 3", t, func() {
c := compiler.New()
out1, err := c.MustCompile(`
RETURN true ? false : ("foo" NOT LIKE "b*")
`).Run(context.Background())
So(err, ShouldBeNil)
So(string(out1), ShouldEqual, `false`)
})
}