github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/strings/trim_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 TestLTrim(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.LTrim(context.Background()) 18 19 So(err, ShouldBeError) 20 21 }) 22 }) 23 24 Convey("LTrim(' foo bar ') should return 'foo bar '", t, func() { 25 out, _ := strings.LTrim( 26 context.Background(), 27 values.NewString(" foo bar "), 28 ) 29 30 So(out, ShouldEqual, "foo bar ") 31 }) 32 33 Convey("LTrim('--==[foo-bar]==--', '-=[]') should return 'foo-bar]==--'", t, func() { 34 out, _ := strings.LTrim( 35 context.Background(), 36 values.NewString("--==[foo-bar]==--"), 37 values.NewString("-=[]"), 38 ) 39 40 So(out, ShouldEqual, "foo-bar]==--") 41 }) 42 } 43 44 func TestRTrim(t *testing.T) { 45 Convey("When args are not passed", t, func() { 46 Convey("It should return an error", func() { 47 var err error 48 _, err = strings.RTrim(context.Background()) 49 50 So(err, ShouldBeError) 51 52 }) 53 }) 54 55 Convey("RTrim(' foo bar ') should return ' foo bar'", t, func() { 56 out, _ := strings.RTrim( 57 context.Background(), 58 values.NewString(" foo bar "), 59 ) 60 61 So(out, ShouldEqual, " foo bar") 62 }) 63 64 Convey("LTrim('--==[foo-bar]==--', '-=[]') should return '--==[foo-bar'", t, func() { 65 out, _ := strings.RTrim( 66 context.Background(), 67 values.NewString("--==[foo-bar]==--"), 68 values.NewString("-=[]"), 69 ) 70 71 So(out, ShouldEqual, "--==[foo-bar") 72 }) 73 } 74 75 func TestTrim(t *testing.T) { 76 Convey("When args are not passed", t, func() { 77 Convey("It should return an error", func() { 78 var err error 79 _, err = strings.Trim(context.Background()) 80 81 So(err, ShouldBeError) 82 83 }) 84 }) 85 86 Convey("Trim(' foo bar ') should return 'foo bar'", t, func() { 87 out, _ := strings.Trim( 88 context.Background(), 89 values.NewString(" foo bar "), 90 ) 91 92 So(out, ShouldEqual, "foo bar") 93 }) 94 95 Convey("Trim('--==[foo-bar]==--', '-=[]') should return 'foo-bar'", t, func() { 96 out, _ := strings.Trim( 97 context.Background(), 98 values.NewString("--==[foo-bar]==--"), 99 values.NewString("-=[]"), 100 ) 101 102 So(out, ShouldEqual, "foo-bar") 103 }) 104 }