@@ -96,7 +96,9 @@ type mediaTypeTest struct {
96
96
p map [string ]string
97
97
}
98
98
99
- func TestParseMediaType (t * testing.T ) {
99
+ var parseMediaTypeTests []mediaTypeTest
100
+
101
+ func init () {
100
102
// Convenience map initializer
101
103
m := func (s ... string ) map [string ]string {
102
104
sm := make (map [string ]string )
@@ -107,7 +109,7 @@ func TestParseMediaType(t *testing.T) {
107
109
}
108
110
109
111
nameFoo := map [string ]string {"name" : "foo" }
110
- tests : = []mediaTypeTest {
112
+ parseMediaTypeTests = []mediaTypeTest {
111
113
{`form-data; name="foo"` , "form-data" , nameFoo },
112
114
{` form-data ; name=foo` , "form-data" , nameFoo },
113
115
{`FORM-DATA;name="foo"` , "form-data" , nameFoo },
@@ -412,7 +414,10 @@ func TestParseMediaType(t *testing.T) {
412
414
{`text; charset=utf-8; charset=utf-8; format=fixed` , "text" , m ("charset" , "utf-8" , "format" , "fixed" )},
413
415
{`text; charset=utf-8; format=flowed; charset=utf-8` , "text" , m ("charset" , "utf-8" , "format" , "flowed" )},
414
416
}
415
- for _ , test := range tests {
417
+ }
418
+
419
+ func TestParseMediaType (t * testing.T ) {
420
+ for _ , test := range parseMediaTypeTests {
416
421
mt , params , err := ParseMediaType (test .in )
417
422
if err != nil {
418
423
if test .t != "" {
@@ -438,6 +443,14 @@ func TestParseMediaType(t *testing.T) {
438
443
}
439
444
}
440
445
446
+ func BenchmarkParseMediaType (b * testing.B ) {
447
+ for range b .N {
448
+ for _ , test := range parseMediaTypeTests {
449
+ ParseMediaType (test .in )
450
+ }
451
+ }
452
+ }
453
+
441
454
type badMediaTypeTest struct {
442
455
in string
443
456
mt string
@@ -486,6 +499,14 @@ func TestParseMediaTypeBogus(t *testing.T) {
486
499
}
487
500
}
488
501
502
+ func BenchmarkParseMediaTypeBogus (b * testing.B ) {
503
+ for range b .N {
504
+ for _ , test := range badMediaTypeTests {
505
+ ParseMediaType (test .in )
506
+ }
507
+ }
508
+ }
509
+
489
510
type formatTest struct {
490
511
typ string
491
512
params map [string ]string
0 commit comments