28 lines
703 B
Go
28 lines
703 B
Go
package Splitstring
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
//测试组
|
|
|
|
func TestGroupSplit(t *testing.T) {
|
|
type testCase struct {
|
|
str string
|
|
sep string
|
|
want []string
|
|
}
|
|
testGroup := []testCase{
|
|
{str: "babcbef", sep: "b", want: []string{"", "a", "c", "ef"}},
|
|
{str: "a:b:c", sep: ":", want: []string{"a", "b", "c"}},
|
|
{str: "abcef", sep: "bc", want: []string{"a", "ef"}},
|
|
{str: "沙河有沙又有河", sep: "有", want: []string{"沙河", "沙又", "河"}},
|
|
}
|
|
for i, testcase := range testGroup {
|
|
if !reflect.DeepEqual(Split(testcase.str, testcase.sep), testcase.want) {
|
|
t.Errorf("testcase %d failed,want: %v got: %v", i+1, testcase.want, Split(testcase.str, testcase.sep))
|
|
}
|
|
}
|
|
}
|