-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser_test.go
54 lines (51 loc) · 890 Bytes
/
parser_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
package govalid
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_parseRules(t *testing.T) {
for _, tc := range []struct {
name string
rule string
want []*rule
}{
{
name: "single rule",
rule: "max:5",
want: []*rule{
{checker: "max", params: []string{"5"}},
},
},
{
name: "multiple rule",
rule: "required;max:5;min:0",
want: []*rule{
{checker: "required"},
{checker: "max", params: []string{"5"}},
{checker: "min", params: []string{"0"}},
},
},
{
name: "no value",
rule: "required:",
want: []*rule{
{checker: "required", params: []string{""}},
},
},
{
name: "nothing",
rule: "::::",
want: []*rule{},
},
{
name: "empty",
rule: "",
want: []*rule{},
},
} {
t.Run(tc.name, func(t *testing.T) {
got := parseRules(tc.rule)
assert.Equal(t, tc.want, got)
})
}
}