LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package url | 5 package url |
6 | 6 |
7 import ( | 7 import ( |
8 "fmt" | 8 "fmt" |
9 "reflect" | 9 "reflect" |
10 "strings" | 10 "strings" |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 if len(tt.roundtrip) > 0 { | 363 if len(tt.roundtrip) > 0 { |
364 expected = tt.roundtrip | 364 expected = tt.roundtrip |
365 } | 365 } |
366 s := u.String() | 366 s := u.String() |
367 if s != expected { | 367 if s != expected { |
368 t.Errorf("%s(%q).String() == %q (expected %q)", name, tt
.in, s, expected) | 368 t.Errorf("%s(%q).String() == %q (expected %q)", name, tt
.in, s, expected) |
369 } | 369 } |
370 } | 370 } |
371 } | 371 } |
372 | 372 |
373 var stringtests = append(urltests, URLTest{ | |
374 // no slash on path should prepend slash | |
375 // on String() call | |
376 "http://www.google.com/search", | |
377 &URL{ | |
378 Scheme: "http", | |
379 Host: "www.google.com", | |
380 Path: "search", | |
381 }, | |
382 "", | |
383 }) | |
384 | |
385 func TestURLString(t *testing.T) { | 373 func TestURLString(t *testing.T) { |
386 » DoTestString(t, Parse, "Parse", stringtests) | 374 » DoTestString(t, Parse, "Parse", urltests) |
| 375 |
| 376 » // no leading slash on path should prepend |
| 377 » // slash on String() call |
| 378 » noslash := URLTest{ |
| 379 » » "http://www.google.com/search", |
| 380 » » &URL{ |
| 381 » » » Scheme: "http", |
| 382 » » » Host: "www.google.com", |
| 383 » » » Path: "search", |
| 384 » » }, |
| 385 » » "", |
| 386 » } |
| 387 » s := noslash.out.String() |
| 388 » if s != noslash.in { |
| 389 » » t.Errorf("Expected %s; go %s", noslash.in, s) |
| 390 » } |
387 } | 391 } |
388 | 392 |
389 type EscapeTest struct { | 393 type EscapeTest struct { |
390 in string | 394 in string |
391 out string | 395 out string |
392 err error | 396 err error |
393 } | 397 } |
394 | 398 |
395 var unescapeTests = []EscapeTest{ | 399 var unescapeTests = []EscapeTest{ |
396 { | 400 { |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 | 877 |
874 func TestParseFailure(t *testing.T) { | 878 func TestParseFailure(t *testing.T) { |
875 // Test that the first parse error is returned. | 879 // Test that the first parse error is returned. |
876 const url = "%gh&%ij" | 880 const url = "%gh&%ij" |
877 _, err := ParseQuery(url) | 881 _, err := ParseQuery(url) |
878 errStr := fmt.Sprint(err) | 882 errStr := fmt.Sprint(err) |
879 if !strings.Contains(errStr, "%gh") { | 883 if !strings.Contains(errStr, "%gh") { |
880 t.Errorf(`ParseQuery(%q) returned error %q, want something conta
ining %q"`, url, errStr, "%gh") | 884 t.Errorf(`ParseQuery(%q) returned error %q, want something conta
ining %q"`, url, errStr, "%gh") |
881 } | 885 } |
882 } | 886 } |
LEFT | RIGHT |