mirror of
https://github.com/MontFerret/ferret.git
synced 2024-12-16 11:37:36 +02:00
50 lines
1.2 KiB
Go
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")
|
||
|
})
|
||
|
}
|