mirror of
https://github.com/MontFerret/ferret.git
synced 2025-03-25 22:01:15 +02:00
83 lines
1.7 KiB
Go
83 lines
1.7 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"]`)
|
||
|
})
|
||
|
}
|