-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdefault_test.go
147 lines (126 loc) · 3.27 KB
/
default_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package govals
import "testing"
type testCase struct {
name string
val string
err error
}
func TestEmail(t *testing.T) {
tc := []testCase{
{name: "valid email", val: "[email protected]"},
{name: "invalid email", val: "ludyyn$$##gmail.com", err: errInvalidFormat},
{name: "empty email", val: "", err: errEmptyValue},
}
for _, tt := range tc {
t.Run(tt.name, func(t *testing.T) {
ok, err := Email(tt.val)
if tt.err != nil {
if tt.err != err && !ok {
t.Errorf("error email expects %v, got %v\n", tt.err, err)
}
}
})
}
}
func TestNumeric(t *testing.T) {
tc := []testCase{
{name: "valid numeric", val: "122323"},
{name: "invalid numeric", val: "23dsdfdfsdf", err: errInvalidFormat},
{name: "empty numeric", val: "", err: errEmptyValue},
}
for _, tt := range tc {
t.Run(tt.name, func(t *testing.T) {
ok, err := Numeric(tt.val)
if tt.err != nil {
if tt.err != err && !ok {
t.Errorf("error numeric expects %v, got %v\n", tt.err, err)
}
}
})
}
}
func TestAlpha(t *testing.T) {
tc := []testCase{
{name: "valid alpha", val: "Ludin Nento"},
{name: "invalid alpha", val: "sdfnj23434", err: errInvalidFormat},
{name: "empty alpha", val: "", err: errEmptyValue},
}
for _, tt := range tc {
t.Run(tt.name, func(t *testing.T) {
ok, err := Alpha(tt.val)
if tt.err != nil {
if tt.err != err && !ok {
t.Errorf("error alpha expects %v, got %v\n", tt.err, err)
}
}
})
}
}
func TestAlphaNumeric(t *testing.T) {
tc := []testCase{
{name: "valid alpha numeric", val: "Ludin Nento2323"},
{name: "invalid alpha numeric", val: "sdfnj23434^^&9", err: errInvalidFormat},
{name: "empty alpha numeric", val: "", err: errEmptyValue},
}
for _, tt := range tc {
t.Run(tt.name, func(t *testing.T) {
ok, err := AlphaNumeric(tt.val)
if tt.err != nil {
if tt.err != err && !ok {
t.Errorf("error alpha numeric expects %v, got %v\n", tt.err, err)
}
}
})
}
}
func TestDate(t *testing.T) {
tc := []testCase{
{name: "valid date", val: "12-12-1996"},
{name: "invalid date", val: "12-", err: errInvalidFormat},
{name: "empty date", val: "", err: errEmptyValue},
}
for _, tt := range tc {
t.Run(tt.name, func(t *testing.T) {
ok, err := Date(tt.val)
if tt.err != nil {
if tt.err != err && !ok {
t.Errorf("error date expects %v, got %v\n", tt.err, err)
}
}
})
}
}
func TestTimes(t *testing.T) {
tc := []testCase{
{name: "valid time", val: "12:12:01"},
{name: "invalid time", val: "12:", err: errInvalidFormat},
{name: "empty time", val: "", err: errEmptyValue},
}
for _, tt := range tc {
t.Run(tt.name, func(t *testing.T) {
ok, err := Times(tt.val)
if tt.err != nil {
if tt.err != err && !ok {
t.Errorf("error time expects %v, got %v\n", tt.err, err)
}
}
})
}
}
func TestPhoneNumber(t *testing.T) {
tc := []testCase{
{name: "valid phone number", val: "+6282290202728"},
{name: "invalid phone number", val: "12--&&809098^^%$:", err: errInvalidFormat},
{name: "empty phone number", val: "", err: errEmptyValue},
}
for _, tt := range tc {
t.Run(tt.name, func(t *testing.T) {
ok, err := PhoneNumber(tt.val)
if tt.err != nil {
if tt.err != err && !ok {
t.Errorf("error phone number expects %v, got %v\n", tt.err, err)
}
}
})
}
}