Replace some "reflect.DeepEqual" calls in the tests with
"slices.Equal" which is much faster for slice comparisons.
Remove unnecessary "runeSlice" and redundant helper functions.
Change-Id: Ib5dc41848d7a3c5149f41701d60471a487cff476
GitHub-Last-Rev:
87b5ed043d2935b971aa676cc52b9b2c5b45736b
GitHub-Pull-Request: golang/go#66509
Reviewed-on: https://go-review.googlesource.com/c/go/+/573977
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: qiulaidongfeng <2645477756@qq.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
import (
"reflect"
"regexp/syntax"
+ "slices"
"strings"
"testing"
"unicode/utf8"
}
split := re.Split(test.s, test.n)
- if !reflect.DeepEqual(split, test.out) {
+ if !slices.Equal(split, test.out) {
t.Errorf("#%d: %q: got %q; want %q", i, test.r, split, test.out)
}
if QuoteMeta(test.r) == test.r {
strsplit := strings.SplitN(test.s, test.r, test.n)
- if !reflect.DeepEqual(split, strsplit) {
+ if !slices.Equal(split, strsplit) {
t.Errorf("#%d: Split(%q, %q, %d): regexp vs strings mismatch\nregexp=%q\nstrings=%q", i, test.s, test.r, test.n, split, strsplit)
}
}
"os"
"path/filepath"
"regexp/syntax"
+ "slices"
"strconv"
"strings"
"testing"
for i := range res {
have, suffix := run[i](re, refull, text)
want := parseResult(t, file, lineno, res[i])
- if !same(have, want) {
+ if !slices.Equal(have, want) {
t.Errorf("%s:%d: %#q%s.FindSubmatchIndex(%#q) = %v, want %v", file, lineno, re, suffix, text, have, want)
if nfail++; nfail >= 100 {
t.Fatalf("stopping after %d errors", nfail)
return out
}
-func same(x, y []int) bool {
- if len(x) != len(y) {
- return false
- }
- for i, xi := range x {
- if xi != y[i] {
- return false
- }
- }
- return true
-}
-
// TestFowler runs this package's regexp API against the
// POSIX regular expression tests collected by Glenn Fowler
// at http://www2.research.att.com/~astopen/testregex/testregex.html.
if len(have) > len(pos) {
have = have[:len(pos)]
}
- if !same(have, pos) {
+ if !slices.Equal(have, pos) {
t.Errorf("%s:%d: %#q.FindSubmatchIndex(%#q) = %v, want %v", file, lineno, pattern, text, have, pos)
}
}
import (
"regexp/syntax"
- "sort"
+ "slices"
"strings"
"unicode"
"unicode/utf8"
return p
}
-// runeSlice exists to permit sorting the case-folded rune sets.
-type runeSlice []rune
-
-func (p runeSlice) Len() int { return len(p) }
-func (p runeSlice) Less(i, j int) bool { return p[i] < p[j] }
-func (p runeSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
-
var anyRuneNotNL = []rune{0, '\n' - 1, '\n' + 1, unicode.MaxRune}
var anyRune = []rune{0, unicode.MaxRune}
for r1 := unicode.SimpleFold(r0); r1 != r0; r1 = unicode.SimpleFold(r1) {
runes = append(runes, r1, r1)
}
- sort.Sort(runeSlice(runes))
+ slices.Sort(runes)
} else {
runes = append(runes, inst.Rune...)
}
for r1 := unicode.SimpleFold(r0); r1 != r0; r1 = unicode.SimpleFold(r1) {
runes = append(runes, r1, r1)
}
- sort.Sort(runeSlice(runes))
+ slices.Sort(runes)
} else {
runes = append(runes, inst.Rune[0], inst.Rune[0])
}
package regexp
import (
- "reflect"
"regexp/syntax"
+ "slices"
"strings"
"testing"
)
func TestMergeRuneSet(t *testing.T) {
for ix, test := range runeMergeTests {
merged, next := mergeRuneSets(&test.left, &test.right, test.leftPC, test.rightPC)
- if !reflect.DeepEqual(merged, test.merged) {
+ if !slices.Equal(merged, test.merged) {
t.Errorf("mergeRuneSet :%d (%v, %v) merged\n have\n%v\nwant\n%v", ix, test.left, test.right, merged, test.merged)
}
- if !reflect.DeepEqual(next, test.next) {
+ if !slices.Equal(next, test.next) {
t.Errorf("mergeRuneSet :%d(%v, %v) next\n have\n%v\nwant\n%v", ix, test.left, test.right, next, test.next)
}
}