1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
11 func isChar(c rune) bool { return c <= 127 }
13 func isCtl(c rune) bool { return c <= 31 || c == 127 }
15 func isSeparator(c rune) bool {
17 case '(', ')', '<', '>', '@', ',', ';', ':', '\\', '"', '/', '[', ']', '?', '=', '{', '}', ' ', '\t':
23 func TestIsToken(t *testing.T) {
24 for i := 0; i <= 130; i++ {
26 expected := isChar(r) && !isCtl(r) && !isSeparator(r)
27 if IsTokenRune(r) != expected {
28 t.Errorf("isToken(0x%x) = %v", r, !expected)
33 func TestHeaderValuesContainsToken(t *testing.T) {
40 vals: []string{"foo"},
45 vals: []string{"bar", "foo"},
50 vals: []string{"foo"},
55 vals: []string{"foo"},
60 vals: []string{" foo "},
65 vals: []string{"foo,bar"},
70 vals: []string{"bar,foo,bar"},
75 vals: []string{"bar , foo"},
80 vals: []string{"foo ,bar "},
85 vals: []string{"bar, foo ,bar"},
90 vals: []string{"bar , foo"},
95 for _, tt := range tests {
96 got := HeaderValuesContainsToken(tt.vals, tt.token)
98 t.Errorf("headerValuesContainsToken(%q, %q) = %v; want %v", tt.vals, tt.token, got, tt.want)
103 func TestPunycodeHostPort(t *testing.T) {
107 {"www.google.com", "www.google.com"},
108 {"гофер.рф", "xn--c1ae0ajs.xn--p1ai"},
109 {"bücher.de", "xn--bcher-kva.de"},
110 {"bücher.de:8080", "xn--bcher-kva.de:8080"},
111 {"[1::6]:8080", "[1::6]:8080"},
113 for _, tt := range tests {
114 got, err := PunycodeHostPort(tt.in)
115 if tt.want != got || err != nil {
116 t.Errorf("PunycodeHostPort(%q) = %q, %v, want %q, nil", tt.in, got, err, tt.want)