mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-31 22:41:53 +02:00
helpers: Remove ToReader funcs
Remove StringToReader and BytesToReader in favor of using the stdlib directly.
This commit is contained in:
@@ -130,16 +130,6 @@ func ReaderToString(lines io.Reader) string {
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// StringToReader does the opposite of ReaderToString.
|
||||
func StringToReader(in string) io.Reader {
|
||||
return strings.NewReader(in)
|
||||
}
|
||||
|
||||
// BytesToReader does the opposite of ReaderToBytes.
|
||||
func BytesToReader(in []byte) io.Reader {
|
||||
return bytes.NewReader(in)
|
||||
}
|
||||
|
||||
// ReaderContains reports whether subslice is within r.
|
||||
func ReaderContains(r io.Reader, subslice []byte) bool {
|
||||
|
||||
|
@@ -14,10 +14,11 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGuessType(t *testing.T) {
|
||||
@@ -62,20 +63,6 @@ func TestFirstUpper(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBytesToReader(t *testing.T) {
|
||||
asBytes := ReaderToBytes(strings.NewReader("Hello World!"))
|
||||
asReader := BytesToReader(asBytes)
|
||||
assert.Equal(t, []byte("Hello World!"), asBytes)
|
||||
assert.Equal(t, asBytes, ReaderToBytes(asReader))
|
||||
}
|
||||
|
||||
func TestStringToReader(t *testing.T) {
|
||||
asString := ReaderToString(strings.NewReader("Hello World!"))
|
||||
assert.Equal(t, "Hello World!", asString)
|
||||
asReader := StringToReader(asString)
|
||||
assert.Equal(t, asString, ReaderToString(asReader))
|
||||
}
|
||||
|
||||
var containsTestText = (`На берегу пустынных волн
|
||||
Стоял он, дум великих полн,
|
||||
И вдаль глядел. Пред ним широко
|
||||
@@ -136,7 +123,7 @@ var containsAdditionalTestData = []struct {
|
||||
|
||||
func TestReaderContains(t *testing.T) {
|
||||
for i, this := range append(containsBenchTestData, containsAdditionalTestData...) {
|
||||
result := ReaderContains(StringToReader(this.v1), this.v2)
|
||||
result := ReaderContains(strings.NewReader(this.v1), this.v2)
|
||||
if result != this.expect {
|
||||
t.Errorf("[%d] got %t but expected %t", i, result, this.expect)
|
||||
}
|
||||
@@ -150,7 +137,7 @@ func BenchmarkReaderContains(b *testing.B) {
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for i, this := range containsBenchTestData {
|
||||
result := ReaderContains(StringToReader(this.v1), this.v2)
|
||||
result := ReaderContains(strings.NewReader(this.v1), this.v2)
|
||||
if result != this.expect {
|
||||
b.Errorf("[%d] got %t but expected %t", i, result, this.expect)
|
||||
}
|
||||
|
Reference in New Issue
Block a user