]> Cypherpunks repositories - gostls13.git/commitdiff
all: use bytes.Equal, bytes.Contains and strings.Contains, again
authorDominik Honnef <dominik@honnef.co>
Fri, 1 Apr 2016 05:34:18 +0000 (07:34 +0200)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 11 Apr 2016 15:16:54 +0000 (15:16 +0000)
The previous cleanup was done with a buggy tool, missing some potential
rewrites.

Change-Id: I333467036e355f999a6a493e8de87e084f374e26
Reviewed-on: https://go-review.googlesource.com/21378
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/go/go_test.go
src/html/template/url.go
src/net/http/serve_test.go
src/path/filepath/path_test.go
src/runtime/gcinfo_test.go

index 411fd1e322e9eb064ddfd4d828444be5e7bb0458..42efa9f3124da61936eda716481e8c9c752e165b 100644 (file)
@@ -1466,7 +1466,7 @@ func TestGoTestWithPackageListedMultipleTimes(t *testing.T) {
        defer tg.cleanup()
        tg.parallel()
        tg.run("test", "errors", "errors", "errors", "errors", "errors")
-       if strings.Index(strings.TrimSpace(tg.getStdout()), "\n") != -1 {
+       if strings.Contains(strings.TrimSpace(tg.getStdout()), "\n") {
                t.Error("go test errors errors errors errors errors tested the same package multiple times")
        }
 }
@@ -1495,7 +1495,7 @@ func TestGoListCmdOnlyShowsCommands(t *testing.T) {
        tg.run("list", "cmd")
        out := strings.TrimSpace(tg.getStdout())
        for _, line := range strings.Split(out, "\n") {
-               if strings.Index(line, "cmd/") == -1 {
+               if !strings.Contains(line, "cmd/") {
                        t.Error("go list cmd shows non-commands")
                        break
                }
index 2ca76bf389fd332781cef026d7311c80e0ac3520..246bfd32cd55825c2ca3fc03db8148f30930fb3c 100644 (file)
@@ -17,7 +17,7 @@ func urlFilter(args ...interface{}) string {
        if t == contentTypeURL {
                return s
        }
-       if i := strings.IndexRune(s, ':'); i >= 0 && strings.IndexRune(s[:i], '/') < 0 {
+       if i := strings.IndexRune(s, ':'); i >= 0 && !strings.ContainsRune(s[:i], '/') {
                protocol := strings.ToLower(s[:i])
                if protocol != "http" && protocol != "https" && protocol != "mailto" {
                        return "#" + filterFailsafe
index 4cd6ed077ff77a2cd53f04b8cf9c310db7fdbc04..e0094234dee01d0b8065d9a9b8c76057625ba0a0 100644 (file)
@@ -4267,7 +4267,7 @@ func BenchmarkClient(b *testing.B) {
                if err != nil {
                        b.Fatalf("ReadAll: %v", err)
                }
-               if bytes.Compare(body, data) != 0 {
+               if !bytes.Equal(body, data) {
                        b.Fatalf("Got body: %q", body)
                }
        }
index 3622f9178e9d31e78f2e5ff0ed10459155810294..1a4a9d2a1ad7aa26a48d4a8965c4d37b4bdeb17a 100644 (file)
@@ -1015,7 +1015,7 @@ func TestAbs(t *testing.T) {
                vol := filepath.VolumeName(root)
                var extra []string
                for _, path := range absTests {
-                       if strings.Index(path, "$") != -1 {
+                       if strings.Contains(path, "$") {
                                continue
                        }
                        path = vol + path
index c1c2354bf93fb317e81fabf0eee6cddff14e7c77..9a61b4f2b202055b6ae0aa1003d356e7ae14ab9e 100644 (file)
@@ -59,7 +59,7 @@ func TestGCInfo(t *testing.T) {
 
 func verifyGCInfo(t *testing.T, name string, p interface{}, mask0 []byte) {
        mask := runtime.GCMask(p)
-       if bytes.Compare(mask, mask0) != 0 {
+       if !bytes.Equal(mask, mask0) {
                t.Errorf("bad GC program for %v:\nwant %+v\ngot  %+v", name, mask0, mask)
                return
        }