Commit 1cb3044c authored by Dominik Honnef's avatar Dominik Honnef Committed by Dave Cheney

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: 's avatarDave Cheney <dave@cheney.net>
parent 42d62946
......@@ -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")
}
}
......
......@@ -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)
}
}
......@@ -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))
}
}
......@@ -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")
}
}
......
......@@ -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
}
}
......
......@@ -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)
}
......
......@@ -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)
......
......@@ -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)
......
......@@ -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
}
......
......@@ -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")
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment