1
0
mirror of https://github.com/golang/go synced 2024-11-13 18:00:30 -07:00

all: use bytes.Equal, bytes.Contains and strings.Contains, again

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>
This commit is contained in:
Dominik Honnef 2016-04-01 07:34:18 +02:00 committed by Brad Fitzpatrick
parent 4f12cc0813
commit 683917a721
5 changed files with 6 additions and 6 deletions

View File

@ -1466,7 +1466,7 @@ func TestGoTestWithPackageListedMultipleTimes(t *testing.T) {
defer tg.cleanup() defer tg.cleanup()
tg.parallel() tg.parallel()
tg.run("test", "errors", "errors", "errors", "errors", "errors") 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") 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") tg.run("list", "cmd")
out := strings.TrimSpace(tg.getStdout()) out := strings.TrimSpace(tg.getStdout())
for _, line := range strings.Split(out, "\n") { 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") t.Error("go list cmd shows non-commands")
break break
} }

View File

@ -17,7 +17,7 @@ func urlFilter(args ...interface{}) string {
if t == contentTypeURL { if t == contentTypeURL {
return s 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]) protocol := strings.ToLower(s[:i])
if protocol != "http" && protocol != "https" && protocol != "mailto" { if protocol != "http" && protocol != "https" && protocol != "mailto" {
return "#" + filterFailsafe return "#" + filterFailsafe

View File

@ -4267,7 +4267,7 @@ func BenchmarkClient(b *testing.B) {
if err != nil { if err != nil {
b.Fatalf("ReadAll: %v", err) b.Fatalf("ReadAll: %v", err)
} }
if bytes.Compare(body, data) != 0 { if !bytes.Equal(body, data) {
b.Fatalf("Got body: %q", body) b.Fatalf("Got body: %q", body)
} }
} }

View File

@ -1015,7 +1015,7 @@ func TestAbs(t *testing.T) {
vol := filepath.VolumeName(root) vol := filepath.VolumeName(root)
var extra []string var extra []string
for _, path := range absTests { for _, path := range absTests {
if strings.Index(path, "$") != -1 { if strings.Contains(path, "$") {
continue continue
} }
path = vol + path path = vol + path

View File

@ -59,7 +59,7 @@ func TestGCInfo(t *testing.T) {
func verifyGCInfo(t *testing.T, name string, p interface{}, mask0 []byte) { func verifyGCInfo(t *testing.T, name string, p interface{}, mask0 []byte) {
mask := runtime.GCMask(p) 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) t.Errorf("bad GC program for %v:\nwant %+v\ngot %+v", name, mask0, mask)
return return
} }