diff options
Diffstat (limited to 'hugolib/page_test.go')
-rw-r--r-- | hugolib/page_test.go | 63 |
1 files changed, 55 insertions, 8 deletions
diff --git a/hugolib/page_test.go b/hugolib/page_test.go index 0f80e3a96..a2a4999df 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -2,9 +2,10 @@ package hugolib import ( "html/template" - "path/filepath" + "path" "strings" "testing" + "time" ) var EMPTY_PAGE = "" @@ -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", @@ -100,6 +101,14 @@ Simple Page Some more text ` +var SIMPLE_PAGE_WITH_SUMMARY_DELIMITER_SAME_LINE = `--- +title: Simple +--- +Simple Page<!--more--> + +Some more text +` + func checkError(t *testing.T, err error, expected string) { if err == nil { t.Fatalf("err is nil") @@ -157,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 { @@ -175,12 +190,37 @@ func TestPageWithDelimiter(t *testing.T) { t.Fatalf("Unable to create a page with frontmatter and body content: %s", err) } checkPageTitle(t, p, "Simple") - checkPageContent(t, p, "<p>Simple Page</p>\n\n<!--more-->\n\n<p>Some more text</p>\n") + checkPageContent(t, p, "<p>Simple Page</p>\n\n<p>Some more text</p>\n") + checkPageSummary(t, p, "<p>Simple Page</p>\n") + checkPageType(t, p, "page") + checkPageLayout(t, p, "page/single.html") + +} + +func TestPageWithMoreTag(t *testing.T) { + p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE_WITH_SUMMARY_DELIMITER_SAME_LINE), "simple") + if err != nil { + t.Fatalf("Unable to create a page with frontmatter and body content: %s", err) + } + checkPageTitle(t, p, "Simple") + checkPageContent(t, p, "<p>Simple Page</p>\n\n<p>Some more text</p>\n") checkPageSummary(t, p, "<p>Simple Page</p>\n") checkPageType(t, p, "page") 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 @@ -219,13 +259,20 @@ func TestDegenerateInvalidFrontMatterLeadingWhitespace(t *testing.T) { } } +func TestSectionEvaluation(t *testing.T) { + page, _ := ReadFrom(strings.NewReader(SIMPLE_PAGE), "blue/file1.md") + if page.Section != "blue" { + t.Errorf("Section should be %s, got: %s", "blue", page.Section) + } +} + func TestLayoutOverride(t *testing.T) { var ( - path_content_one_dir = filepath.Join("content", "gub", "file1.md") - path_content_two_dir = filepath.Join("content", "dub", "sub", "file1.md") - path_content_no_dir = filepath.Join("content", "file1") - path_one_directory = filepath.Join("fub", "file1.md") - path_no_directory = filepath.Join("file1.md") + path_content_one_dir = path.Join("content", "gub", "file1.md") + path_content_two_dir = path.Join("content", "dub", "sub", "file1.md") + path_content_no_dir = path.Join("content", "file1") + path_one_directory = path.Join("fub", "file1.md") + path_no_directory = path.Join("file1.md") ) tests := []struct { content string |