hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit b190ad0ff9626f383945e137e66c0ae213f2c112
parent f8a840a14c9ad2ffa0120e9540be0a250409bfd3
Author: bep <bjorn.erik.pedersen@gmail.com>
Date:   Thu, 12 Mar 2015 20:50:44 +0100

source: add some test cases for File

Diffstat:
Mhelpers/general.go | 6++++++
Asource/file_test.go | 25+++++++++++++++++++++++++
2 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/helpers/general.go b/helpers/general.go
@@ -75,6 +75,9 @@ func GuessType(in string) string {
 // 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 @@ func ReaderToBytes(lines io.Reader) []byte {
 
 // 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)
diff --git a/source/file_test.go b/source/file_test.go
@@ -0,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())
+}