Introduce unit testing for page.go

This commit is contained in:
Noah Campbell 2013-08-04 19:02:15 -07:00
parent fa55cd9857
commit 274d324c8b
3 changed files with 24 additions and 9 deletions

View file

@ -78,10 +78,9 @@ func (p Pages) Limit(n int) Pages { return p[0:n] }
func initializePage(filename string) (page Page) {
page = Page{contentType: "",
File: File{FileName: filename,
Extension: "html"},
Params: make(map[string]interface{}),
File: File{FileName: filename, Extension: "html"},
Node: Node{Keywords: make([]string, 10, 30)},
Params: make(map[string]interface{}),
Markup: "md"}
page.Date, _ = time.Parse("20060102", "20080101")
page.setSection()

View file

@ -1,17 +1,33 @@
package hugolib
import (
"testing"
"path/filepath"
"testing"
)
func TestDegenerateMissingFolderInPageFilename(t *testing.T) {
p := NewPage(filepath.Join("foobar"))
if p != nil {
t.Fatalf("Creating a new Page without a subdirectory should result in nil page")
if p.Section != "" {
t.Fatalf("No section should be set for a file path: foobar")
}
}
func TestCreateNewPage(t *testing.T) {
toCheck := []map[string]string{
{"input": filepath.Join("sub", "foobar.html"), "expect": "sub"},
{"input": filepath.Join("content", "sub", "foobar.html"), "expect": "sub"},
{"input": filepath.Join("content", "dub", "sub", "foobar.html"), "expect": "sub"},
}
for _, el := range toCheck {
p := NewPage(el["input"])
if p.Section != el["expect"] {
t.Fatalf("Section not set to %s for page %s. Got: %s", el["expect"], el["input"], p.Section)
}
}
}
func TestSettingOutFileOnPageContainsCorrectSlashes(t *testing.T) {
s := NewSite(&Config{})
p := NewPage(filepath.Join("sub", "foobar"))