1 // Copyright 2018 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.
9 var encodeTests = []struct {
11 enc string // empty means same as path
13 {path: "ascii.com/abcdefghijklmnopqrstuvwxyz.-+/~_0123456789"},
14 {path: "github.com/GoogleCloudPlatform/omega", enc: "github.com/!google!cloud!platform/omega"},
17 func TestEncodePath(t *testing.T) {
19 for _, tt := range encodeTests {
20 enc, err := encodePath(tt.path)
22 t.Errorf("encodePath(%q): unexpected error: %v", tt.path, err)
30 t.Errorf("encodePath(%q) = %q, want %q", tt.path, enc, want)
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",
43 func TestDecodePath(t *testing.T) {
44 // Check invalid decodings.
45 for _, bad := range badDecode {
46 _, err := decodePath(bad)
48 t.Errorf("DecodePath(%q): succeeded, want error (invalid decoding)", bad)
53 for _, tt := range encodeTests {
58 path, err := decodePath(enc)
60 t.Errorf("decodePath(%q): unexpected error: %v", enc, err)
64 t.Errorf("decodePath(%q) = %q, want %q", enc, path, tt.path)