diff options
Diffstat (limited to 'src/pkg/bytes/bytes_test.go')
| -rw-r--r-- | src/pkg/bytes/bytes_test.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/pkg/bytes/bytes_test.go b/src/pkg/bytes/bytes_test.go index b91ae5734d..de503878cd 100644 --- a/src/pkg/bytes/bytes_test.go +++ b/src/pkg/bytes/bytes_test.go @@ -125,6 +125,15 @@ var indexAnyTests = []BinOpTest{ BinOpTest{dots + dots + dots, " ", -1}, } +var indexRuneTests = []BinOpTest{ + BinOpTest{"", "a", -1}, + BinOpTest{"", "☺", -1}, + BinOpTest{"foo", "☹", -1}, + BinOpTest{"foo", "o", 1}, + BinOpTest{"foo☺bar", "☺", 3}, + BinOpTest{"foo☺☻☹bar", "☹", 9}, +} + // Execute f on each test case. funcName should be the name of f; it's used // in failure reports. func runIndexTests(t *testing.T, f func(s, sep []byte) int, funcName string, testCases []BinOpTest) { @@ -168,6 +177,17 @@ func TestIndexByte(t *testing.T) { } } +func TestIndexRune(t *testing.T) { + for _, tt := range indexRuneTests { + a := []byte(tt.a) + r, _ := utf8.DecodeRuneInString(tt.b) + pos := IndexRune(a, r) + if pos != tt.i { + t.Errorf(`IndexRune(%q, '%c') = %v`, tt.a, r, pos) + } + } +} + func BenchmarkIndexByte4K(b *testing.B) { bmIndex(b, IndexByte, 4<<10) } func BenchmarkIndexByte4M(b *testing.B) { bmIndex(b, IndexByte, 4<<20) } @@ -336,6 +356,23 @@ func TestFields(t *testing.T) { } } +func TestFieldsFunc(t *testing.T) { + pred := func(c int) bool { return c == 'X' } + var fieldsFuncTests = []FieldsTest{ + FieldsTest{"", []string{}}, + FieldsTest{"XX", []string{}}, + FieldsTest{"XXhiXXX", []string{"hi"}}, + FieldsTest{"aXXbXXXcX", []string{"a", "b", "c"}}, + } + for _, tt := range fieldsFuncTests { + a := FieldsFunc([]byte(tt.s), pred) + result := arrayOfString(a) + if !eq(result, tt.a) { + t.Errorf("FieldsFunc(%q) = %v, want %v", tt.s, a, tt.a) + } + } +} + // Test case for any function which accepts and returns a byte array. // For ease of creation, we write the byte arrays as strings. type StringTest struct { |
