bytes, strings: replace reflect.DeepEqual and custom eq with slices.Equal in tests

Change-Id: I016672af79d49a00ddc2d0449cdaac61e98b4ba0
GitHub-Last-Rev: 38d15d9a03e5bd29e4b25f1d767e40cf7165a7a6
GitHub-Pull-Request: golang/go#68730
Reviewed-on: https://go-review.googlesource.com/c/go/+/602698
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Commit-Queue: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
aimuz 2024-08-05 03:00:42 +00:00 committed by Gopher Robot
parent d465aee0b8
commit 677e080dfe
2 changed files with 9 additions and 22 deletions

View File

@ -10,7 +10,6 @@ import (
"internal/testenv" "internal/testenv"
"math" "math"
"math/rand" "math/rand"
"reflect"
"slices" "slices"
"strings" "strings"
"testing" "testing"
@ -814,8 +813,8 @@ func TestSplit(t *testing.T) {
t.Errorf(`Join(Split(%q, %q, %d), %q) = %q`, tt.s, tt.sep, tt.n, tt.sep, s) t.Errorf(`Join(Split(%q, %q, %d), %q) = %q`, tt.s, tt.sep, tt.n, tt.sep, s)
} }
if tt.n < 0 { if tt.n < 0 {
b := Split([]byte(tt.s), []byte(tt.sep)) b := sliceOfString(Split([]byte(tt.s), []byte(tt.sep)))
if !reflect.DeepEqual(a, b) { if !slices.Equal(result, b) {
t.Errorf("Split disagrees withSplitN(%q, %q, %d) = %v; want %v", tt.s, tt.sep, tt.n, b, a) t.Errorf("Split disagrees withSplitN(%q, %q, %d) = %v; want %v", tt.s, tt.sep, tt.n, b, a)
} }
} }
@ -869,8 +868,8 @@ func TestSplitAfter(t *testing.T) {
t.Errorf(`Join(Split(%q, %q, %d), %q) = %q`, tt.s, tt.sep, tt.n, tt.sep, s) t.Errorf(`Join(Split(%q, %q, %d), %q) = %q`, tt.s, tt.sep, tt.n, tt.sep, s)
} }
if tt.n < 0 { if tt.n < 0 {
b := SplitAfter([]byte(tt.s), []byte(tt.sep)) b := sliceOfString(SplitAfter([]byte(tt.s), []byte(tt.sep)))
if !reflect.DeepEqual(a, b) { if !slices.Equal(result, b) {
t.Errorf("SplitAfter disagrees withSplitAfterN(%q, %q, %d) = %v; want %v", tt.s, tt.sep, tt.n, b, a) t.Errorf("SplitAfter disagrees withSplitAfterN(%q, %q, %d) = %v; want %v", tt.s, tt.sep, tt.n, b, a)
} }
} }

View File

@ -19,18 +19,6 @@ import (
"unsafe" "unsafe"
) )
func eq(a, b []string) bool {
if len(a) != len(b) {
return false
}
for i := 0; i < len(a); i++ {
if a[i] != b[i] {
return false
}
}
return true
}
var abcd = "abcd" var abcd = "abcd"
var faces = "☺☻☹" var faces = "☺☻☹"
var commas = "1,2,3,4" var commas = "1,2,3,4"
@ -418,7 +406,7 @@ var splittests = []SplitTest{
func TestSplit(t *testing.T) { func TestSplit(t *testing.T) {
for _, tt := range splittests { for _, tt := range splittests {
a := SplitN(tt.s, tt.sep, tt.n) a := SplitN(tt.s, tt.sep, tt.n)
if !eq(a, tt.a) { if !slices.Equal(a, tt.a) {
t.Errorf("Split(%q, %q, %d) = %v; want %v", tt.s, tt.sep, tt.n, a, tt.a) t.Errorf("Split(%q, %q, %d) = %v; want %v", tt.s, tt.sep, tt.n, a, tt.a)
continue continue
} }
@ -457,7 +445,7 @@ var splitaftertests = []SplitTest{
func TestSplitAfter(t *testing.T) { func TestSplitAfter(t *testing.T) {
for _, tt := range splitaftertests { for _, tt := range splitaftertests {
a := SplitAfterN(tt.s, tt.sep, tt.n) a := SplitAfterN(tt.s, tt.sep, tt.n)
if !eq(a, tt.a) { if !slices.Equal(a, tt.a) {
t.Errorf(`Split(%q, %q, %d) = %v; want %v`, tt.s, tt.sep, tt.n, a, tt.a) t.Errorf(`Split(%q, %q, %d) = %v; want %v`, tt.s, tt.sep, tt.n, a, tt.a)
continue continue
} }
@ -500,7 +488,7 @@ var fieldstests = []FieldsTest{
func TestFields(t *testing.T) { func TestFields(t *testing.T) {
for _, tt := range fieldstests { for _, tt := range fieldstests {
a := Fields(tt.s) a := Fields(tt.s)
if !eq(a, tt.a) { if !slices.Equal(a, tt.a) {
t.Errorf("Fields(%q) = %v; want %v", tt.s, a, tt.a) t.Errorf("Fields(%q) = %v; want %v", tt.s, a, tt.a)
continue continue
} }
@ -517,7 +505,7 @@ var FieldsFuncTests = []FieldsTest{
func TestFieldsFunc(t *testing.T) { func TestFieldsFunc(t *testing.T) {
for _, tt := range fieldstests { for _, tt := range fieldstests {
a := FieldsFunc(tt.s, unicode.IsSpace) a := FieldsFunc(tt.s, unicode.IsSpace)
if !eq(a, tt.a) { if !slices.Equal(a, tt.a) {
t.Errorf("FieldsFunc(%q, unicode.IsSpace) = %v; want %v", tt.s, a, tt.a) t.Errorf("FieldsFunc(%q, unicode.IsSpace) = %v; want %v", tt.s, a, tt.a)
continue continue
} }
@ -525,7 +513,7 @@ func TestFieldsFunc(t *testing.T) {
pred := func(c rune) bool { return c == 'X' } pred := func(c rune) bool { return c == 'X' }
for _, tt := range FieldsFuncTests { for _, tt := range FieldsFuncTests {
a := FieldsFunc(tt.s, pred) a := FieldsFunc(tt.s, pred)
if !eq(a, tt.a) { if !slices.Equal(a, tt.a) {
t.Errorf("FieldsFunc(%q) = %v, want %v", tt.s, a, tt.a) t.Errorf("FieldsFunc(%q) = %v, want %v", tt.s, a, tt.a)
} }
} }