1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-23 01:24:30 +02:00
ferret/pkg/stdlib/strings/substitute_test.go
Tim Voronov e6d692010c stdlib.strings
Added string functions to standard library
2018-09-21 20:37:09 -04:00

50 lines
1.2 KiB
Go

package strings_test
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/values"
"github.com/MontFerret/ferret/pkg/stdlib/strings"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestSubstitute(t *testing.T) {
Convey("When args are not passed", t, func() {
Convey("It should return an error", func() {
var err error
_, err = strings.Substitute(context.Background())
So(err, ShouldBeError)
_, err = strings.Substitute(context.Background(), values.NewString("foo"))
So(err, ShouldBeError)
})
})
Convey("Substitute('foo-bar-baz', 'a', 'o') should return 'foo-bor-boz'", t, func() {
out, err := strings.Substitute(
context.Background(),
values.NewString("foo-bar-baz"),
values.NewString("a"),
values.NewString("o"),
)
So(err, ShouldBeNil)
So(out, ShouldEqual, "foo-bor-boz")
})
Convey("Substitute('foo-bar-baz', 'a', 'o', 1) should return 'foo-bor-baz'", t, func() {
out, err := strings.Substitute(
context.Background(),
values.NewString("foo-bar-baz"),
values.NewString("a"),
values.NewString("o"),
values.NewInt(1),
)
So(err, ShouldBeNil)
So(out, ShouldEqual, "foo-bor-baz")
})
}