ref: b190ad0ff9626f383945e137e66c0ae213f2c112
parent: f8a840a14c9ad2ffa0120e9540be0a250409bfd3
author: bep <[email protected]>
date: Thu Mar 12 16:50:44 EDT 2015
source: add some test cases for File
--- a/helpers/general.go
+++ b/helpers/general.go
@@ -75,6 +75,9 @@
// ReaderToBytes takes an io.Reader argument, reads from it
// and returns bytes.
func ReaderToBytes(lines io.Reader) []byte {
+ if lines == nil {
+ return []byte{}
+ }
b := bp.GetBuffer()
defer bp.PutBuffer(b)
@@ -87,6 +90,9 @@
// ReaderToString is the same as ReaderToBytes, but returns a string.
func ReaderToString(lines io.Reader) string {
+ if lines == nil {
+ return ""
+ }
b := bp.GetBuffer()
defer bp.PutBuffer(b)
b.ReadFrom(lines)
--- /dev/null
+++ b/source/file_test.go
@@ -1,0 +1,25 @@
+package source
+
+import (
+ "github.com/spf13/hugo/helpers"
+ "github.com/stretchr/testify/assert"
+ "testing"
+)
+
+func TestFileUniqueID(t *testing.T) {
+ f1 := File{uniqueID: "123"}
+ f2 := NewFile("a")
+
+ assert.Equal(t, "123", f1.UniqueID())
+ assert.Equal(t, "0cc175b9c0f1b6a831c399e269772661", f2.UniqueID())
+}
+
+func TestFileString(t *testing.T) {
+ assert.Equal(t, "abc", NewFileWithContents("a", helpers.StringToReader("abc")).String())
+ assert.Equal(t, "", NewFile("a").String())
+}
+
+func TestFileBytes(t *testing.T) {
+ assert.Equal(t, []byte("abc"), NewFileWithContents("a", helpers.StringToReader("abc")).Bytes())
+ assert.Equal(t, []byte(""), NewFile("a").Bytes())
+}