]> Cypherpunks repositories - gostls13.git/commitdiff
bytes, strings: replace reflect.DeepEqual and custom eq with slices.Equal in tests
authoraimuz <mr.imuz@gmail.com>
Mon, 5 Aug 2024 03:00:42 +0000 (03:00 +0000)
committerGopher Robot <gobot@golang.org>
Mon, 5 Aug 2024 18:44:21 +0000 (18:44 +0000)
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>
src/bytes/bytes_test.go
src/strings/strings_test.go

index 94301358e037b82c3f24e980559294f28e442ca8..6fb6140c1889b85a15a4135c78d67a899c3c38be 100644 (file)
@@ -10,7 +10,6 @@ import (
        "internal/testenv"
        "math"
        "math/rand"
-       "reflect"
        "slices"
        "strings"
        "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)
                }
                if tt.n < 0 {
-                       b := Split([]byte(tt.s), []byte(tt.sep))
-                       if !reflect.DeepEqual(a, b) {
+                       b := sliceOfString(Split([]byte(tt.s), []byte(tt.sep)))
+                       if !slices.Equal(result, b) {
                                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)
                }
                if tt.n < 0 {
-                       b := SplitAfter([]byte(tt.s), []byte(tt.sep))
-                       if !reflect.DeepEqual(a, b) {
+                       b := sliceOfString(SplitAfter([]byte(tt.s), []byte(tt.sep)))
+                       if !slices.Equal(result, b) {
                                t.Errorf("SplitAfter disagrees withSplitAfterN(%q, %q, %d) = %v; want %v", tt.s, tt.sep, tt.n, b, a)
                        }
                }
index 4c8c25ee132a2840f6a5e6a05ffe552366c1f73e..c9183722804fb436c2afcc9da30bb984ca5f8c0f 100644 (file)
@@ -19,18 +19,6 @@ import (
        "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 faces = "☺☻☹"
 var commas = "1,2,3,4"
@@ -418,7 +406,7 @@ var splittests = []SplitTest{
 func TestSplit(t *testing.T) {
        for _, tt := range splittests {
                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)
                        continue
                }
@@ -457,7 +445,7 @@ var splitaftertests = []SplitTest{
 func TestSplitAfter(t *testing.T) {
        for _, tt := range splitaftertests {
                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)
                        continue
                }
@@ -500,7 +488,7 @@ var fieldstests = []FieldsTest{
 func TestFields(t *testing.T) {
        for _, tt := range fieldstests {
                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)
                        continue
                }
@@ -517,7 +505,7 @@ var FieldsFuncTests = []FieldsTest{
 func TestFieldsFunc(t *testing.T) {
        for _, tt := range fieldstests {
                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)
                        continue
                }
@@ -525,7 +513,7 @@ func TestFieldsFunc(t *testing.T) {
        pred := func(c rune) bool { return c == 'X' }
        for _, tt := range FieldsFuncTests {
                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)
                }
        }