-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlen_test.go
60 lines (55 loc) · 1.63 KB
/
len_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
package govals
import (
"fmt"
"testing"
)
func TestRuneLength(t *testing.T) {
tc := []struct {
name string
value string
min int
max int
err error
}{
{name: "valid rune length", value: "ludin", min: 2, max: 10},
{name: "invalid rune length min", value: "ludin", min: 8, max: 10, err: fmt.Errorf("error value")},
{name: "invalid rune length max", value: "ludidsfsdfdfsdf234343", min: 8, max: 10, err: fmt.Errorf("error value")},
{name: "invalid len parameter", value: "ludin", min: 11, max: 10, err: fmt.Errorf("error value")},
{name: "empty rune", value: "", min: 11, max: 10, err: fmt.Errorf("error value")},
}
for _, tt := range tc {
t.Run(tt.name, func(t *testing.T) {
ok, err := RuneLength(tt.value, tt.min, tt.max)
if tt.err != nil {
if err == nil && ok {
t.Errorf("error expect %v, got %v\n", tt.err, err)
}
}
})
}
}
func TestLength(t *testing.T) {
tc := []struct {
name string
value int
min int
max int
err error
}{
{name: "valid length", value: 123, min: 2, max: 10},
{name: "invalid length min", value: 123, min: 8, max: 10, err: fmt.Errorf("error value")},
{name: "invalid length max", value: 123234342342343, min: 8, max: 10, err: fmt.Errorf("error value")},
{name: "invalid len parameter", value: 1234, min: 11, max: 10, err: fmt.Errorf("error value")},
{name: "empty length", min: 3, max: 10, err: fmt.Errorf("error value")},
}
for _, tt := range tc {
t.Run(tt.name, func(t *testing.T) {
ok, err := Length(tt.value, tt.min, tt.max)
if tt.err != nil {
if err == nil && ok {
t.Errorf("error expect %v, got %v\n", tt.err, err)
}
}
})
}
}