Skip to content

Commit 677e080

Browse files
aimuzgopherbot
authored andcommitted
bytes, strings: replace reflect.DeepEqual and custom eq with slices.Equal in tests
Change-Id: I016672af79d49a00ddc2d0449cdaac61e98b4ba0 GitHub-Last-Rev: 38d15d9 GitHub-Pull-Request: #68730 Reviewed-on: https://go-review.googlesource.com/c/go/+/602698 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> Auto-Submit: Robert Griesemer <[email protected]> Commit-Queue: Ian Lance Taylor <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent d465aee commit 677e080

File tree

2 files changed

+9
-22
lines changed

2 files changed

+9
-22
lines changed

src/bytes/bytes_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"internal/testenv"
1111
"math"
1212
"math/rand"
13-
"reflect"
1413
"slices"
1514
"strings"
1615
"testing"
@@ -814,8 +813,8 @@ func TestSplit(t *testing.T) {
814813
t.Errorf(`Join(Split(%q, %q, %d), %q) = %q`, tt.s, tt.sep, tt.n, tt.sep, s)
815814
}
816815
if tt.n < 0 {
817-
b := Split([]byte(tt.s), []byte(tt.sep))
818-
if !reflect.DeepEqual(a, b) {
816+
b := sliceOfString(Split([]byte(tt.s), []byte(tt.sep)))
817+
if !slices.Equal(result, b) {
819818
t.Errorf("Split disagrees withSplitN(%q, %q, %d) = %v; want %v", tt.s, tt.sep, tt.n, b, a)
820819
}
821820
}
@@ -869,8 +868,8 @@ func TestSplitAfter(t *testing.T) {
869868
t.Errorf(`Join(Split(%q, %q, %d), %q) = %q`, tt.s, tt.sep, tt.n, tt.sep, s)
870869
}
871870
if tt.n < 0 {
872-
b := SplitAfter([]byte(tt.s), []byte(tt.sep))
873-
if !reflect.DeepEqual(a, b) {
871+
b := sliceOfString(SplitAfter([]byte(tt.s), []byte(tt.sep)))
872+
if !slices.Equal(result, b) {
874873
t.Errorf("SplitAfter disagrees withSplitAfterN(%q, %q, %d) = %v; want %v", tt.s, tt.sep, tt.n, b, a)
875874
}
876875
}

src/strings/strings_test.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,6 @@ import (
1919
"unsafe"
2020
)
2121

22-
func eq(a, b []string) bool {
23-
if len(a) != len(b) {
24-
return false
25-
}
26-
for i := 0; i < len(a); i++ {
27-
if a[i] != b[i] {
28-
return false
29-
}
30-
}
31-
return true
32-
}
33-
3422
var abcd = "abcd"
3523
var faces = "☺☻☹"
3624
var commas = "1,2,3,4"
@@ -418,7 +406,7 @@ var splittests = []SplitTest{
418406
func TestSplit(t *testing.T) {
419407
for _, tt := range splittests {
420408
a := SplitN(tt.s, tt.sep, tt.n)
421-
if !eq(a, tt.a) {
409+
if !slices.Equal(a, tt.a) {
422410
t.Errorf("Split(%q, %q, %d) = %v; want %v", tt.s, tt.sep, tt.n, a, tt.a)
423411
continue
424412
}
@@ -457,7 +445,7 @@ var splitaftertests = []SplitTest{
457445
func TestSplitAfter(t *testing.T) {
458446
for _, tt := range splitaftertests {
459447
a := SplitAfterN(tt.s, tt.sep, tt.n)
460-
if !eq(a, tt.a) {
448+
if !slices.Equal(a, tt.a) {
461449
t.Errorf(`Split(%q, %q, %d) = %v; want %v`, tt.s, tt.sep, tt.n, a, tt.a)
462450
continue
463451
}
@@ -500,7 +488,7 @@ var fieldstests = []FieldsTest{
500488
func TestFields(t *testing.T) {
501489
for _, tt := range fieldstests {
502490
a := Fields(tt.s)
503-
if !eq(a, tt.a) {
491+
if !slices.Equal(a, tt.a) {
504492
t.Errorf("Fields(%q) = %v; want %v", tt.s, a, tt.a)
505493
continue
506494
}
@@ -517,15 +505,15 @@ var FieldsFuncTests = []FieldsTest{
517505
func TestFieldsFunc(t *testing.T) {
518506
for _, tt := range fieldstests {
519507
a := FieldsFunc(tt.s, unicode.IsSpace)
520-
if !eq(a, tt.a) {
508+
if !slices.Equal(a, tt.a) {
521509
t.Errorf("FieldsFunc(%q, unicode.IsSpace) = %v; want %v", tt.s, a, tt.a)
522510
continue
523511
}
524512
}
525513
pred := func(c rune) bool { return c == 'X' }
526514
for _, tt := range FieldsFuncTests {
527515
a := FieldsFunc(tt.s, pred)
528-
if !eq(a, tt.a) {
516+
if !slices.Equal(a, tt.a) {
529517
t.Errorf("FieldsFunc(%q) = %v, want %v", tt.s, a, tt.a)
530518
}
531519
}

0 commit comments

Comments
 (0)