-
Notifications
You must be signed in to change notification settings - Fork 4
/
numeric_test.go
62 lines (55 loc) · 1.29 KB
/
numeric_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
package govalidator
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_NumericString(t *testing.T) {
tests := []struct {
name string
field string
value string
isPassed bool
msg string
expectedMsg string
}{
{
name: "test `1234` will pass validation as a numeric-string value",
field: "postal_code",
value: "1234",
isPassed: true,
msg: "",
expectedMsg: "",
},
{
name: "test `abc` won't pass numeric-string validation",
field: "postal_code",
value: "abc",
isPassed: false,
msg: "",
expectedMsg: "postal_code must be a numeric string",
},
{
name: "test ` ` won't pass numeric-string validation",
field: "postal_code",
value: " ",
isPassed: false,
msg: "postal_code must be a numeric string",
expectedMsg: "postal_code must be a numeric string",
},
}
for _, test := range tests {
v := New()
v.NumericString(test.value, test.field, test.msg)
assert.Equal(t, test.isPassed, v.IsPassed())
if !test.isPassed {
assert.Equalf(
t,
test.expectedMsg,
v.Errors()[test.field],
"%q failed: expected: %s, got: %s",
test.expectedMsg,
v.Errors()[test.field],
)
}
}
}