-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate_test.go
61 lines (55 loc) · 1.26 KB
/
validate_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package gdk
import "testing"
func TestIsEmail(t *testing.T) {
tests := []struct {
name string
input string
want bool
}{
{"good case with qq", "[email protected]", true},
{"good case with gmail", "[email protected]", true},
{"bad case", "122.com", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsEmail(tt.input); got != tt.want {
t.Errorf("got %v, want %v", got, tt.want)
}
})
}
}
func TestIsEmailRFC(t *testing.T) {
tests := []struct {
name string
input string
want bool
}{
{"good case with qq", "[email protected]", true},
{"good case with gmail", "[email protected]", true},
{"bad case", "122.com", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsEmailRFC(tt.input); got != tt.want {
t.Errorf("got %v, want %v", got, tt.want)
}
})
}
}
func TestIsUrl(t *testing.T) {
tests := []struct {
name string
input string
want bool
}{
{"good case", "http://www.baidu.com", true},
{"good case with https", "https://www.baidu.com", true},
{"good case with ftp", "ftp://www.baidu.com", true},
{"bad case", "www.baidu.com", false},
}
for _, tt := range tests {
if got := IsUrl(tt.input); got != tt.want {
t.Errorf("got %v, want %v", got, tt.want)
}
}
}