package goconvey import ( c "github.com/smartystreets/goconvey/convey" // 别名导入 "testing" ) func Test_Split(t *testing.T) { c.Convey("基础用例", t, func() { var ( s = "a:b:c" sep = ":" expect = []string{"a", "b", "c"} ) got := Split(s, sep) c.So(got, c.ShouldResemble, expect) // 断言 }) c.Convey("不包含分隔符用例", t, func() { var ( s = "a:b:c" sep = "|" expect = []string{"a:b:c"} ) got := Split(s, sep) c.So(got, c.ShouldResemble, expect) // 断言 }) } func Test_SplitMuch(t *testing.T) { c.Convey("分隔符在开头或结尾用例", t, func() { tt := []struct { name string s string sep string expect []string }{ {"分隔符在开头", "*1*2*3", "*", []string{"", "1", "2", "3"}}, {"分隔符在结尾", "1+2+3+", "+", []string{"1", "2", "3", ""}}, } for _, tc := range tt { c.Convey(tc.name, func() { // 嵌套调用Convey got := Split(tc.s, tc.sep) c.So(got, c.ShouldResemble, tc.expect) }) } }) }