pinyin_test.go 1004 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package stringutil
  2. import (
  3. "regexp"
  4. "testing"
  5. "time"
  6. "github.com/dlclark/regexp2"
  7. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/util/authutil"
  8. )
  9. func TestZhToPinyin(t *testing.T) {
  10. zh := "隐私级别1"
  11. l := []rune(zh)
  12. t.Logf("l %v", string(l[0:2]))
  13. sep := "_"
  14. got := ZhToPinyin(zh, sep)
  15. t.Logf("got: %v", SnakeToCamel(got, CamelSmall))
  16. }
  17. func TestCamelToSnake(t *testing.T) {
  18. got := CamelToSnake("AsdFert")
  19. t.Logf("got: %v", got)
  20. }
  21. func TestSnakeToCamel(t *testing.T) {
  22. p, _ := authutil.Encrypt("123123")
  23. t.Logf("密码:%s", p)
  24. t.Logf(time.UnixMilli(1678679758000).String())
  25. }
  26. func TestSnake(t *testing.T) {
  27. str := "wq1234"
  28. matched, _ := regexp.MatchString("^(?:.*\\d)(?:.*[a-zA-Z])[0-9a-zA-Z]*$", str)
  29. t.Logf("ret1: %v", matched)
  30. matched, _ = regexp.MatchString("^(.*\\d)(.*[a-zA-Z])[0-9a-zA-Z]*$", str)
  31. t.Logf("ret2: %v", matched)
  32. reg, _ := regexp2.Compile(`^((?=.*[0-9])(?=.*[a-zA-Z]).{6,50})$`, 0)
  33. matched, _ = reg.MatchString(str)
  34. t.Logf("ret3: %v", matched)
  35. }