github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/strings/substitute_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 TestSubstitute(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.Substitute(context.Background()) 18 19 So(err, ShouldBeError) 20 21 _, err = strings.Substitute(context.Background(), values.NewString("foo")) 22 23 So(err, ShouldBeError) 24 }) 25 }) 26 27 Convey("Substitute('foo-bar-baz', 'a', 'o') should return 'foo-bor-boz'", t, func() { 28 out, err := strings.Substitute( 29 context.Background(), 30 values.NewString("foo-bar-baz"), 31 values.NewString("a"), 32 values.NewString("o"), 33 ) 34 35 So(err, ShouldBeNil) 36 So(out, ShouldEqual, "foo-bor-boz") 37 }) 38 39 Convey("Substitute('foo-bar-baz', 'a', 'o', 1) should return 'foo-bor-baz'", t, func() { 40 out, err := strings.Substitute( 41 context.Background(), 42 values.NewString("foo-bar-baz"), 43 values.NewString("a"), 44 values.NewString("o"), 45 values.NewInt(1), 46 ) 47 48 So(err, ShouldBeNil) 49 So(out, ShouldEqual, "foo-bor-baz") 50 }) 51 }