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

Change-Id: Iba82a5bd3846f7ab038cc10ec72ff6bcd2c0b484
Reviewed-on: https://go-review.googlesource.com/21377
Run-TryBot: Dave Cheney <dave@cheney.net>
Reviewed-by: Dave Cheney <dave@cheney.net>
This commit is contained in:
Dominik Honnef 2016-04-01 03:49:43 +02:00 committed by Dave Cheney
parent 42d6294694
commit 1cb3044c9f
10 changed files with 11 additions and 11 deletions

View file

@ -59,7 +59,7 @@ func main() {
if err != nil { if err != nil {
log.Fatalf("could not read target: %v", err) log.Fatalf("could not read target: %v", err)
} }
if bytes.Index(out, []byte("scanInt")) != -1 { if bytes.Contains(out, []byte("scanInt")) {
log.Fatalf("scanf code not removed from helloworld") log.Fatalf("scanf code not removed from helloworld")
} }
} }

View file

@ -159,7 +159,7 @@ func TestCRLF(t *testing.T) {
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
if bytes.Index(data, []byte("\r\n")) < 0 { if !bytes.Contains(data, []byte("\r\n")) {
t.Errorf("%s contains no CR/LF's", input) t.Errorf("%s contains no CR/LF's", input)
} }
@ -167,7 +167,7 @@ func TestCRLF(t *testing.T) {
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
if bytes.Index(data, []byte("\r")) >= 0 { if bytes.Contains(data, []byte("\r")) {
t.Errorf("%s contains CR's", golden) t.Errorf("%s contains CR's", golden)
} }
} }

View file

@ -196,7 +196,7 @@ func testDeterministic(i int, t *testing.T) {
b1b := b1.Bytes() b1b := b1.Bytes()
b2b := b2.Bytes() b2b := b2.Bytes()
if bytes.Compare(b1b, b2b) != 0 { if !bytes.Equal(b1b, b2b) {
t.Errorf("level %d did not produce deterministic result, result mismatch, len(a) = %d, len(b) = %d", i, len(b1b), len(b2b)) t.Errorf("level %d did not produce deterministic result, result mismatch, len(a) = %d, len(b) = %d", i, len(b1b), len(b2b))
} }
} }

View file

@ -19,7 +19,7 @@ func TestXOR(t *testing.T) {
d2 := make([]byte, 1024+alignD)[alignD:] d2 := make([]byte, 1024+alignD)[alignD:]
xorBytes(d1, p, q) xorBytes(d1, p, q)
safeXORBytes(d2, p, q) safeXORBytes(d2, p, q)
if bytes.Compare(d1, d2) != 0 { if !bytes.Equal(d1, d2) {
t.Error("not equal") t.Error("not equal")
} }
} }

View file

@ -382,7 +382,7 @@ func testVerify(t *testing.T, useSystemRoots bool) {
continue continue
} }
for k, cert := range chain { for k, cert := range chain {
if strings.Index(nameToKey(&cert.Subject), expectedChain[k]) == -1 { if !strings.Contains(nameToKey(&cert.Subject), expectedChain[k]) {
continue TryNextExpected continue TryNextExpected
} }
} }

View file

@ -488,7 +488,7 @@ func TestCreateSelfSignedCertificate(t *testing.T) {
t.Errorf("%s: ExtraExtensions didn't override SubjectKeyId", test.name) t.Errorf("%s: ExtraExtensions didn't override SubjectKeyId", test.name)
} }
if bytes.Index(derBytes, extraExtensionData) == -1 { if !bytes.Contains(derBytes, extraExtensionData) {
t.Errorf("%s: didn't find extra extension in DER output", test.name) t.Errorf("%s: didn't find extra extension in DER output", test.name)
} }

View file

@ -856,7 +856,7 @@ func (p *printer) marshalStruct(tinfo *typeInfo, val reflect.Value) error {
} }
case reflect.Slice: case reflect.Slice:
b := vf.Bytes() b := vf.Bytes()
dashDash = bytes.Index(b, ddBytes) >= 0 dashDash = bytes.Contains(b, ddBytes)
dashLast = b[len(b)-1] == '-' dashLast = b[len(b)-1] == '-'
if !dashDash { if !dashDash {
p.Write(b) p.Write(b)

View file

@ -249,7 +249,7 @@ func cssValueFilter(args ...interface{}) string {
} }
} }
id = bytes.ToLower(id) id = bytes.ToLower(id)
if bytes.Index(id, expressionBytes) != -1 || bytes.Index(id, mozBindingBytes) != -1 { if bytes.Contains(id, expressionBytes) || bytes.Contains(id, mozBindingBytes) {
return filterFailsafe return filterFailsafe
} }
return string(b) return string(b)

View file

@ -990,7 +990,7 @@ func TestErrors(t *testing.T) {
} }
continue continue
} }
if strings.Index(got, test.err) == -1 { if !strings.Contains(got, test.err) {
t.Errorf("input=%q: error\n\t%q\ndoes not contain expected string\n\t%q", test.input, got, test.err) t.Errorf("input=%q: error\n\t%q\ndoes not contain expected string\n\t%q", test.input, got, test.err)
continue continue
} }

View file

@ -94,7 +94,7 @@ func readTrace(r io.Reader) ([]rawEvent, error) {
if off != 16 || err != nil { if off != 16 || err != nil {
return nil, fmt.Errorf("failed to read header: read %v, err %v", off, err) return nil, fmt.Errorf("failed to read header: read %v, err %v", off, err)
} }
if bytes.Compare(buf[:], []byte("go 1.5 trace\x00\x00\x00\x00")) != 0 { if !bytes.Equal(buf[:], []byte("go 1.5 trace\x00\x00\x00\x00")) {
return nil, fmt.Errorf("not a trace file") return nil, fmt.Errorf("not a trace file")
} }