-
Notifications
You must be signed in to change notification settings - Fork 0
/
multilines_struct_tag_test.go
76 lines (71 loc) · 1.11 KB
/
multilines_struct_tag_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
package structtag
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func TestStructTagLookup(t *testing.T) {
cases := []struct {
structTag reflect.StructTag
tagName string
valid bool
expected string
}{
// Valid Tags
{
`tag1:"value1"
tag2:"value2"`,
"tag2",
true,
"value2",
},
{
`tag1:"value1"
tag2:"The value of
tag1 is value2"`,
"tag2",
true,
"The value of tag1 is value2",
},
{
`tag1:"\\"`,
"tag1",
true,
"\\",
},
// Invalid Tags
{
``,
"tag1",
false,
"",
},
{
` `,
"tag1",
false,
"",
},
{
`tag1:"`,
"tag1",
false,
"",
},
{
`tag1:a`,
"tag1",
false,
"",
},
}
for i, c := range cases {
res, ok := Lookup(c.structTag, c.tagName)
assert.Equal(t, c.valid, ok, "%d case fail: structTag is %s and tagName is %s", i, c.structTag, c.tagName)
assert.Equal(t, c.expected, res, "%d case fail: structTag is %s and tagName is %s", i, c.structTag, c.tagName)
}
}
func TestStructTagGet(t *testing.T) {
val := Get(`tag1:"value1"`, "tag1")
assert.Equal(t, "value1", val)
}