| |
| |
| |
|
|
| package textproto |
|
|
| import "testing" |
|
|
| type canonicalHeaderKeyTest struct { |
| in, out string |
| } |
|
|
| var canonicalHeaderKeyTests = []canonicalHeaderKeyTest{ |
| {"a-b-c", "A-B-C"}, |
| {"a-1-c", "A-1-C"}, |
| {"User-Agent", "User-Agent"}, |
| {"uSER-aGENT", "User-Agent"}, |
| {"user-agent", "User-Agent"}, |
| {"USER-AGENT", "User-Agent"}, |
|
|
| |
| {"foo-bar_baz", "Foo-Bar_baz"}, |
| {"foo-bar$baz", "Foo-Bar$baz"}, |
| {"foo-bar~baz", "Foo-Bar~baz"}, |
| {"foo-bar*baz", "Foo-Bar*baz"}, |
|
|
| |
| {"üser-agenT", "üser-agenT"}, |
| {"a B", "a B"}, |
|
|
| |
| {"C Ontent-Transfer-Encoding", "C Ontent-Transfer-Encoding"}, |
| {"foo bar", "foo bar"}, |
| } |
|
|
| func TestCanonicalMIMEHeaderKey(t *testing.T) { |
| for _, tt := range canonicalHeaderKeyTests { |
| if s := CanonicalMIMEHeaderKey(tt.in); s != tt.out { |
| t.Errorf("CanonicalMIMEHeaderKey(%q) = %q, want %q", tt.in, s, tt.out) |
| } |
| } |
| } |
|
|
| |
| func TestMIMEHeaderMultipleValues(t *testing.T) { |
| testHeader := MIMEHeader{ |
| "Set-Cookie": {"cookie 1", "cookie 2"}, |
| } |
| values := testHeader.Values("set-cookie") |
| n := len(values) |
| if n != 2 { |
| t.Errorf("count: %d; want 2", n) |
| } |
| } |
|
|