mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
bytes: add test for Contains
R=golang-codereviews, dave CC=golang-codereviews https://golang.org/cl/46140043
This commit is contained in:
parent
42cea1a452
commit
872f5ffa09
1 changed files with 18 additions and 0 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue