summaryrefslogtreecommitdiffstats
path: root/hugolib/page_test.go
diff options
context:
space:
mode:
authorNoah Campbell <noahcampbell@gmail.com>2013-09-03 14:51:06 -0700
committerNoah Campbell <noahcampbell@gmail.com>2013-09-03 14:51:06 -0700
commit207d8fb7af6d1b7bcb9753a290fd60e90f8e5e0c (patch)
treeb5c403db2d18de08f81d6dd7cfe51672fd709642 /hugolib/page_test.go
parent3ecc698f5e109610288b48b49c5ac2ee442a5ed0 (diff)
Date rendering unit tests in pages
Tests to ensure rendering dates in templates is working correctly. Actually, I was running into invalid templates not giving warnings when I was trying to render a date.
Diffstat (limited to 'hugolib/page_test.go')
-rw-r--r--hugolib/page_test.go21
1 files changed, 20 insertions, 1 deletions
diff --git a/hugolib/page_test.go b/hugolib/page_test.go
index f321a1655..7780a1cff 100644
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -2,6 +2,7 @@ package hugolib
import (
"path/filepath"
+ "time"
"strings"
"testing"
"html/template"
@@ -54,7 +55,7 @@ var SIMPLE_PAGE_JSON = `
Content of the file goes Here
`
-
+var SIMPLE_PAGE_RFC3339_DATE = "---\ntitle: RFC3339 Date\ndate: \"2013-05-17T16:59:30Z\"\n---\nrfc3339 content"
var SIMPLE_PAGE_JSON_MULTIPLE = `
{
"title": "foobar",
@@ -165,6 +166,12 @@ func checkPageLayout(t *testing.T, page *Page, layout string) {
}
}
+func checkPageDate(t *testing.T, page *Page, time time.Time) {
+ if page.Date != time {
+ t.Fatalf("Page date is: %s. Expected: %s", page.Date, time)
+ }
+}
+
func TestCreateNewPage(t *testing.T) {
p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE), "simple")
if err != nil {
@@ -202,6 +209,18 @@ func TestPageWithMoreTag(t *testing.T) {
checkPageLayout(t, p, "page/single.html")
}
+func TestPageWithDate(t *testing.T) {
+ p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE_RFC3339_DATE), "simple")
+ if err != nil {
+ t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
+ }
+ d, err := time.Parse(time.RFC3339, "2013-05-17T16:59:30Z")
+ if err != nil {
+ t.Fatalf("Unable to prase page.")
+ }
+ checkPageDate(t, p, d)
+}
+
func TestCreatePage(t *testing.T) {
var tests = []struct {
r string