1
0
mirror of https://github.com/golang/go synced 2024-11-18 15:44:41 -07:00

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 {
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")
}
}

View 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)
}
}

View 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))
}
}

View 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")
}
}

View 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
}
}

View 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)
}

View 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)

View 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)

View 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
}

View 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")
}