@@ -20,7 +20,7 @@ func isSeparator(c rune) bool {
20
20
return false
21
21
}
22
22
23
- func TestIsToken (t * testing.T ) {
23
+ func TestIsTokenRune (t * testing.T ) {
24
24
for i := 0 ; i <= 130 ; i ++ {
25
25
r := rune (i )
26
26
expected := isChar (r ) && ! isCtl (r ) && ! isSeparator (r )
@@ -30,6 +30,15 @@ func TestIsToken(t *testing.T) {
30
30
}
31
31
}
32
32
33
+ func BenchmarkIsTokenRune (b * testing.B ) {
34
+ for i := 0 ; i < b .N ; i ++ {
35
+ var r rune
36
+ for ; r < 1024 ; r ++ {
37
+ IsTokenRune (r )
38
+ }
39
+ }
40
+ }
41
+
33
42
func TestHeaderValuesContainsToken (t * testing.T ) {
34
43
tests := []struct {
35
44
vals []string
@@ -100,6 +109,44 @@ func TestHeaderValuesContainsToken(t *testing.T) {
100
109
}
101
110
}
102
111
112
+ func TestValidHeaderFieldName (t * testing.T ) {
113
+ tests := []struct {
114
+ in string
115
+ want bool
116
+ }{
117
+ {"" , false },
118
+ {"Accept Charset" , false },
119
+ {"Accept-Charset" , true },
120
+ {"AccepT-EncodinG" , true },
121
+ {"CONNECTION" , true },
122
+ {"résumé" , false },
123
+ }
124
+ for _ , tt := range tests {
125
+ got := ValidHeaderFieldName (tt .in )
126
+ if tt .want != got {
127
+ t .Errorf ("ValidHeaderFieldName(%q) = %t; want %t" , tt .in , got , tt .want )
128
+ }
129
+ }
130
+ }
131
+
132
+ func BenchmarkValidHeaderFieldName (b * testing.B ) {
133
+ names := []string {
134
+ "" ,
135
+ "Accept Charset" ,
136
+ "Accept-Charset" ,
137
+ "AccepT-EncodinG" ,
138
+ "CONNECTION" ,
139
+ "résumé" ,
140
+ }
141
+ b .ReportAllocs ()
142
+ b .ResetTimer ()
143
+ for i := 0 ; i < b .N ; i ++ {
144
+ for _ , name := range names {
145
+ ValidHeaderFieldName (name )
146
+ }
147
+ }
148
+ }
149
+
103
150
func TestPunycodeHostPort (t * testing.T ) {
104
151
tests := []struct {
105
152
in , want string
0 commit comments