OSDN Git Service

2011-12-06 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / libgo / go / url / url_test.go
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.
4
5 package url
6
7 import (
8         "fmt"
9         "reflect"
10         "testing"
11 )
12
13 type URLTest struct {
14         in        string
15         out       *URL
16         roundtrip string // expected result of reserializing the URL; empty means same as "in".
17 }
18
19 var urltests = []URLTest{
20         // no path
21         {
22                 "http://www.google.com",
23                 &URL{
24                         Raw:          "http://www.google.com",
25                         Scheme:       "http",
26                         RawAuthority: "www.google.com",
27                         Host:         "www.google.com",
28                 },
29                 "",
30         },
31         // path
32         {
33                 "http://www.google.com/",
34                 &URL{
35                         Raw:          "http://www.google.com/",
36                         Scheme:       "http",
37                         RawAuthority: "www.google.com",
38                         Host:         "www.google.com",
39                         RawPath:      "/",
40                         Path:         "/",
41                 },
42                 "",
43         },
44         // path with hex escaping
45         {
46                 "http://www.google.com/file%20one%26two",
47                 &URL{
48                         Raw:          "http://www.google.com/file%20one%26two",
49                         Scheme:       "http",
50                         RawAuthority: "www.google.com",
51                         Host:         "www.google.com",
52                         RawPath:      "/file%20one%26two",
53                         Path:         "/file one&two",
54                 },
55                 "http://www.google.com/file%20one&two",
56         },
57         // user
58         {
59                 "ftp://webmaster@www.google.com/",
60                 &URL{
61                         Raw:          "ftp://webmaster@www.google.com/",
62                         Scheme:       "ftp",
63                         RawAuthority: "webmaster@www.google.com",
64                         RawUserinfo:  "webmaster",
65                         Host:         "www.google.com",
66                         RawPath:      "/",
67                         Path:         "/",
68                 },
69                 "",
70         },
71         // escape sequence in username
72         {
73                 "ftp://john%20doe@www.google.com/",
74                 &URL{
75                         Raw:          "ftp://john%20doe@www.google.com/",
76                         Scheme:       "ftp",
77                         RawAuthority: "john%20doe@www.google.com",
78                         RawUserinfo:  "john%20doe",
79                         Host:         "www.google.com",
80                         RawPath:      "/",
81                         Path:         "/",
82                 },
83                 "ftp://john%20doe@www.google.com/",
84         },
85         // query
86         {
87                 "http://www.google.com/?q=go+language",
88                 &URL{
89                         Raw:          "http://www.google.com/?q=go+language",
90                         Scheme:       "http",
91                         RawAuthority: "www.google.com",
92                         Host:         "www.google.com",
93                         RawPath:      "/?q=go+language",
94                         Path:         "/",
95                         RawQuery:     "q=go+language",
96                 },
97                 "",
98         },
99         // query with hex escaping: NOT parsed
100         {
101                 "http://www.google.com/?q=go%20language",
102                 &URL{
103                         Raw:          "http://www.google.com/?q=go%20language",
104                         Scheme:       "http",
105                         RawAuthority: "www.google.com",
106                         Host:         "www.google.com",
107                         RawPath:      "/?q=go%20language",
108                         Path:         "/",
109                         RawQuery:     "q=go%20language",
110                 },
111                 "",
112         },
113         // %20 outside query
114         {
115                 "http://www.google.com/a%20b?q=c+d",
116                 &URL{
117                         Raw:          "http://www.google.com/a%20b?q=c+d",
118                         Scheme:       "http",
119                         RawAuthority: "www.google.com",
120                         Host:         "www.google.com",
121                         RawPath:      "/a%20b?q=c+d",
122                         Path:         "/a b",
123                         RawQuery:     "q=c+d",
124                 },
125                 "",
126         },
127         // path without leading /, so no query parsing
128         {
129                 "http:www.google.com/?q=go+language",
130                 &URL{
131                         Raw:        "http:www.google.com/?q=go+language",
132                         Scheme:     "http",
133                         RawPath:    "www.google.com/?q=go+language",
134                         Path:       "www.google.com/?q=go+language",
135                         OpaquePath: true,
136                 },
137                 "http:www.google.com/?q=go+language",
138         },
139         // path without leading /, so no query parsing
140         {
141                 "http:%2f%2fwww.google.com/?q=go+language",
142                 &URL{
143                         Raw:        "http:%2f%2fwww.google.com/?q=go+language",
144                         Scheme:     "http",
145                         RawPath:    "%2f%2fwww.google.com/?q=go+language",
146                         Path:       "//www.google.com/?q=go+language",
147                         OpaquePath: true,
148                 },
149                 "http:%2f/www.google.com/?q=go+language",
150         },
151         // non-authority
152         {
153                 "mailto:/webmaster@golang.org",
154                 &URL{
155                         Raw:     "mailto:/webmaster@golang.org",
156                         Scheme:  "mailto",
157                         RawPath: "/webmaster@golang.org",
158                         Path:    "/webmaster@golang.org",
159                 },
160                 "",
161         },
162         // non-authority
163         {
164                 "mailto:webmaster@golang.org",
165                 &URL{
166                         Raw:        "mailto:webmaster@golang.org",
167                         Scheme:     "mailto",
168                         RawPath:    "webmaster@golang.org",
169                         Path:       "webmaster@golang.org",
170                         OpaquePath: true,
171                 },
172                 "",
173         },
174         // unescaped :// in query should not create a scheme
175         {
176                 "/foo?query=http://bad",
177                 &URL{
178                         Raw:      "/foo?query=http://bad",
179                         RawPath:  "/foo?query=http://bad",
180                         Path:     "/foo",
181                         RawQuery: "query=http://bad",
182                 },
183                 "",
184         },
185         // leading // without scheme should create an authority
186         {
187                 "//foo",
188                 &URL{
189                         RawAuthority: "foo",
190                         Raw:          "//foo",
191                         Host:         "foo",
192                         Scheme:       "",
193                         RawPath:      "",
194                         Path:         "",
195                 },
196                 "",
197         },
198         // leading // without scheme, with userinfo, path, and query
199         {
200                 "//user@foo/path?a=b",
201                 &URL{
202                         Raw:          "//user@foo/path?a=b",
203                         RawAuthority: "user@foo",
204                         RawUserinfo:  "user",
205                         Scheme:       "",
206                         RawPath:      "/path?a=b",
207                         Path:         "/path",
208                         RawQuery:     "a=b",
209                         Host:         "foo",
210                 },
211                 "",
212         },
213         // Three leading slashes isn't an authority, but doesn't return an error.
214         // (We can't return an error, as this code is also used via
215         // ServeHTTP -> ReadRequest -> Parse, which is arguably a
216         // different URL parsing context, but currently shares the
217         // same codepath)
218         {
219                 "///threeslashes",
220                 &URL{
221                         RawAuthority: "",
222                         Raw:          "///threeslashes",
223                         Host:         "",
224                         Scheme:       "",
225                         RawPath:      "///threeslashes",
226                         Path:         "///threeslashes",
227                 },
228                 "",
229         },
230         {
231                 "http://user:password@google.com",
232                 &URL{
233                         Raw:          "http://user:password@google.com",
234                         Scheme:       "http",
235                         RawAuthority: "user:password@google.com",
236                         RawUserinfo:  "user:password",
237                         Host:         "google.com",
238                 },
239                 "http://user:******@google.com",
240         },
241         {
242                 "http://user:longerpass@google.com",
243                 &URL{
244                         Raw:          "http://user:longerpass@google.com",
245                         Scheme:       "http",
246                         RawAuthority: "user:longerpass@google.com",
247                         RawUserinfo:  "user:longerpass",
248                         Host:         "google.com",
249                 },
250                 "http://user:******@google.com",
251         },
252 }
253
254 var urlnofragtests = []URLTest{
255         {
256                 "http://www.google.com/?q=go+language#foo",
257                 &URL{
258                         Raw:          "http://www.google.com/?q=go+language#foo",
259                         Scheme:       "http",
260                         RawAuthority: "www.google.com",
261                         Host:         "www.google.com",
262                         RawPath:      "/?q=go+language#foo",
263                         Path:         "/",
264                         RawQuery:     "q=go+language#foo",
265                 },
266                 "",
267         },
268 }
269
270 var urlfragtests = []URLTest{
271         {
272                 "http://www.google.com/?q=go+language#foo",
273                 &URL{
274                         Raw:          "http://www.google.com/?q=go+language#foo",
275                         Scheme:       "http",
276                         RawAuthority: "www.google.com",
277                         Host:         "www.google.com",
278                         RawPath:      "/?q=go+language#foo",
279                         Path:         "/",
280                         RawQuery:     "q=go+language",
281                         Fragment:     "foo",
282                 },
283                 "",
284         },
285         {
286                 "http://www.google.com/?q=go+language#foo%26bar",
287                 &URL{
288                         Raw:          "http://www.google.com/?q=go+language#foo%26bar",
289                         Scheme:       "http",
290                         RawAuthority: "www.google.com",
291                         Host:         "www.google.com",
292                         RawPath:      "/?q=go+language#foo%26bar",
293                         Path:         "/",
294                         RawQuery:     "q=go+language",
295                         Fragment:     "foo&bar",
296                 },
297                 "http://www.google.com/?q=go+language#foo&bar",
298         },
299 }
300
301 // more useful string for debugging than fmt's struct printer
302 func ufmt(u *URL) string {
303         return fmt.Sprintf("raw=%q, scheme=%q, rawpath=%q, auth=%q, userinfo=%q, host=%q, path=%q, rawq=%q, frag=%q",
304                 u.Raw, u.Scheme, u.RawPath, u.RawAuthority, u.RawUserinfo,
305                 u.Host, u.Path, u.RawQuery, u.Fragment)
306 }
307
308 func DoTest(t *testing.T, parse func(string) (*URL, error), name string, tests []URLTest) {
309         for _, tt := range tests {
310                 u, err := parse(tt.in)
311                 if err != nil {
312                         t.Errorf("%s(%q) returned error %s", name, tt.in, err)
313                         continue
314                 }
315                 if !reflect.DeepEqual(u, tt.out) {
316                         t.Errorf("%s(%q):\n\thave %v\n\twant %v\n",
317                                 name, tt.in, ufmt(u), ufmt(tt.out))
318                 }
319         }
320 }
321
322 func TestParse(t *testing.T) {
323         DoTest(t, Parse, "Parse", urltests)
324         DoTest(t, Parse, "Parse", urlnofragtests)
325 }
326
327 func TestParseWithReference(t *testing.T) {
328         DoTest(t, ParseWithReference, "ParseWithReference", urltests)
329         DoTest(t, ParseWithReference, "ParseWithReference", urlfragtests)
330 }
331
332 const pathThatLooksSchemeRelative = "//not.a.user@not.a.host/just/a/path"
333
334 var parseRequestUrlTests = []struct {
335         url           string
336         expectedValid bool
337 }{
338         {"http://foo.com", true},
339         {"http://foo.com/", true},
340         {"http://foo.com/path", true},
341         {"/", true},
342         {pathThatLooksSchemeRelative, true},
343         {"//not.a.user@%66%6f%6f.com/just/a/path/also", true},
344         {"foo.html", false},
345         {"../dir/", false},
346 }
347
348 func TestParseRequest(t *testing.T) {
349         for _, test := range parseRequestUrlTests {
350                 _, err := ParseRequest(test.url)
351                 valid := err == nil
352                 if valid != test.expectedValid {
353                         t.Errorf("Expected valid=%v for %q; got %v", test.expectedValid, test.url, valid)
354                 }
355         }
356
357         url, err := ParseRequest(pathThatLooksSchemeRelative)
358         if err != nil {
359                 t.Fatalf("Unexpected error %v", err)
360         }
361         if url.Path != pathThatLooksSchemeRelative {
362                 t.Errorf("Expected path %q; got %q", pathThatLooksSchemeRelative, url.Path)
363         }
364 }
365
366 func DoTestString(t *testing.T, parse func(string) (*URL, error), name string, tests []URLTest) {
367         for _, tt := range tests {
368                 u, err := parse(tt.in)
369                 if err != nil {
370                         t.Errorf("%s(%q) returned error %s", name, tt.in, err)
371                         continue
372                 }
373                 s := u.String()
374                 expected := tt.in
375                 if len(tt.roundtrip) > 0 {
376                         expected = tt.roundtrip
377                 }
378                 if s != expected {
379                         t.Errorf("%s(%q).String() == %q (expected %q)", name, tt.in, s, expected)
380                 }
381         }
382 }
383
384 func TestURLString(t *testing.T) {
385         DoTestString(t, Parse, "Parse", urltests)
386         DoTestString(t, Parse, "Parse", urlnofragtests)
387         DoTestString(t, ParseWithReference, "ParseWithReference", urltests)
388         DoTestString(t, ParseWithReference, "ParseWithReference", urlfragtests)
389 }
390
391 type EscapeTest struct {
392         in  string
393         out string
394         err error
395 }
396
397 var unescapeTests = []EscapeTest{
398         {
399                 "",
400                 "",
401                 nil,
402         },
403         {
404                 "abc",
405                 "abc",
406                 nil,
407         },
408         {
409                 "1%41",
410                 "1A",
411                 nil,
412         },
413         {
414                 "1%41%42%43",
415                 "1ABC",
416                 nil,
417         },
418         {
419                 "%4a",
420                 "J",
421                 nil,
422         },
423         {
424                 "%6F",
425                 "o",
426                 nil,
427         },
428         {
429                 "%", // not enough characters after %
430                 "",
431                 EscapeError("%"),
432         },
433         {
434                 "%a", // not enough characters after %
435                 "",
436                 EscapeError("%a"),
437         },
438         {
439                 "%1", // not enough characters after %
440                 "",
441                 EscapeError("%1"),
442         },
443         {
444                 "123%45%6", // not enough characters after %
445                 "",
446                 EscapeError("%6"),
447         },
448         {
449                 "%zzzzz", // invalid hex digits
450                 "",
451                 EscapeError("%zz"),
452         },
453 }
454
455 func TestUnescape(t *testing.T) {
456         for _, tt := range unescapeTests {
457                 actual, err := QueryUnescape(tt.in)
458                 if actual != tt.out || (err != nil) != (tt.err != nil) {
459                         t.Errorf("QueryUnescape(%q) = %q, %s; want %q, %s", tt.in, actual, err, tt.out, tt.err)
460                 }
461         }
462 }
463
464 var escapeTests = []EscapeTest{
465         {
466                 "",
467                 "",
468                 nil,
469         },
470         {
471                 "abc",
472                 "abc",
473                 nil,
474         },
475         {
476                 "one two",
477                 "one+two",
478                 nil,
479         },
480         {
481                 "10%",
482                 "10%25",
483                 nil,
484         },
485         {
486                 " ?&=#+%!<>#\"{}|\\^[]`☺\t",
487                 "+%3F%26%3D%23%2B%25!%3C%3E%23%22%7B%7D%7C%5C%5E%5B%5D%60%E2%98%BA%09",
488                 nil,
489         },
490 }
491
492 func TestEscape(t *testing.T) {
493         for _, tt := range escapeTests {
494                 actual := QueryEscape(tt.in)
495                 if tt.out != actual {
496                         t.Errorf("QueryEscape(%q) = %q, want %q", tt.in, actual, tt.out)
497                 }
498
499                 // for bonus points, verify that escape:unescape is an identity.
500                 roundtrip, err := QueryUnescape(actual)
501                 if roundtrip != tt.in || err != nil {
502                         t.Errorf("QueryUnescape(%q) = %q, %s; want %q, %s", actual, roundtrip, err, tt.in, "[no error]")
503                 }
504         }
505 }
506
507 type UserinfoTest struct {
508         User     string
509         Password string
510         Raw      string
511 }
512
513 var userinfoTests = []UserinfoTest{
514         {"user", "password", "user:password"},
515         {"foo:bar", "~!@#$%^&*()_+{}|[]\\-=`:;'\"<>?,./",
516                 "foo%3Abar:~!%40%23$%25%5E&*()_+%7B%7D%7C%5B%5D%5C-=%60%3A;'%22%3C%3E?,.%2F"},
517 }
518
519 func TestEscapeUserinfo(t *testing.T) {
520         for _, tt := range userinfoTests {
521                 if raw := EscapeUserinfo(tt.User, tt.Password); raw != tt.Raw {
522                         t.Errorf("EscapeUserinfo(%q, %q) = %q, want %q", tt.User, tt.Password, raw, tt.Raw)
523                 }
524         }
525 }
526
527 func TestUnescapeUserinfo(t *testing.T) {
528         for _, tt := range userinfoTests {
529                 if user, pass, err := UnescapeUserinfo(tt.Raw); user != tt.User || pass != tt.Password || err != nil {
530                         t.Errorf("UnescapeUserinfo(%q) = %q, %q, %v, want %q, %q, nil", tt.Raw, user, pass, err, tt.User, tt.Password)
531                 }
532         }
533 }
534
535 type EncodeQueryTest struct {
536         m         Values
537         expected  string
538         expected1 string
539 }
540
541 var encodeQueryTests = []EncodeQueryTest{
542         {nil, "", ""},
543         {Values{"q": {"puppies"}, "oe": {"utf8"}}, "q=puppies&oe=utf8", "oe=utf8&q=puppies"},
544         {Values{"q": {"dogs", "&", "7"}}, "q=dogs&q=%26&q=7", "q=dogs&q=%26&q=7"},
545 }
546
547 func TestEncodeQuery(t *testing.T) {
548         for _, tt := range encodeQueryTests {
549                 if q := tt.m.Encode(); q != tt.expected && q != tt.expected1 {
550                         t.Errorf(`EncodeQuery(%+v) = %q, want %q`, tt.m, q, tt.expected)
551                 }
552         }
553 }
554
555 var resolvePathTests = []struct {
556         base, ref, expected string
557 }{
558         {"a/b", ".", "a/"},
559         {"a/b", "c", "a/c"},
560         {"a/b", "..", ""},
561         {"a/", "..", ""},
562         {"a/", "../..", ""},
563         {"a/b/c", "..", "a/"},
564         {"a/b/c", "../d", "a/d"},
565         {"a/b/c", ".././d", "a/d"},
566         {"a/b", "./..", ""},
567         {"a/./b", ".", "a/./"},
568         {"a/../", ".", "a/../"},
569         {"a/.././b", "c", "a/.././c"},
570 }
571
572 func TestResolvePath(t *testing.T) {
573         for _, test := range resolvePathTests {
574                 got := resolvePath(test.base, test.ref)
575                 if got != test.expected {
576                         t.Errorf("For %q + %q got %q; expected %q", test.base, test.ref, got, test.expected)
577                 }
578         }
579 }
580
581 var resolveReferenceTests = []struct {
582         base, rel, expected string
583 }{
584         // Absolute URL references
585         {"http://foo.com?a=b", "https://bar.com/", "https://bar.com/"},
586         {"http://foo.com/", "https://bar.com/?a=b", "https://bar.com/?a=b"},
587         {"http://foo.com/bar", "mailto:foo@example.com", "mailto:foo@example.com"},
588
589         // Path-absolute references
590         {"http://foo.com/bar", "/baz", "http://foo.com/baz"},
591         {"http://foo.com/bar?a=b#f", "/baz", "http://foo.com/baz"},
592         {"http://foo.com/bar?a=b", "/baz?c=d", "http://foo.com/baz?c=d"},
593
594         // Scheme-relative
595         {"https://foo.com/bar?a=b", "//bar.com/quux", "https://bar.com/quux"},
596
597         // Path-relative references:
598
599         // ... current directory
600         {"http://foo.com", ".", "http://foo.com/"},
601         {"http://foo.com/bar", ".", "http://foo.com/"},
602         {"http://foo.com/bar/", ".", "http://foo.com/bar/"},
603
604         // ... going down
605         {"http://foo.com", "bar", "http://foo.com/bar"},
606         {"http://foo.com/", "bar", "http://foo.com/bar"},
607         {"http://foo.com/bar/baz", "quux", "http://foo.com/bar/quux"},
608
609         // ... going up
610         {"http://foo.com/bar/baz", "../quux", "http://foo.com/quux"},
611         {"http://foo.com/bar/baz", "../../../../../quux", "http://foo.com/quux"},
612         {"http://foo.com/bar", "..", "http://foo.com/"},
613         {"http://foo.com/bar/baz", "./..", "http://foo.com/"},
614
615         // "." and ".." in the base aren't special
616         {"http://foo.com/dot/./dotdot/../foo/bar", "../baz", "http://foo.com/dot/./dotdot/../baz"},
617
618         // Triple dot isn't special
619         {"http://foo.com/bar", "...", "http://foo.com/..."},
620
621         // Fragment
622         {"http://foo.com/bar", ".#frag", "http://foo.com/#frag"},
623 }
624
625 func TestResolveReference(t *testing.T) {
626         mustParse := func(url string) *URL {
627                 u, err := ParseWithReference(url)
628                 if err != nil {
629                         t.Fatalf("Expected URL to parse: %q, got error: %v", url, err)
630                 }
631                 return u
632         }
633         for _, test := range resolveReferenceTests {
634                 base := mustParse(test.base)
635                 rel := mustParse(test.rel)
636                 url := base.ResolveReference(rel)
637                 urlStr := url.String()
638                 if urlStr != test.expected {
639                         t.Errorf("Resolving %q + %q != %q; got %q", test.base, test.rel, test.expected, urlStr)
640                 }
641         }
642
643         // Test that new instances are returned.
644         base := mustParse("http://foo.com/")
645         abs := base.ResolveReference(mustParse("."))
646         if base == abs {
647                 t.Errorf("Expected no-op reference to return new URL instance.")
648         }
649         barRef := mustParse("http://bar.com/")
650         abs = base.ResolveReference(barRef)
651         if abs == barRef {
652                 t.Errorf("Expected resolution of absolute reference to return new URL instance.")
653         }
654
655         // Test the convenience wrapper too
656         base = mustParse("http://foo.com/path/one/")
657         abs, _ = base.Parse("../two")
658         expected := "http://foo.com/path/two"
659         if abs.String() != expected {
660                 t.Errorf("Parse wrapper got %q; expected %q", abs.String(), expected)
661         }
662         _, err := base.Parse("")
663         if err == nil {
664                 t.Errorf("Expected an error from Parse wrapper parsing an empty string.")
665         }
666
667 }
668
669 func TestQueryValues(t *testing.T) {
670         u, _ := Parse("http://x.com?foo=bar&bar=1&bar=2")
671         v := u.Query()
672         if len(v) != 2 {
673                 t.Errorf("got %d keys in Query values, want 2", len(v))
674         }
675         if g, e := v.Get("foo"), "bar"; g != e {
676                 t.Errorf("Get(foo) = %q, want %q", g, e)
677         }
678         // Case sensitive:
679         if g, e := v.Get("Foo"), ""; g != e {
680                 t.Errorf("Get(Foo) = %q, want %q", g, e)
681         }
682         if g, e := v.Get("bar"), "1"; g != e {
683                 t.Errorf("Get(bar) = %q, want %q", g, e)
684         }
685         if g, e := v.Get("baz"), ""; g != e {
686                 t.Errorf("Get(baz) = %q, want %q", g, e)
687         }
688         v.Del("bar")
689         if g, e := v.Get("bar"), ""; g != e {
690                 t.Errorf("second Get(bar) = %q, want %q", g, e)
691         }
692 }
693
694 type parseTest struct {
695         query string
696         out   Values
697 }
698
699 var parseTests = []parseTest{
700         {
701                 query: "a=1&b=2",
702                 out:   Values{"a": []string{"1"}, "b": []string{"2"}},
703         },
704         {
705                 query: "a=1&a=2&a=banana",
706                 out:   Values{"a": []string{"1", "2", "banana"}},
707         },
708         {
709                 query: "ascii=%3Ckey%3A+0x90%3E",
710                 out:   Values{"ascii": []string{"<key: 0x90>"}},
711         },
712         {
713                 query: "a=1;b=2",
714                 out:   Values{"a": []string{"1"}, "b": []string{"2"}},
715         },
716         {
717                 query: "a=1&a=2;a=banana",
718                 out:   Values{"a": []string{"1", "2", "banana"}},
719         },
720 }
721
722 func TestParseQuery(t *testing.T) {
723         for i, test := range parseTests {
724                 form, err := ParseQuery(test.query)
725                 if err != nil {
726                         t.Errorf("test %d: Unexpected error: %v", i, err)
727                         continue
728                 }
729                 if len(form) != len(test.out) {
730                         t.Errorf("test %d: len(form) = %d, want %d", i, len(form), len(test.out))
731                 }
732                 for k, evs := range test.out {
733                         vs, ok := form[k]
734                         if !ok {
735                                 t.Errorf("test %d: Missing key %q", i, k)
736                                 continue
737                         }
738                         if len(vs) != len(evs) {
739                                 t.Errorf("test %d: len(form[%q]) = %d, want %d", i, k, len(vs), len(evs))
740                                 continue
741                         }
742                         for j, ev := range evs {
743                                 if v := vs[j]; v != ev {
744                                         t.Errorf("test %d: form[%q][%d] = %q, want %q", i, k, j, v, ev)
745                                 }
746                         }
747                 }
748         }
749 }