strutils_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package strutils
  2. import (
  3. "strings"
  4. "testing"
  5. )
  6. func TestAllBlank(t *testing.T) {
  7. allBlank := AllBlank("", "", "")
  8. if !allBlank {
  9. t.Fatal("字符串全为空但是检测失败")
  10. }
  11. allBlank = AllBlank("", "foo", "")
  12. if allBlank {
  13. t.Fatal("字符串不全为空但是检测失败")
  14. }
  15. }
  16. func TestIsStringEmpty(t *testing.T) {
  17. stringEmpty := IsStringEmpty("")
  18. if !stringEmpty {
  19. t.Fatal("字符串为空但是检测失败")
  20. }
  21. stringEmpty = IsStringEmpty("foo")
  22. if stringEmpty {
  23. t.Fatal("字符串不为空但是检测失败")
  24. }
  25. }
  26. func TestIsStringNotEmpty(t *testing.T) {
  27. stringNotEmpty := IsStringNotEmpty("")
  28. if stringNotEmpty {
  29. t.Fatal("字符串为空但是检测失败")
  30. }
  31. stringNotEmpty = IsStringNotEmpty("foo")
  32. if !stringNotEmpty {
  33. t.Fatal("字符串不为空但是检测失败")
  34. }
  35. }
  36. func TestUUID(t *testing.T) {
  37. UUID := GetUUID()
  38. UUIDParts := strings.Split(UUID, "-")
  39. if len(UUIDParts) != 5 {
  40. t.Fatal("生成uuid格式不正确")
  41. }
  42. if len(UUIDParts[0]) != 8 {
  43. t.Fatal("生成uuid第一段长度不为8")
  44. }
  45. if len(UUIDParts[1]) != 4 {
  46. t.Fatal("生成uuid第二段长度不为4")
  47. }
  48. if len(UUIDParts[2]) != 4 {
  49. t.Fatal("生成uuid第三段长度不为4")
  50. }
  51. if len(UUIDParts[3]) != 4 {
  52. t.Fatal("生成uuid第四段长度不为4")
  53. }
  54. if len(UUIDParts[4]) != 12 {
  55. t.Fatal("生成uuid第五段长度不为12")
  56. }
  57. simpleUUID := SimpleUUID()
  58. if len(simpleUUID) != 32 {
  59. t.Fatal("生成uuid长度不为32")
  60. }
  61. }