@@ -96,7 +96,9 @@ type mediaTypeTest struct {
9696 p map [string ]string
9797}
9898
99- func TestParseMediaType (t * testing.T ) {
99+ var parseMediaTypeTests []mediaTypeTest
100+
101+ func init () {
100102 // Convenience map initializer
101103 m := func (s ... string ) map [string ]string {
102104 sm := make (map [string ]string )
@@ -107,7 +109,7 @@ func TestParseMediaType(t *testing.T) {
107109 }
108110
109111 nameFoo := map [string ]string {"name" : "foo" }
110- tests : = []mediaTypeTest {
112+ parseMediaTypeTests = []mediaTypeTest {
111113 {`form-data; name="foo"` , "form-data" , nameFoo },
112114 {` form-data ; name=foo` , "form-data" , nameFoo },
113115 {`FORM-DATA;name="foo"` , "form-data" , nameFoo },
@@ -412,7 +414,10 @@ func TestParseMediaType(t *testing.T) {
412414 {`text; charset=utf-8; charset=utf-8; format=fixed` , "text" , m ("charset" , "utf-8" , "format" , "fixed" )},
413415 {`text; charset=utf-8; format=flowed; charset=utf-8` , "text" , m ("charset" , "utf-8" , "format" , "flowed" )},
414416 }
415- for _ , test := range tests {
417+ }
418+
419+ func TestParseMediaType (t * testing.T ) {
420+ for _ , test := range parseMediaTypeTests {
416421 mt , params , err := ParseMediaType (test .in )
417422 if err != nil {
418423 if test .t != "" {
@@ -438,6 +443,14 @@ func TestParseMediaType(t *testing.T) {
438443 }
439444}
440445
446+ func BenchmarkParseMediaType (b * testing.B ) {
447+ for range b .N {
448+ for _ , test := range parseMediaTypeTests {
449+ ParseMediaType (test .in )
450+ }
451+ }
452+ }
453+
441454type badMediaTypeTest struct {
442455 in string
443456 mt string
@@ -486,6 +499,14 @@ func TestParseMediaTypeBogus(t *testing.T) {
486499 }
487500}
488501
502+ func BenchmarkParseMediaTypeBogus (b * testing.B ) {
503+ for range b .N {
504+ for _ , test := range badMediaTypeTests {
505+ ParseMediaType (test .in )
506+ }
507+ }
508+ }
509+
489510type formatTest struct {
490511 typ string
491512 params map [string ]string
0 commit comments