aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/net/url/url_test.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2019-01-18 19:04:36 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2019-01-18 19:04:36 +0000
commit4f4a855d82a889cebcfca150a7a43909bcb6a346 (patch)
treef12bae0781920fa34669fe30b6f4615a86d9fb80 /libgo/go/net/url/url_test.go
parent225220d668dafb8262db7012bced688acbe63b33 (diff)
downloadgcc-4f4a855d82a889cebcfca150a7a43909bcb6a346.zip
gcc-4f4a855d82a889cebcfca150a7a43909bcb6a346.tar.gz
gcc-4f4a855d82a889cebcfca150a7a43909bcb6a346.tar.bz2
libgo: update to Go1.12beta2
Reviewed-on: https://go-review.googlesource.com/c/158019 gotools/: * Makefile.am (go_cmd_vet_files): Update for Go1.12beta2 release. (GOTOOLS_TEST_TIMEOUT): Increase to 600. (check-runtime): Export LD_LIBRARY_PATH before computing GOARCH and GOOS. (check-vet): Copy golang.org/x/tools into check-vet-dir. * Makefile.in: Regenerate. gcc/testsuite/: * go.go-torture/execute/names-1.go: Stop using debug/xcoff, which is no longer externally visible. From-SVN: r268084
Diffstat (limited to 'libgo/go/net/url/url_test.go')
-rw-r--r--libgo/go/net/url/url_test.go109
1 files changed, 106 insertions, 3 deletions
diff --git a/libgo/go/net/url/url_test.go b/libgo/go/net/url/url_test.go
index 9043a84..7c4ada2 100644
--- a/libgo/go/net/url/url_test.go
+++ b/libgo/go/net/url/url_test.go
@@ -848,18 +848,18 @@ func TestUnescape(t *testing.T) {
in := tt.in
out := tt.out
if strings.Contains(tt.in, "+") {
- in = strings.Replace(tt.in, "+", "%20", -1)
+ in = strings.ReplaceAll(tt.in, "+", "%20")
actual, err := PathUnescape(in)
if actual != tt.out || (err != nil) != (tt.err != nil) {
t.Errorf("PathUnescape(%q) = %q, %s; want %q, %s", in, actual, err, tt.out, tt.err)
}
if tt.err == nil {
- s, err := QueryUnescape(strings.Replace(tt.in, "+", "XXX", -1))
+ s, err := QueryUnescape(strings.ReplaceAll(tt.in, "+", "XXX"))
if err != nil {
continue
}
in = tt.in
- out = strings.Replace(s, "XXX", "+", -1)
+ out = strings.ReplaceAll(s, "XXX", "+")
}
}
@@ -1743,3 +1743,106 @@ func TestInvalidUserPassword(t *testing.T) {
t.Errorf("error = %q; want substring %q", got, wantsub)
}
}
+
+var escapeBenchmarks = []struct {
+ unescaped string
+ query string
+ path string
+}{
+ {
+ unescaped: "one two",
+ query: "one+two",
+ path: "one%20two",
+ },
+ {
+ unescaped: "Фотки собак",
+ query: "%D0%A4%D0%BE%D1%82%D0%BA%D0%B8+%D1%81%D0%BE%D0%B1%D0%B0%D0%BA",
+ path: "%D0%A4%D0%BE%D1%82%D0%BA%D0%B8%20%D1%81%D0%BE%D0%B1%D0%B0%D0%BA",
+ },
+
+ {
+ unescaped: "shortrun(break)shortrun",
+ query: "shortrun%28break%29shortrun",
+ path: "shortrun%28break%29shortrun",
+ },
+
+ {
+ unescaped: "longerrunofcharacters(break)anotherlongerrunofcharacters",
+ query: "longerrunofcharacters%28break%29anotherlongerrunofcharacters",
+ path: "longerrunofcharacters%28break%29anotherlongerrunofcharacters",
+ },
+
+ {
+ unescaped: strings.Repeat("padded/with+various%characters?that=need$some@escaping+paddedsowebreak/256bytes", 4),
+ query: strings.Repeat("padded%2Fwith%2Bvarious%25characters%3Fthat%3Dneed%24some%40escaping%2Bpaddedsowebreak%2F256bytes", 4),
+ path: strings.Repeat("padded%2Fwith+various%25characters%3Fthat=need$some@escaping+paddedsowebreak%2F256bytes", 4),
+ },
+}
+
+func BenchmarkQueryEscape(b *testing.B) {
+ for _, tc := range escapeBenchmarks {
+ b.Run("", func(b *testing.B) {
+ b.ReportAllocs()
+ var g string
+ for i := 0; i < b.N; i++ {
+ g = QueryEscape(tc.unescaped)
+ }
+ b.StopTimer()
+ if g != tc.query {
+ b.Errorf("QueryEscape(%q) == %q, want %q", tc.unescaped, g, tc.query)
+ }
+
+ })
+ }
+}
+
+func BenchmarkPathEscape(b *testing.B) {
+ for _, tc := range escapeBenchmarks {
+ b.Run("", func(b *testing.B) {
+ b.ReportAllocs()
+ var g string
+ for i := 0; i < b.N; i++ {
+ g = PathEscape(tc.unescaped)
+ }
+ b.StopTimer()
+ if g != tc.path {
+ b.Errorf("PathEscape(%q) == %q, want %q", tc.unescaped, g, tc.path)
+ }
+
+ })
+ }
+}
+
+func BenchmarkQueryUnescape(b *testing.B) {
+ for _, tc := range escapeBenchmarks {
+ b.Run("", func(b *testing.B) {
+ b.ReportAllocs()
+ var g string
+ for i := 0; i < b.N; i++ {
+ g, _ = QueryUnescape(tc.query)
+ }
+ b.StopTimer()
+ if g != tc.unescaped {
+ b.Errorf("QueryUnescape(%q) == %q, want %q", tc.query, g, tc.unescaped)
+ }
+
+ })
+ }
+}
+
+func BenchmarkPathUnescape(b *testing.B) {
+ for _, tc := range escapeBenchmarks {
+ b.Run("", func(b *testing.B) {
+ b.ReportAllocs()
+ var g string
+ for i := 0; i < b.N; i++ {
+ g, _ = PathUnescape(tc.path)
+ }
+ b.StopTimer()
+ if g != tc.unescaped {
+ b.Errorf("PathUnescape(%q) == %q, want %q", tc.path, g, tc.unescaped)
+ }
+
+ })
+ }
+}