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