| 7 | ) |
| 8 | |
| 9 | func TestBase(t *testing.T) { |
| 10 | tests := []struct { |
| 11 | in, out, err string |
| 12 | }{ |
| 13 | {"", "", ""}, |
| 14 | {"http://foo.com/x/y", "http://foo.com/x", ""}, |
| 15 | {"http://foo.com/x/y?p=q", "http://foo.com/x?p=q", ""}, |
| 16 | } |
| 17 | |
| 18 | for i, tt := range tests { |
| 19 | u, err := base(tt.in) |
| 20 | if err != nil { |
| 21 | if got, want := err.Error(), tt.err; got != want { |
| 22 | t.Errorf("%d: got %v want %v", i, got, want) |
| 23 | continue |
| 24 | } |
| 25 | } |
| 26 | if tt.err != "" { |
| 27 | t.Errorf("%d: got nil want %v", i, tt.err) |
| 28 | continue |
| 29 | } |
| 30 | if got, want := u, tt.out; got != want { |
| 31 | t.Errorf("%d: got %v want %v", i, got, want) |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | func TestReplaceSuffix(t *testing.T) { |
| 37 | if got, want := replaceSuffix("ab", "b", "c"), "ac"; got != want { |