deepseek修改版
This commit is contained in:
@@ -495,6 +495,28 @@ func TestUUIDShort(t *testing.T) {
|
||||
if len(uuid) != 32 {
|
||||
t.Errorf("UUIDShort length = %d", len(uuid))
|
||||
}
|
||||
// U1 回归:确保无破折号
|
||||
if uuid[8] == '-' || uuid[12] == '-' || uuid[16] == '-' || uuid[20] == '-' {
|
||||
t.Errorf("UUIDShort contains dashes at unexpected positions: %s", uuid)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUUIDShort_NoDashes(t *testing.T) {
|
||||
// U1 回归:100 次生成全部不含破折号,长度精确 32
|
||||
for range 100 {
|
||||
s := utils.UUIDShort()
|
||||
if len(s) != 32 {
|
||||
t.Fatalf("UUIDShort length = %d, want 32", len(s))
|
||||
}
|
||||
for j, c := range s {
|
||||
if c == '-' {
|
||||
t.Fatalf("UUIDShort contains dash at position %d: %s", j, s)
|
||||
}
|
||||
if !((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f')) {
|
||||
t.Fatalf("UUIDShort non-hex char at position %d: %c in %s", j, c, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUUIDValid(t *testing.T) {
|
||||
|
||||
+4
-2
@@ -1,6 +1,8 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
@@ -9,9 +11,9 @@ func UUID() string {
|
||||
return uuid.New().String()
|
||||
}
|
||||
|
||||
// UUIDShort 生成短 UUID(无横线)
|
||||
// UUIDShort 生成短 UUID(无横线,32 个十六进制字符)
|
||||
func UUIDShort() string {
|
||||
return uuid.New().String()[:32]
|
||||
return strings.ReplaceAll(uuid.New().String(), "-", "")
|
||||
}
|
||||
|
||||
// UUIDParse 解析 UUID 字符串
|
||||
|
||||
Reference in New Issue
Block a user