From: Shawn Smith Date: Sat, 28 Dec 2013 09:33:05 +0000 (+1100) Subject: bytes: add test for Contains X-Git-Tag: go1.3beta1~1099 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=872f5ffa095c483a506a639f1960f6778328d83e;p=gostls13.git bytes: add test for Contains R=golang-codereviews, dave CC=golang-codereviews https://golang.org/cl/46140043 --- diff --git a/src/pkg/bytes/bytes_test.go b/src/pkg/bytes/bytes_test.go index 4c4780f79a..808655a4a4 100644 --- a/src/pkg/bytes/bytes_test.go +++ b/src/pkg/bytes/bytes_test.go @@ -1162,6 +1162,24 @@ func TestBufferTruncateOutOfRange(t *testing.T) { b.Truncate(20) } +var containsTests = []struct { + b, subslice []byte + want bool +}{ + {[]byte("hello"), []byte("hel"), true}, + {[]byte("日本語"), []byte("日本"), true}, + {[]byte("hello"), []byte("Hello, world"), false}, + {[]byte("東京"), []byte("京東"), false}, +} + +func TestContains(t *testing.T) { + for _, tt := range containsTests { + if got := Contains(tt.b, tt.subslice); got != tt.want { + t.Errorf("Contains(%q, %q) = %v, want %v", tt.b, tt.subslice, got, tt.want) + } + } +} + var makeFieldsInput = func() []byte { x := make([]byte, 1<<20) // Input is ~10% space, ~10% 2-byte UTF-8, rest ASCII non-space.