github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/strings/like_test.go (about) 1 package strings_test 2 3 import ( 4 "context" 5 "testing" 6 7 . "github.com/smartystreets/goconvey/convey" 8 9 "github.com/MontFerret/ferret/pkg/runtime/values" 10 "github.com/MontFerret/ferret/pkg/stdlib/strings" 11 ) 12 13 func TestLike(t *testing.T) { 14 Convey("When args are not passed", t, func() { 15 Convey("It should return an error", func() { 16 var err error 17 _, err = strings.Like(context.Background()) 18 19 So(err, ShouldBeError) 20 21 _, err = strings.Like(context.Background(), values.NewString("")) 22 23 So(err, ShouldBeError) 24 }) 25 }) 26 27 Convey("Should return true when matches with _ pattern", t, func() { 28 out, _ := strings.Like( 29 context.Background(), 30 values.NewString("cart"), 31 values.NewString("ca_t"), 32 ) 33 34 So(out, ShouldEqual, true) 35 }) 36 37 Convey("Should return true when matches with % pattern", t, func() { 38 out, _ := strings.Like( 39 context.Background(), 40 values.NewString("foo bar baz"), 41 values.NewString("%bar%"), 42 ) 43 44 So(out, ShouldEqual, true) 45 }) 46 47 Convey("Should return false when matches with no caseInsensitive parameter", t, func() { 48 out, _ := strings.Like( 49 context.Background(), 50 values.NewString("FoO bAr BaZ"), 51 values.NewString("fOo%bAz"), 52 ) 53 54 So(out, ShouldEqual, false) 55 }) 56 57 Convey("Should return true when matches with caseInsensitive parameter", t, func() { 58 out, _ := strings.Like( 59 context.Background(), 60 values.NewString("FoO bAr BaZ"), 61 values.NewString("fOo%bAz"), 62 values.True, 63 ) 64 65 So(out, ShouldEqual, true) 66 }) 67 }