OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [net/] [url/] [url_test.go] - Blame information for rev 747

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.