Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbep <bjorn.erik.pedersen@gmail.com>2015-03-30 02:22:08 +0300
committerbep <bjorn.erik.pedersen@gmail.com>2015-03-30 02:22:09 +0300
commitbe21e2cbed6c7832d060c7c186459e9f6b7de238 (patch)
tree24e4171377f21a60cb0f2de12d23ae13f3de9fcb /helpers
parentbe1429fa88a5d872b568bf89cdc4ab4745a9f69b (diff)
Add some more corner tests for ReaderContains
Diffstat (limited to 'helpers')
-rw-r--r--helpers/general.go2
-rw-r--r--helpers/general_test.go6
2 files changed, 6 insertions, 2 deletions
diff --git a/helpers/general.go b/helpers/general.go
index baf957d75..14cce5cf0 100644
--- a/helpers/general.go
+++ b/helpers/general.go
@@ -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
}
diff --git a/helpers/general_test.go b/helpers/general_test.go
index 496439db1..26aba6701 100644
--- a/helpers/general_test.go
+++ b/helpers/general_test.go
@@ -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) {