aboutsummaryrefslogtreecommitdiff
path: root/src/bytes/bytes_test.go
diff options
context:
space:
mode:
authorEmmanuel Odeke <emm.odeke@gmail.com>2016-04-07 23:22:30 -0700
committerRob Pike <r@golang.org>2016-04-08 20:24:57 +0000
commit59af53d681845a8b0be2a728ca1b59aee5ad9ea6 (patch)
treeafa72e2301c2cda3ddcf4f9ecb73a90204c35dfa /src/bytes/bytes_test.go
parent6c5352f181846b73d532c039df3017befe657d6a (diff)
downloadgo-59af53d681845a8b0be2a728ca1b59aee5ad9ea6.tar.xz
bytes: add ContainsRune
Make package bytes consistent with strings by adding missing function ContainsRune. Fixes #15189 Change-Id: Ie09080b389e55bbe070c57aa3bd134053a805423 Reviewed-on: https://go-review.googlesource.com/21710 Run-TryBot: Rob Pike <r@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src/bytes/bytes_test.go')
-rw-r--r--src/bytes/bytes_test.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/bytes/bytes_test.go b/src/bytes/bytes_test.go
index 40e8d09b59..620cfd1bce 100644
--- a/src/bytes/bytes_test.go
+++ b/src/bytes/bytes_test.go
@@ -1245,6 +1245,30 @@ func TestContainsAny(t *testing.T) {
}
}
+var ContainsRuneTests = []struct {
+ b []byte
+ r rune
+ expected bool
+}{
+ {[]byte(""), 'a', false},
+ {[]byte("a"), 'a', true},
+ {[]byte("aaa"), 'a', true},
+ {[]byte("abc"), 'y', false},
+ {[]byte("abc"), 'c', true},
+ {[]byte("a☺b☻c☹d"), 'x', false},
+ {[]byte("a☺b☻c☹d"), '☻', true},
+ {[]byte("aRegExp*"), '*', true},
+}
+
+func TestContainsRune(t *testing.T) {
+ for _, ct := range ContainsRuneTests {
+ if ContainsRune(ct.b, ct.r) != ct.expected {
+ t.Errorf("ContainsRune(%q, %q) = %v, want %v",
+ ct.b, ct.r, !ct.expected, ct.expected)
+ }
+ }
+}
+
var makeFieldsInput = func() []byte {
x := make([]byte, 1<<20)
// Input is ~10% space, ~10% 2-byte UTF-8, rest ASCII non-space.