Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1147)

Delta Between Two Patch Sets: src/pkg/url/url_test.go

Issue 4973062: code review 4973062: url: handle ; in ParseQuery (Closed)
Left Patch Set: Created 12 years, 6 months ago
Right Patch Set: diff -r ce2e5f44b310 https://go.googlecode.com/hg Created 12 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/url/url.go ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
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 "os" 9 "os"
10 "reflect" 10 "reflect"
11 "testing" 11 "testing"
12 ) 12 )
13
14 // TODO(rsc):
15 // test Unescape
16 // test Escape
17 // test Parse
18 13
19 type URLTest struct { 14 type URLTest struct {
20 in string 15 in string
21 out *URL 16 out *URL
22 roundtrip string // expected result of reserializing the URL; empty mean s same as "in". 17 roundtrip string // expected result of reserializing the URL; empty mean s same as "in".
23 } 18 }
24 19
25 var urltests = []URLTest{ 20 var urltests = []URLTest{
26 // no path 21 // no path
27 { 22 {
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 t.Errorf("Get(bar) = %q, want %q", g, e) 684 t.Errorf("Get(bar) = %q, want %q", g, e)
690 } 685 }
691 if g, e := v.Get("baz"), ""; g != e { 686 if g, e := v.Get("baz"), ""; g != e {
692 t.Errorf("Get(baz) = %q, want %q", g, e) 687 t.Errorf("Get(baz) = %q, want %q", g, e)
693 } 688 }
694 v.Del("bar") 689 v.Del("bar")
695 if g, e := v.Get("bar"), ""; g != e { 690 if g, e := v.Get("bar"), ""; g != e {
696 t.Errorf("second Get(bar) = %q, want %q", g, e) 691 t.Errorf("second Get(bar) = %q, want %q", g, e)
697 } 692 }
698 } 693 }
694
695 type parseTest struct {
696 query string
697 out Values
698 }
699
700 var parseTests = []parseTest{
701 {
702 query: "a=1&b=2",
703 out: Values{"a": []string{"1"}, "b": []string{"2"}},
704 },
705 {
706 query: "a=1&a=2&a=banana",
707 out: Values{"a": []string{"1", "2", "banana"}},
708 },
709 {
710 query: "ascii=%3Ckey%3A+0x90%3E",
711 out: Values{"ascii": []string{"<key: 0x90>"}},
712 },
713 {
714 query: "a=1;b=2",
715 out: Values{"a": []string{"1"}, "b": []string{"2"}},
716 },
717 {
718 query: "a=1&a=2;a=banana",
719 out: Values{"a": []string{"1", "2", "banana"}},
720 },
721 }
722
723 func TestParseQuery(t *testing.T) {
724 for i, test := range parseTests {
725 form, err := ParseQuery(test.query)
726 if err != nil {
727 t.Errorf("test %d: Unexpected error: %v", i, err)
728 continue
729 }
730 if len(form) != len(test.out) {
731 t.Errorf("test %d: len(form) = %d, want %d", i, len(form ), len(test.out))
732 }
733 for k, evs := range test.out {
734 vs, ok := form[k]
735 if !ok {
736 t.Errorf("test %d: Missing key %q", i, k)
737 continue
738 }
739 if len(vs) != len(evs) {
740 t.Errorf("test %d: len(form[%q]) = %d, want %d", i, k, len(vs), len(evs))
741 continue
742 }
743 for j, ev := range evs {
744 if v := vs[j]; v != ev {
745 t.Errorf("test %d: form[%q][%d] = %q, wa nt %q", i, k, j, v, ev)
746 }
747 }
748 }
749 }
750 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b