func_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package goconvey
  2. import (
  3. c "github.com/smartystreets/goconvey/convey" // 别名导入
  4. "testing"
  5. )
  6. func Test_Split(t *testing.T) {
  7. c.Convey("基础用例", t, func() {
  8. var (
  9. s = "a:b:c"
  10. sep = ":"
  11. expect = []string{"a", "b", "c"}
  12. )
  13. got := Split(s, sep)
  14. c.So(got, c.ShouldResemble, expect) // 断言
  15. })
  16. c.Convey("不包含分隔符用例", t, func() {
  17. var (
  18. s = "a:b:c"
  19. sep = "|"
  20. expect = []string{"a:b:c"}
  21. )
  22. got := Split(s, sep)
  23. c.So(got, c.ShouldResemble, expect) // 断言
  24. })
  25. }
  26. func Test_SplitMuch(t *testing.T) {
  27. c.Convey("分隔符在开头或结尾用例", t, func() {
  28. tt := []struct {
  29. name string
  30. s string
  31. sep string
  32. expect []string
  33. }{
  34. {"分隔符在开头", "*1*2*3", "*", []string{"", "1", "2", "3"}},
  35. {"分隔符在结尾", "1+2+3+", "+", []string{"1", "2", "3", ""}},
  36. }
  37. for _, tc := range tt {
  38. c.Convey(tc.name, func() { // 嵌套调用Convey
  39. got := Split(tc.s, tc.sep)
  40. c.So(got, c.ShouldResemble, tc.expect)
  41. })
  42. }
  43. })
  44. }