-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser_test.go
70 lines (66 loc) · 1.09 KB
/
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package validator
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseValidateTags(t *testing.T) {
tests := []struct {
input string
want []ValidateTag
}{
{
input: "",
want: []ValidateTag{},
},
{
input: "optional",
want: []ValidateTag{
{
Op: "optional",
Args: []interface{}{},
},
},
},
{
input: "gt(-10),lt(10)",
want: []ValidateTag{
{
Op: "gt",
Args: []interface{}{"-10"},
},
{
Op: "lt",
Args: []interface{}{"10"},
},
},
},
{
input: "oneOf(foo, bar, baz)",
want: []ValidateTag{
{
Op: "oneOf",
Args: []interface{}{"foo", "bar", "baz"},
},
},
},
{
input: "foo1(+1, -2, 6.02e+23),foo_bar(this, that)",
want: []ValidateTag{
{
Op: "foo1",
Args: []interface{}{"+1", "-2", "6.02e+23"},
},
{
Op: "foo_bar",
Args: []interface{}{"this", "that"},
},
},
},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
tags := parseValidateTags(tt.input)
assert.Equal(t, tt.want, tags)
})
}
}