aboutsummaryrefslogtreecommitdiff
path: root/src/bytes
diff options
context:
space:
mode:
authorapocelipes <seve3r@outlook.com>2024-07-24 10:32:22 +0000
committerRobert Griesemer <gri@google.com>2024-07-24 18:45:08 +0000
commitc0eac35a4cd3ca16d3d1fc153a155b0b18f49633 (patch)
treed0b5071068940ae7a1bcce685a80828dc95e02d8 /src/bytes
parent910e6b5fae7cbf84e4a3fcfa6739e20239080bcd (diff)
downloadgo-c0eac35a4cd3ca16d3d1fc153a155b0b18f49633.tar.xz
bytes,strings,unicode/utf16: use slices to clean up tests
Replace reflect.DeepEqual with slices.Equal, which is much faster. Remove some redundant helper functions. Change-Id: I51b32a3d0c3fc5ad0d3b6ff0dd03f39c507e5762 GitHub-Last-Rev: e21f46d4a026b6bf6e8d912dfb8d361a20a4e779 GitHub-Pull-Request: golang/go#67609 Reviewed-on: https://go-review.googlesource.com/c/go/+/587937 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Griesemer <gri@google.com>
Diffstat (limited to 'src/bytes')
-rw-r--r--src/bytes/bytes_test.go37
1 files changed, 7 insertions, 30 deletions
diff --git a/src/bytes/bytes_test.go b/src/bytes/bytes_test.go
index 200a357bc0..94301358e0 100644
--- a/src/bytes/bytes_test.go
+++ b/src/bytes/bytes_test.go
@@ -11,6 +11,7 @@ import (
"math"
"math/rand"
"reflect"
+ "slices"
"strings"
"testing"
"unicode"
@@ -18,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
-}
-
func sliceOfString(s [][]byte) []string {
result := make([]string, len(s))
for i, v := range s {
@@ -808,7 +797,7 @@ func TestSplit(t *testing.T) {
}
result := sliceOfString(a)
- if !eq(result, tt.a) {
+ if !slices.Equal(result, tt.a) {
t.Errorf(`Split(%q, %q, %d) = %v; want %v`, tt.s, tt.sep, tt.n, result, tt.a)
continue
}
@@ -866,7 +855,7 @@ func TestSplitAfter(t *testing.T) {
}
result := sliceOfString(a)
- if !eq(result, tt.a) {
+ if !slices.Equal(result, tt.a) {
t.Errorf(`Split(%q, %q, %d) = %v; want %v`, tt.s, tt.sep, tt.n, result, tt.a)
continue
}
@@ -919,7 +908,7 @@ func TestFields(t *testing.T) {
}
result := sliceOfString(a)
- if !eq(result, tt.a) {
+ if !slices.Equal(result, tt.a) {
t.Errorf("Fields(%q) = %v; want %v", tt.s, a, tt.a)
continue
}
@@ -939,7 +928,7 @@ func TestFieldsFunc(t *testing.T) {
for _, tt := range fieldstests {
a := FieldsFunc([]byte(tt.s), unicode.IsSpace)
result := sliceOfString(a)
- if !eq(result, tt.a) {
+ if !slices.Equal(result, tt.a) {
t.Errorf("FieldsFunc(%q, unicode.IsSpace) = %v; want %v", tt.s, a, tt.a)
continue
}
@@ -962,7 +951,7 @@ func TestFieldsFunc(t *testing.T) {
}
result := sliceOfString(a)
- if !eq(result, tt.a) {
+ if !slices.Equal(result, tt.a) {
t.Errorf("FieldsFunc(%q) = %v, want %v", tt.s, a, tt.a)
}
@@ -1286,18 +1275,6 @@ func TestRepeatCatchesOverflow(t *testing.T) {
})
}
-func runesEqual(a, b []rune) bool {
- if len(a) != len(b) {
- return false
- }
- for i, r := range a {
- if r != b[i] {
- return false
- }
- }
- return true
-}
-
type RunesTest struct {
in string
out []rune
@@ -1318,7 +1295,7 @@ func TestRunes(t *testing.T) {
for _, tt := range RunesTests {
tin := []byte(tt.in)
a := Runes(tin)
- if !runesEqual(a, tt.out) {
+ if !slices.Equal(a, tt.out) {
t.Errorf("Runes(%q) = %v; want %v", tin, a, tt.out)
continue
}