-
Notifications
You must be signed in to change notification settings - Fork 1
/
number_test.go
40 lines (32 loc) · 1.02 KB
/
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
package hvalid
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNumberMin(t *testing.T) {
var n1 int = 256
err := Validate[int](n1, Min(1000, ""))
assert.Error(t, err)
var n2 uint = 256
err = Validate[uint](n2, Min(uint(255), ""))
assert.NoError(t, err)
}
func TestNumberMax(t *testing.T) {
var n1 int = 256
err := Validate[int](n1, Max(255))
assert.Error(t, err)
var n2 uint = 256
err = Validate[uint](n2, Max(uint(1000)))
assert.NoError(t, err)
}
func TestNumberLimit(t *testing.T) {
var n1 int = 100
err := Validate[int](n1, Min(110, "The num is less than the minimum value"), Max(200))
assert.ErrorContains(t, err, "The num is less than the minimum value")
var n2 uint = 100
err = Validate[uint](n2, Min(uint(1)), Max(uint(99), "The num is greater than the maximum value, maximum value"))
assert.ErrorContains(t, err, "The num is greater than the maximum value, maximum value")
var n3 float32 = 0.12
err = Validate[float32](n3, Min(float32(0.1)), Max(float32(1.0)))
assert.NoError(t, err)
}