@@ -8,6 +8,13 @@ import (
88func Test_fetchTagKey (t * testing.T ) {
99 t .Parallel ()
1010
11+ registredTags := map [string ]struct {}{
12+ "json" : {},
13+ "xml" : {},
14+ "flag" : {},
15+ "default" : {},
16+ }
17+
1118 tests := []struct {
1219 name string
1320 in reflect.StructTag
@@ -27,9 +34,9 @@ func Test_fetchTagKey(t *testing.T) {
2734 },
2835 {
2936 name : "non-empty tag value" ,
30- in : reflect .StructTag (`json:"id "` ),
37+ in : reflect .StructTag (`default:"one;two "` ),
3138 want : map [string ]struct {}{
32- "json " : {},
39+ "default " : {},
3340 },
3441 },
3542 {
@@ -40,14 +47,35 @@ func Test_fetchTagKey(t *testing.T) {
4047 "xml" : {},
4148 },
4249 },
50+ {
51+ name : "malformed tag" ,
52+ in : reflect .StructTag (`json` ),
53+ want : map [string ]struct {}{},
54+ },
55+ {
56+ name : "tag with spaces in value" ,
57+ in : reflect .StructTag (`flag:"name_flag||Some description" json:"id" xml:"ID"` ),
58+ want : map [string ]struct {}{
59+ "flag" : {},
60+ "json" : {},
61+ "xml" : {},
62+ },
63+ },
64+ {
65+ name : "special characters in tag value" ,
66+ in : reflect .StructTag (`default:"one;two-three_1,/ and this!=2*7&^3:,. $"` ),
67+ want : map [string ]struct {}{
68+ "default" : {},
69+ },
70+ },
4371 }
4472 for _ , tt := range tests {
4573 tt := tt
4674
4775 t .Run (tt .name , func (t * testing.T ) {
4876 t .Parallel ()
4977
50- assert (t , tt .want , fetchTagKey (tt .in ))
78+ assert (t , tt .want , fetchTagKey (tt .in , registredTags ))
5179 })
5280 }
5381}
0 commit comments