123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- package strutils
- import (
- "strings"
- "testing"
- )
- func TestAllBlank(t *testing.T) {
- allBlank := AllBlank("", "", "")
- if !allBlank {
- t.Fatal("字符串全为空但是检测失败")
- }
- allBlank = AllBlank("", "foo", "")
- if allBlank {
- t.Fatal("字符串不全为空但是检测失败")
- }
- }
- func TestHasBlank(t *testing.T) {
- hasBlank := HasBlank("a", "", "b")
- if !hasBlank {
- t.Fatal("字符串包含空字符串检测失败")
- }
- hasBlank = HasBlank("a", "b", "c")
- if hasBlank {
- t.Fatal("字符串不包含空字符串但是检测失败")
- }
- }
- func TestHasText(t *testing.T) {
- hasText := HasText("a", "", "b")
- if !hasText {
- t.Fatal("字符串包含字符串检测失败")
- }
- hasText = HasText("", "", "")
- if hasText {
- 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")
- }
- }
- func TestGenerateUpperLetters(t *testing.T) {
- letters := GenerateUpperLetters(3)
- if letters[0] != "A" || letters[1] != "B" || letters[2] != "C" {
- t.Fatal("生成字母错误")
- }
- }
- func TestGenerateLowerLetters(t *testing.T) {
- letters := GenerateLowerLetters(3)
- if letters[0] != "a" || letters[1] != "b" || letters[2] != "c" {
- t.Fatal("生成字母错误")
- }
- }
|