]> Cypherpunks repositories - gostls13.git/commitdiff
all: use bytes.Equal, bytes.Contains and strings.Contains
authorDominik Honnef <dominik@honnef.co>
Fri, 1 Apr 2016 01:49:43 +0000 (03:49 +0200)
committerDave Cheney <dave@cheney.net>
Fri, 1 Apr 2016 02:05:01 +0000 (02:05 +0000)
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>
src/cmd/compile/internal/gc/global_test.go
src/cmd/gofmt/gofmt_test.go
src/compress/flate/writer_test.go
src/crypto/cipher/xor_test.go
src/crypto/x509/verify_test.go
src/crypto/x509/x509_test.go
src/encoding/xml/marshal.go
src/html/template/css.go
src/html/template/escape_test.go
src/internal/trace/parser.go

index 54d3ed1b7d4490bfbdad83be1e8b0203cf6c0b11..f0139e763c6226136bc819153f81b7fc457070ae 100644 (file)
@@ -59,7 +59,7 @@ func main() {
        if err != nil {
                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")
        }
 }
index d1edb7bcc16c25fba5cdaa68b287838bd451cfac..dea012764b38308a43d12ed7db8ff63c62aa4662 100644 (file)
@@ -159,7 +159,7 @@ func TestCRLF(t *testing.T) {
        if err != nil {
                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)
        }
 
@@ -167,7 +167,7 @@ func TestCRLF(t *testing.T) {
        if err != nil {
                t.Error(err)
        }
-       if bytes.Index(data, []byte("\r")) >= 0 {
+       if bytes.Contains(data, []byte("\r")) {
                t.Errorf("%s contains CR's", golden)
        }
 }
index dd479bea82fbdd448c0f4c18a72ad713dd55386e..633cadf2b7cfa87c97a1b189552506f84b5ad0fa 100644 (file)
@@ -196,7 +196,7 @@ func testDeterministic(i int, t *testing.T) {
        b1b := b1.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))
        }
 }
index cc1c9d72d5591d8130920f34bd6b29f14bb83020..d9187eb72638508dfa14baab795d338cc7bc463a 100644 (file)
@@ -19,7 +19,7 @@ func TestXOR(t *testing.T) {
                                d2 := make([]byte, 1024+alignD)[alignD:]
                                xorBytes(d1, p, q)
                                safeXORBytes(d2, p, q)
-                               if bytes.Compare(d1, d2) != 0 {
+                               if !bytes.Equal(d1, d2) {
                                        t.Error("not equal")
                                }
                        }
index a08cdeff057277649a62525b96f579f1a36ac263..bacf7ded29f532d1daba76e2a0c8f20710e9cde6 100644 (file)
@@ -382,7 +382,7 @@ func testVerify(t *testing.T, useSystemRoots bool) {
                                        continue
                                }
                                for k, cert := range chain {
-                                       if strings.Index(nameToKey(&cert.Subject), expectedChain[k]) == -1 {
+                                       if !strings.Contains(nameToKey(&cert.Subject), expectedChain[k]) {
                                                continue TryNextExpected
                                        }
                                }
index d1ef0274bc27e0fbb0ce9cd691e346d7e6c47d60..cd70a27da3f2871dd9c978377116bc5be3ecf982 100644 (file)
@@ -488,7 +488,7 @@ func TestCreateSelfSignedCertificate(t *testing.T) {
                        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)
                }
 
index ec4822b5c141567d22b73dc949a33568d7205720..609c790520fbf6e68b49c4a397ffedc266fc4b3d 100644 (file)
@@ -856,7 +856,7 @@ func (p *printer) marshalStruct(tinfo *typeInfo, val reflect.Value) error {
                                }
                        case reflect.Slice:
                                b := vf.Bytes()
-                               dashDash = bytes.Index(b, ddBytes) >= 0
+                               dashDash = bytes.Contains(b, ddBytes)
                                dashLast = b[len(b)-1] == '-'
                                if !dashDash {
                                        p.Write(b)
index 318464835fa05d68efb9b194f6c8fc46df356f65..4c27cce85ac830d1032de3a4e130e0408bb24f0f 100644 (file)
@@ -249,7 +249,7 @@ func cssValueFilter(args ...interface{}) string {
                }
        }
        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 string(b)
index 707394e3b02456ad10559338b55169902d4d7b25..023ee57d597c4f321a282f7f059a074b9e2b6684 100644 (file)
@@ -990,7 +990,7 @@ func TestErrors(t *testing.T) {
                        }
                        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)
                        continue
                }
index 00e5d75a2eff19e6a29aca18608479f3a71dd33b..e32567873359f3bdb57eed3277fad804e34bf2a1 100644 (file)
@@ -94,7 +94,7 @@ func readTrace(r io.Reader) ([]rawEvent, error) {
        if off != 16 || err != nil {
                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")
        }