strutils_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 TestHasBlank(t *testing.T) {
  17. hasBlank := HasBlank("a", "", "b")
  18. if !hasBlank {
  19. t.Fatal("字符串包含空字符串检测失败")
  20. }
  21. hasBlank = HasBlank("a", "b", "c")
  22. if hasBlank {
  23. t.Fatal("字符串不包含空字符串但是检测失败")
  24. }
  25. }
  26. func TestIsStringEmpty(t *testing.T) {
  27. stringEmpty := IsStringEmpty("")
  28. if !stringEmpty {
  29. t.Fatal("字符串为空但是检测失败")
  30. }
  31. stringEmpty = IsStringEmpty("foo")
  32. if stringEmpty {
  33. t.Fatal("字符串不为空但是检测失败")
  34. }
  35. }
  36. func TestIsStringNotEmpty(t *testing.T) {
  37. stringNotEmpty := IsStringNotEmpty("")
  38. if stringNotEmpty {
  39. t.Fatal("字符串为空但是检测失败")
  40. }
  41. stringNotEmpty = IsStringNotEmpty("foo")
  42. if !stringNotEmpty {
  43. t.Fatal("字符串不为空但是检测失败")
  44. }
  45. }
  46. func TestUUID(t *testing.T) {
  47. UUID := GetUUID()
  48. UUIDParts := strings.Split(UUID, "-")
  49. if len(UUIDParts) != 5 {
  50. t.Fatal("生成uuid格式不正确")
  51. }
  52. if len(UUIDParts[0]) != 8 {
  53. t.Fatal("生成uuid第一段长度不为8")
  54. }
  55. if len(UUIDParts[1]) != 4 {
  56. t.Fatal("生成uuid第二段长度不为4")
  57. }
  58. if len(UUIDParts[2]) != 4 {
  59. t.Fatal("生成uuid第三段长度不为4")
  60. }
  61. if len(UUIDParts[3]) != 4 {
  62. t.Fatal("生成uuid第四段长度不为4")
  63. }
  64. if len(UUIDParts[4]) != 12 {
  65. t.Fatal("生成uuid第五段长度不为12")
  66. }
  67. simpleUUID := SimpleUUID()
  68. if len(simpleUUID) != 32 {
  69. t.Fatal("生成uuid长度不为32")
  70. }
  71. }