aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/bytes/bytes_test.go
diff options
context:
space:
mode:
authorBenny Siegert <bsiegert@gmail.com>2010-11-12 12:47:50 -0800
committerRob Pike <r@golang.org>2010-11-12 12:47:50 -0800
commit8530e8ef6566c2345866a1e42b484dbf24c64264 (patch)
tree721f327556136368ce2d973c29e3e2063770e17a /src/pkg/bytes/bytes_test.go
parentf0d174b776fd0312c6e92193e6a27c516a0b2da6 (diff)
downloadgo-8530e8ef6566c2345866a1e42b484dbf24c64264.tar.xz
strings: add LastIndexAny
The need for a LastIndexAny function has come up in the discussion for https://golang.org/cl/3008041/. This function is implemented analogously to lastIndexFunc, using functions from the utf8 package. R=r, rsc, PeterGo CC=golang-dev https://golang.org/cl/3057041
Diffstat (limited to 'src/pkg/bytes/bytes_test.go')
-rw-r--r--src/pkg/bytes/bytes_test.go31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/pkg/bytes/bytes_test.go b/src/pkg/bytes/bytes_test.go
index f3ca371f83..28e7086529 100644
--- a/src/pkg/bytes/bytes_test.go
+++ b/src/pkg/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 {