summaryrefslogtreecommitdiff
path: root/libgo/go/bytes/bytes_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/bytes/bytes_test.go')
-rw-r--r--libgo/go/bytes/bytes_test.go70
1 files changed, 25 insertions, 45 deletions
diff --git a/libgo/go/bytes/bytes_test.go b/libgo/go/bytes/bytes_test.go
index f3ca371f83e..063686ec5d6 100644
--- a/libgo/go/bytes/bytes_test.go
+++ b/libgo/go/bytes/bytes_test.go
@@ -128,6 +128,20 @@ var indexAnyTests = []BinOpTest{
{dots + dots + dots, " ", -1},
}
+var lastIndexAnyTests = []BinOpTest{
+ {"", "", -1},
+ {"", "a", -1},
+ {"", "abc", -1},
+ {"a", "", -1},
+ {"a", "a", 0},
+ {"aaa", "a", 2},
+ {"abc", "xyz", -1},
+ {"abc", "ab", 1},
+ {"a☺b☻c☹d", "uvw☻xyz", 2 + len("☺")},
+ {"a.RegExp*", ".(|)*+?^$[]", 8},
+ {dots + dots + dots, " ", -1},
+}
+
var indexRuneTests = []BinOpTest{
{"", "a", -1},
{"", "☺", -1},
@@ -150,18 +164,23 @@ func runIndexTests(t *testing.T, f func(s, sep []byte) int, funcName string, tes
}
}
-func TestIndex(t *testing.T) { runIndexTests(t, Index, "Index", indexTests) }
-func TestLastIndex(t *testing.T) { runIndexTests(t, LastIndex, "LastIndex", lastIndexTests) }
-func TestIndexAny(t *testing.T) {
- for _, test := range indexAnyTests {
+func runIndexAnyTests(t *testing.T, f func(s []byte, chars string) int, funcName string, testCases []BinOpTest) {
+ for _, test := range testCases {
a := []byte(test.a)
- actual := IndexAny(a, test.b)
+ actual := f(a, test.b)
if actual != test.i {
- t.Errorf("IndexAny(%q,%q) = %v; want %v", a, test.b, actual, test.i)
+ t.Errorf("%s(%q,%q) = %v; want %v", funcName, a, test.b, actual, test.i)
}
}
}
+func TestIndex(t *testing.T) { runIndexTests(t, Index, "Index", indexTests) }
+func TestLastIndex(t *testing.T) { runIndexTests(t, LastIndex, "LastIndex", lastIndexTests) }
+func TestIndexAny(t *testing.T) { runIndexAnyTests(t, IndexAny, "IndexAny", indexAnyTests) }
+func TestLastIndexAny(t *testing.T) {
+ runIndexAnyTests(t, LastIndexAny, "LastIndexAny", lastIndexAnyTests)
+}
+
func TestIndexByte(t *testing.T) {
for _, tt := range indexTests {
if len(tt.b) != 1 {
@@ -554,45 +573,6 @@ func TestToLower(t *testing.T) { runStringTests(t, ToLower, "ToLower", lowerTest
func TestTrimSpace(t *testing.T) { runStringTests(t, TrimSpace, "TrimSpace", trimSpaceTests) }
-type AddTest struct {
- s, t string
- cap int
-}
-
-var addtests = []AddTest{
- {"", "", 0},
- {"a", "", 1},
- {"a", "b", 1},
- {"abc", "def", 100},
-}
-
-func TestAdd(t *testing.T) {
- for _, test := range addtests {
- b := make([]byte, len(test.s), test.cap)
- copy(b, test.s)
- b = Add(b, []byte(test.t))
- if string(b) != test.s+test.t {
- t.Errorf("Add(%q,%q) = %q", test.s, test.t, string(b))
- }
- }
-}
-
-func TestAddByte(t *testing.T) {
- const N = 2e5
- b := make([]byte, 0)
- for i := 0; i < N; i++ {
- b = AddByte(b, byte(i))
- }
- if len(b) != N {
- t.Errorf("AddByte: too small; expected %d got %d", N, len(b))
- }
- for i, c := range b {
- if c != byte(i) {
- t.Fatalf("AddByte: b[%d] should be %d is %d", i, c, byte(i))
- }
- }
-}
-
type RepeatTest struct {
in, out string
count int