| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package sumweb |
| 6 |
|
| 7 |
import "testing" |
| 8 |
|
| 9 |
var encodeTests = []struct { |
| 10 |
path string |
| 11 |
enc string |
| 12 |
}{ |
| 13 |
{path: "ascii.com/abcdefghijklmnopqrstuvwxyz.-+/~_0123456789"}, |
| 14 |
{path: "github.com/GoogleCloudPlatform/omega", enc: "github.com/!google!cloud!platform/omega"}, |
| 15 |
} |
| 16 |
|
| 17 |
func TestEncodePath(t *testing.T) { |
| 18 |
|
| 19 |
for _, tt := range encodeTests { |
| 20 |
enc, err := encodePath(tt.path) |
| 21 |
if err != nil { |
| 22 |
t.Errorf("encodePath(%q): unexpected error: %v", tt.path, err) |
| 23 |
continue |
| 24 |
} |
| 25 |
want := tt.enc |
| 26 |
if want == "" { |
| 27 |
want = tt.path |
| 28 |
} |
| 29 |
if enc != want { |
| 30 |
t.Errorf("encodePath(%q) = %q, want %q", tt.path, enc, want) |
| 31 |
} |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
var badDecode = []string{ |
| 36 |
"github.com/GoogleCloudPlatform/omega", |
| 37 |
"github.com/!google!cloud!platform!/omega", |
| 38 |
"github.com/!0google!cloud!platform/omega", |
| 39 |
"github.com/!_google!cloud!platform/omega", |
| 40 |
"github.com/!!google!cloud!platform/omega", |
| 41 |
} |
| 42 |
|
| 43 |
func TestDecodePath(t *testing.T) { |
| 44 |
|
| 45 |
for _, bad := range badDecode { |
| 46 |
_, err := decodePath(bad) |
| 47 |
if err == nil { |
| 48 |
t.Errorf("DecodePath(%q): succeeded, want error (invalid decoding)", bad) |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
for _, tt := range encodeTests { |
| 54 |
enc := tt.enc |
| 55 |
if enc == "" { |
| 56 |
enc = tt.path |
| 57 |
} |
| 58 |
path, err := decodePath(enc) |
| 59 |
if err != nil { |
| 60 |
t.Errorf("decodePath(%q): unexpected error: %v", enc, err) |
| 61 |
continue |
| 62 |
} |
| 63 |
if path != tt.path { |
| 64 |
t.Errorf("decodePath(%q) = %q, want %q", enc, path, tt.path) |
| 65 |
} |
| 66 |
} |
| 67 |
} |