mirror of
				https://github.com/MontFerret/ferret.git
				synced 2025-10-30 23:37:40 +02:00 
			
		
		
		
	
		
			
				
	
	
		
			50 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.1 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 TestSplit(t *testing.T) {
 | |
| 	Convey("When args are not passed", t, func() {
 | |
| 		Convey("It should return an error", func() {
 | |
| 			var err error
 | |
| 			_, err = strings.Split(context.Background())
 | |
| 
 | |
| 			So(err, ShouldBeError)
 | |
| 
 | |
| 			_, err = strings.Split(context.Background(), values.NewString("foo"))
 | |
| 
 | |
| 			So(err, ShouldBeError)
 | |
| 		})
 | |
| 	})
 | |
| 
 | |
| 	Convey("Split('foo-bar-baz', '-' ) should return an array", t, func() {
 | |
| 		out, err := strings.Split(
 | |
| 			context.Background(),
 | |
| 			values.NewString("foo-bar-baz"),
 | |
| 			values.NewString("-"),
 | |
| 		)
 | |
| 
 | |
| 		So(err, ShouldBeNil)
 | |
| 
 | |
| 		So(out.String(), ShouldEqual, `["foo","bar","baz"]`)
 | |
| 	})
 | |
| 
 | |
| 	Convey("Split('foo-bar-baz', '-', 2) should return an array", t, func() {
 | |
| 		out, err := strings.Split(
 | |
| 			context.Background(),
 | |
| 			values.NewString("foo-bar-baz"),
 | |
| 			values.NewString("-"),
 | |
| 			values.NewInt(2),
 | |
| 		)
 | |
| 
 | |
| 		So(err, ShouldBeNil)
 | |
| 
 | |
| 		So(out.String(), ShouldEqual, `["foo","bar-baz"]`)
 | |
| 	})
 | |
| }
 |