@@ -16,8 +16,8 @@ import (
16
16
)
17
17
18
18
// test that Values(input) matches want. If not, report an error on t.
19
- func testValue (t * testing.T , input interface {}, want url.Values ) {
20
- v , err := Values (input )
19
+ func testValue (t * testing.T , userTag string , input interface {}, want url.Values ) {
20
+ v , err := Values (userTag , input )
21
21
if err != nil {
22
22
t .Errorf ("Values(%q) returned error: %v" , input , err )
23
23
}
@@ -28,31 +28,34 @@ func testValue(t *testing.T, input interface{}, want url.Values) {
28
28
29
29
func TestValues_BasicTypes (t * testing.T ) {
30
30
tests := []struct {
31
+ myTag string
31
32
input interface {}
32
33
want url.Values
33
34
}{
34
35
// zero values
35
- {struct { V string }{}, url.Values {"V" : {"" }}},
36
- {struct { V int }{}, url.Values {"V" : {"0" }}},
37
- {struct { V uint }{}, url.Values {"V" : {"0" }}},
38
- {struct { V float32 }{}, url.Values {"V" : {"0" }}},
39
- {struct { V bool }{}, url.Values {"V" : {"false" }}},
36
+ {"userTag" , struct { V string }{}, url.Values {"V" : {"" }}},
37
+ {"userTag" , struct { V int }{}, url.Values {"V" : {"0" }}},
38
+ {"userTag" , struct { V uint }{}, url.Values {"V" : {"0" }}},
39
+ {"userTag" , struct { V float32 }{}, url.Values {"V" : {"0" }}},
40
+ {"userTag" , struct { V bool }{}, url.Values {"V" : {"false" }}},
40
41
41
42
// simple non-zero values
42
- {struct { V string }{"v" }, url.Values {"V" : {"v" }}},
43
- {struct { V int }{1 }, url.Values {"V" : {"1" }}},
44
- {struct { V uint }{1 }, url.Values {"V" : {"1" }}},
45
- {struct { V float32 }{0.1 }, url.Values {"V" : {"0.1" }}},
46
- {struct { V bool }{true }, url.Values {"V" : {"true" }}},
43
+ {"userTag" , struct { V string }{"v" }, url.Values {"V" : {"v" }}},
44
+ {"userTag" , struct { V int }{1 }, url.Values {"V" : {"1" }}},
45
+ {"userTag" , struct { V uint }{1 }, url.Values {"V" : {"1" }}},
46
+ {"userTag" , struct { V float32 }{0.1 }, url.Values {"V" : {"0.1" }}},
47
+ {"userTag" , struct { V bool }{true }, url.Values {"V" : {"true" }}},
47
48
48
49
// bool-specific options
49
50
{
51
+ "url" ,
50
52
struct {
51
53
V bool `url:",int"`
52
54
}{false },
53
55
url.Values {"V" : {"0" }},
54
56
},
55
57
{
58
+ "url" ,
56
59
struct {
57
60
V bool `url:",int"`
58
61
}{true },
@@ -61,30 +64,35 @@ func TestValues_BasicTypes(t *testing.T) {
61
64
62
65
// time values
63
66
{
67
+ "" ,
64
68
struct {
65
69
V time.Time
66
70
}{time .Date (2000 , 1 , 1 , 12 , 34 , 56 , 0 , time .UTC )},
67
71
url.Values {"V" : {"2000-01-01T12:34:56Z" }},
68
72
},
69
73
{
74
+ "url" ,
70
75
struct {
71
76
V time.Time `url:",unix"`
72
77
}{time .Date (2000 , 1 , 1 , 12 , 34 , 56 , 0 , time .UTC )},
73
78
url.Values {"V" : {"946730096" }},
74
79
},
75
80
{
81
+ "url" ,
76
82
struct {
77
83
V time.Time `url:",unixmilli"`
78
84
}{time .Date (2000 , 1 , 1 , 12 , 34 , 56 , 0 , time .UTC )},
79
85
url.Values {"V" : {"946730096000" }},
80
86
},
81
87
{
88
+ "url" ,
82
89
struct {
83
90
V time.Time `url:",unixnano"`
84
91
}{time .Date (2000 , 1 , 1 , 12 , 34 , 56 , 0 , time .UTC )},
85
92
url.Values {"V" : {"946730096000000000" }},
86
93
},
87
94
{
95
+ "url" ,
88
96
struct {
89
97
V time.Time `layout:"2006-01-02"`
90
98
}{time .Date (2000 , 1 , 1 , 12 , 34 , 56 , 0 , time .UTC )},
@@ -93,7 +101,7 @@ func TestValues_BasicTypes(t *testing.T) {
93
101
}
94
102
95
103
for _ , tt := range tests {
96
- testValue (t , tt .input , tt .want )
104
+ testValue (t , tt .myTag , tt . input , tt .want )
97
105
}
98
106
}
99
107
@@ -129,7 +137,7 @@ func TestValues_Pointers(t *testing.T) {
129
137
}
130
138
131
139
for _ , tt := range tests {
132
- testValue (t , tt .input , tt .want )
140
+ testValue (t , "url" , tt .input , tt .want )
133
141
}
134
142
}
135
143
@@ -268,7 +276,7 @@ func TestValues_Slices(t *testing.T) {
268
276
}
269
277
270
278
for _ , tt := range tests {
271
- testValue (t , tt .input , tt .want )
279
+ testValue (t , "url" , tt .input , tt .want )
272
280
}
273
281
}
274
282
@@ -325,7 +333,7 @@ func TestValues_NestedTypes(t *testing.T) {
325
333
}
326
334
327
335
for _ , tt := range tests {
328
- testValue (t , tt .input , tt .want )
336
+ testValue (t , "url" , tt .input , tt .want )
329
337
}
330
338
}
331
339
@@ -365,7 +373,7 @@ func TestValues_OmitEmpty(t *testing.T) {
365
373
}
366
374
367
375
for _ , tt := range tests {
368
- testValue (t , tt .input , tt .want )
376
+ testValue (t , "url" , tt .input , tt .want )
369
377
}
370
378
}
371
379
@@ -420,12 +428,12 @@ func TestValues_EmbeddedStructs(t *testing.T) {
420
428
}
421
429
422
430
for _ , tt := range tests {
423
- testValue (t , tt .input , tt .want )
431
+ testValue (t , "url" , tt .input , tt .want )
424
432
}
425
433
}
426
434
427
435
func TestValues_InvalidInput (t * testing.T ) {
428
- _ , err := Values ("" )
436
+ _ , err := Values ("" , "" )
429
437
if err == nil {
430
438
t .Errorf ("expected Values() to return an error on invalid input" )
431
439
}
@@ -480,7 +488,7 @@ func TestValues_CustomEncodingSlice(t *testing.T) {
480
488
}
481
489
482
490
for _ , tt := range tests {
483
- testValue (t , tt .input , tt .want )
491
+ testValue (t , "" , tt .input , tt .want )
484
492
}
485
493
}
486
494
@@ -504,7 +512,7 @@ func TestValues_CustomEncoding_Error(t *testing.T) {
504
512
},
505
513
}
506
514
for _ , tt := range tests {
507
- _ , err := Values (tt .input )
515
+ _ , err := Values ("" , tt .input )
508
516
if err == nil {
509
517
t .Errorf ("Values(%q) did not return expected encoding error" , tt .input )
510
518
}
@@ -574,7 +582,7 @@ func TestValues_CustomEncodingInt(t *testing.T) {
574
582
}
575
583
576
584
for _ , tt := range tests {
577
- testValue (t , tt .input , tt .want )
585
+ testValue (t , "" , tt .input , tt .want )
578
586
}
579
587
}
580
588
@@ -657,7 +665,7 @@ func TestValues_CustomEncodingPointer(t *testing.T) {
657
665
}
658
666
659
667
for _ , tt := range tests {
660
- testValue (t , tt .input , tt .want )
668
+ testValue (t , "" , tt .input , tt .want )
661
669
}
662
670
}
663
671
0 commit comments