...
1
2
3
4
5 package textproto
6
7 import "testing"
8
9 type canonicalHeaderKeyTest struct {
10 in, out string
11 }
12
13 var canonicalHeaderKeyTests = []canonicalHeaderKeyTest{
14 {"a-b-c", "A-B-C"},
15 {"a-1-c", "A-1-C"},
16 {"User-Agent", "User-Agent"},
17 {"uSER-aGENT", "User-Agent"},
18 {"user-agent", "User-Agent"},
19 {"USER-AGENT", "User-Agent"},
20
21
22 {"foo-bar_baz", "Foo-Bar_baz"},
23 {"foo-bar$baz", "Foo-Bar$baz"},
24 {"foo-bar~baz", "Foo-Bar~baz"},
25 {"foo-bar*baz", "Foo-Bar*baz"},
26
27
28 {"üser-agenT", "üser-agenT"},
29 {"a B", "a B"},
30
31
32 {"C Ontent-Transfer-Encoding", "C Ontent-Transfer-Encoding"},
33 {"foo bar", "foo bar"},
34 }
35
36 func TestCanonicalMIMEHeaderKey(t *testing.T) {
37 for _, tt := range canonicalHeaderKeyTests {
38 if s := CanonicalMIMEHeaderKey(tt.in); s != tt.out {
39 t.Errorf("CanonicalMIMEHeaderKey(%q) = %q, want %q", tt.in, s, tt.out)
40 }
41 }
42 }
43
44
45 func TestMIMEHeaderMultipleValues(t *testing.T) {
46 testHeader := MIMEHeader{
47 "Set-Cookie": {"cookie 1", "cookie 2"},
48 }
49 values := testHeader.Values("set-cookie")
50 n := len(values)
51 if n != 2 {
52 t.Errorf("count: %d; want 2", n)
53 }
54 }
55
View as plain text