validators_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package utl
  2. import (
  3. "testing"
  4. )
  5. func TestIsPhone(t *testing.T) {
  6. phones := []string{
  7. "137234510452",
  8. "12398765434",
  9. "13604550543",
  10. "13456786543",
  11. "16703440355",
  12. "19100001111",
  13. "19200001111",
  14. }
  15. var b, bs bool
  16. var phone string
  17. phone = phones[0]
  18. bs, b = IsPhoneSimple(phone), IsPhone(phone)
  19. AssertFalse(bs, phone+" should not be phone", t)
  20. AssertFalse(b, phone+" should not be phone", t)
  21. phone = phones[1]
  22. bs, b = IsPhoneSimple(phone), IsPhone(phone)
  23. AssertTrue(bs, phone+" should be phone", t)
  24. AssertFalse(b, phone+" should not be phone", t)
  25. }
  26. func TestIsEmail(t *testing.T) {
  27. yes := IsEmail("y282@163.com")
  28. if !yes {
  29. t.Fatal("?")
  30. }
  31. yes = IsEmail("t23.yjd@gmail.com")
  32. if !yes {
  33. t.Fatal("??")
  34. }
  35. yes = IsEmail("2343@163.com")
  36. if !yes {
  37. t.Fatal("???")
  38. }
  39. }
  40. func TestIsAlpha(t *testing.T) {
  41. yes := IsAlpha("y282@163.com")
  42. if yes {
  43. t.Fatal("?")
  44. }
  45. yes = IsAlpha("t45")
  46. if !yes {
  47. t.Fatal("??")
  48. }
  49. yes = IsAlpha("234")
  50. if yes {
  51. t.Fatal("???")
  52. }
  53. }
  54. func TestIsSafePasswd(t *testing.T) {
  55. l, n, u, o := CheckPasswd("Ty234#")
  56. if !(l && n && u && o) {
  57. t.Fatal("what")
  58. }
  59. }