|
@@ -0,0 +1,77 @@
|
|
|
+package strutils
|
|
|
+
|
|
|
+import (
|
|
|
+ "strings"
|
|
|
+ "testing"
|
|
|
+)
|
|
|
+
|
|
|
+func TestAllBlank(t *testing.T) {
|
|
|
+ allBlank := AllBlank("", "", "")
|
|
|
+ if !allBlank {
|
|
|
+ t.Fatal("字符串全为空但是检测失败")
|
|
|
+ }
|
|
|
+
|
|
|
+ allBlank = AllBlank("", "foo", "")
|
|
|
+ if allBlank {
|
|
|
+ t.Fatal("字符串不全为空但是检测失败")
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func TestIsStringEmpty(t *testing.T) {
|
|
|
+ stringEmpty := IsStringEmpty("")
|
|
|
+ if !stringEmpty {
|
|
|
+ t.Fatal("字符串为空但是检测失败")
|
|
|
+ }
|
|
|
+
|
|
|
+ stringEmpty = IsStringEmpty("foo")
|
|
|
+ if stringEmpty {
|
|
|
+ t.Fatal("字符串不为空但是检测失败")
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func TestIsStringNotEmpty(t *testing.T) {
|
|
|
+ stringNotEmpty := IsStringNotEmpty("")
|
|
|
+ if stringNotEmpty {
|
|
|
+ t.Fatal("字符串为空但是检测失败")
|
|
|
+ }
|
|
|
+
|
|
|
+ stringNotEmpty = IsStringNotEmpty("foo")
|
|
|
+ if !stringNotEmpty {
|
|
|
+ t.Fatal("字符串不为空但是检测失败")
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func TestUUID(t *testing.T) {
|
|
|
+ UUID := GetUUID()
|
|
|
+ UUIDParts := strings.Split(UUID, "-")
|
|
|
+
|
|
|
+ if len(UUIDParts) != 5 {
|
|
|
+ t.Fatal("生成uuid格式不正确")
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(UUIDParts[0]) != 8 {
|
|
|
+ t.Fatal("生成uuid第一段长度不为8")
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(UUIDParts[1]) != 4 {
|
|
|
+ t.Fatal("生成uuid第二段长度不为4")
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(UUIDParts[2]) != 4 {
|
|
|
+ t.Fatal("生成uuid第三段长度不为4")
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(UUIDParts[3]) != 4 {
|
|
|
+ t.Fatal("生成uuid第四段长度不为4")
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(UUIDParts[4]) != 12 {
|
|
|
+ t.Fatal("生成uuid第五段长度不为12")
|
|
|
+ }
|
|
|
+
|
|
|
+ simpleUUID := SimpleUUID()
|
|
|
+
|
|
|
+ if len(simpleUUID) != 32 {
|
|
|
+ t.Fatal("生成uuid长度不为32")
|
|
|
+ }
|
|
|
+}
|