]> git.ipfire.org Git - thirdparty/gcc.git/blob - libgo/go/cmd/go/internal/sumweb/encode_test.go
Add error check on return value of build_co_await
[thirdparty/gcc.git] / libgo / go / cmd / go / internal / sumweb / encode_test.go
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.
4
5 package sumweb
6
7 import "testing"
8
9 var encodeTests = []struct {
10 path string
11 enc string // empty means same as path
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 // Check encodings.
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 // Check invalid decodings.
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 // Check encodings.
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 }