mirror of
https://github.com/gohugoio/hugo.git
synced 2025-01-23 23:22:42 +00:00
Add some more corner tests for ReaderContains
This commit is contained in:
parent
be1429fa88
commit
be21e2cbed
2 changed files with 6 additions and 2 deletions
|
@ -115,7 +115,7 @@ func BytesToReader(in []byte) io.Reader {
|
|||
// ReaderContains reports whether subslice is within r.
|
||||
func ReaderContains(r io.Reader, subslice []byte) bool {
|
||||
|
||||
if len(subslice) == 0 {
|
||||
if r == nil || len(subslice) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ var containsBenchTestData = []struct {
|
|||
{"abc", []byte("d"), false},
|
||||
{containsTestText, []byte("стремился"), true},
|
||||
{containsTestText, []byte(containsTestText[10:80]), true},
|
||||
{containsTestText, []byte(containsTestText[100:110]), true},
|
||||
{containsTestText, []byte(containsTestText[100:111]), true},
|
||||
{containsTestText, []byte(containsTestText[len(containsTestText)-100 : len(containsTestText)-10]), true},
|
||||
{containsTestText, []byte(containsTestText[len(containsTestText)-20:]), true},
|
||||
{containsTestText, []byte("notfound"), false},
|
||||
|
@ -98,6 +98,7 @@ var containsAdditionalTestData = []struct {
|
|||
v2 []byte
|
||||
expect bool
|
||||
}{
|
||||
{"", nil, false},
|
||||
{"", []byte("a"), false},
|
||||
{"a", []byte(""), false},
|
||||
{"", []byte(""), false},
|
||||
|
@ -110,6 +111,9 @@ func TestReaderContains(t *testing.T) {
|
|||
t.Errorf("[%d] Got %t but expected %t", i, result, this.expect)
|
||||
}
|
||||
}
|
||||
|
||||
assert.False(t, ReaderContains(nil, []byte("a")))
|
||||
assert.False(t, ReaderContains(nil, nil))
|
||||
}
|
||||
|
||||
func BenchmarkReaderContains(b *testing.B) {
|
||||
|
|
Loading…
Reference in a new issue