-
Notifications
You must be signed in to change notification settings - Fork 1
/
validator_number_test.go
79 lines (62 loc) · 2.19 KB
/
validator_number_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
package validation
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/tiendc/gofn"
)
func Test_NumEQ(t *testing.T) {
errs := NumEQ(gofn.ToPtr(10), 10).Validate(ctxBg)
assert.Equal(t, 0, len(errs))
errs = NumEQ(gofn.ToPtr(10), 9).Validate(ctxBg)
assert.Equal(t, 1, len(errs))
}
func Test_NumGT_NumGTE(t *testing.T) {
errs := NumGT(gofn.ToPtr(10), 9).Validate(ctxBg)
assert.Equal(t, 0, len(errs))
errs = NumGTE(gofn.ToPtr(10), 10).Validate(ctxBg)
assert.Equal(t, 0, len(errs))
errs = NumGT(gofn.ToPtr(10), 10).Validate(ctxBg)
assert.Equal(t, "gt", errs[0].Type())
errs = NumGTE(gofn.ToPtr(10), 11).Validate(ctxBg)
assert.Equal(t, "gte", errs[0].Type())
}
func Test_NumLT_NumLTE(t *testing.T) {
errs := NumLT(gofn.ToPtr(10), 11).Validate(ctxBg)
assert.Equal(t, 0, len(errs))
errs = NumLTE(gofn.ToPtr(10), 10).Validate(ctxBg)
assert.Equal(t, 0, len(errs))
errs = NumLT(gofn.ToPtr(10), 10).Validate(ctxBg)
assert.Equal(t, "lt", errs[0].Type())
errs = NumLTE(gofn.ToPtr(10), 9).Validate(ctxBg)
assert.Equal(t, "lte", errs[0].Type())
}
func Test_NumRange(t *testing.T) {
errs := NumRange(gofn.ToPtr(10), 2, 10).Validate(ctxBg)
assert.Equal(t, 0, len(errs))
errs = NumRange(gofn.ToPtr(10), 1, 9).Validate(ctxBg)
assert.Equal(t, "range", errs[0].Type())
}
func Test_NumIn(t *testing.T) {
errs := NumIn(gofn.ToPtr(1), 0, 1, 10).Validate(ctxBg)
assert.Equal(t, 0, len(errs))
errs = NumIn(gofn.ToPtr(1), 0, 2, 10).Validate(ctxBg)
assert.Equal(t, "in", errs[0].Type())
}
func Test_NumNotIn(t *testing.T) {
errs := NumNotIn(gofn.ToPtr(1), 0, 2, 10).Validate(ctxBg)
assert.Equal(t, 0, len(errs))
errs = NumNotIn(gofn.ToPtr(1), 0, 1, 2).Validate(ctxBg)
assert.Equal(t, "not_in", errs[0].Type())
}
func Test_NumDivisibleBy(t *testing.T) {
errs := NumDivisibleBy(gofn.ToPtr(10), 5).Validate(ctxBg)
assert.Equal(t, 0, len(errs))
errs = NumDivisibleBy(gofn.ToPtr(8), 3).Validate(ctxBg)
assert.Equal(t, "divisible_by", errs[0].Type())
}
func Test_NumJsSafeInt(t *testing.T) {
errs := NumJsSafeInt(gofn.ToPtr(9007199254740991)).Validate(ctxBg)
assert.Equal(t, 0, len(errs))
errs = NumJsSafeInt(gofn.ToPtr(9007199254740992)).Validate(ctxBg)
assert.Equal(t, "js_safe_int", errs[0].Type())
}