mirror of
https://github.com/MontFerret/ferret.git
synced 2025-01-26 03:51:57 +02:00
Add like function test
This commit is contained in:
parent
0a3e488af9
commit
c97e12d90f
@ -1 +1,66 @@
|
||||
package strings_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/MontFerret/ferret/pkg/runtime/values"
|
||||
"github.com/MontFerret/ferret/pkg/stdlib/strings"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestLike(t *testing.T) {
|
||||
Convey("When args are not passed", t, func() {
|
||||
Convey("It should return an error", func() {
|
||||
var err error
|
||||
_, err = strings.Like(context.Background())
|
||||
|
||||
So(err, ShouldBeError)
|
||||
|
||||
_, err = strings.Like(context.Background(), values.NewString(""))
|
||||
|
||||
So(err, ShouldBeError)
|
||||
})
|
||||
})
|
||||
|
||||
Convey("Should return true when matches with _ pattern", t, func() {
|
||||
out, _ := strings.Like(
|
||||
context.Background(),
|
||||
values.NewString("cart"),
|
||||
values.NewString("ca_t"),
|
||||
)
|
||||
|
||||
So(out, ShouldEqual, true)
|
||||
})
|
||||
|
||||
Convey("Should return true when matches with % pattern", t, func() {
|
||||
out, _ := strings.Like(
|
||||
context.Background(),
|
||||
values.NewString("foo bar baz"),
|
||||
values.NewString("%bar%"),
|
||||
)
|
||||
|
||||
So(out, ShouldEqual, true)
|
||||
})
|
||||
|
||||
Convey("Should return false when matches with no caseInsensitive parameter", t, func() {
|
||||
out, _ := strings.Like(
|
||||
context.Background(),
|
||||
values.NewString("FoO bAr BaZ"),
|
||||
values.NewString("fOo%bAz"),
|
||||
)
|
||||
|
||||
So(out, ShouldEqual, false)
|
||||
})
|
||||
|
||||
Convey("Should return true when matches with caseInsensitive parameter", t, func() {
|
||||
out, _ := strings.Like(
|
||||
context.Background(),
|
||||
values.NewString("FoO bAr BaZ"),
|
||||
values.NewString("fOo%bAz"),
|
||||
values.True,
|
||||
)
|
||||
|
||||
So(out, ShouldEqual, true)
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user