]> Cypherpunks repositories - gostls13.git/commitdiff
bytes: add test for Contains
authorShawn Smith <shawn.p.smith@gmail.com>
Sat, 28 Dec 2013 09:33:05 +0000 (20:33 +1100)
committerDave Cheney <dave@cheney.net>
Sat, 28 Dec 2013 09:33:05 +0000 (20:33 +1100)
R=golang-codereviews, dave
CC=golang-codereviews
https://golang.org/cl/46140043

src/pkg/bytes/bytes_test.go

index 4c4780f79ac88e7a95115a931596ddc4751a1682..808655a4a48622c9d4145c6278cdb46937a47a0e 100644 (file)
@@ -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.