}
func TestDegenerateEmptyPageZeroLengthName(t *testing.T) {
- _, err := ReadFrom(strings.NewReader(EMPTY_PAGE), "")
+
+ _, err := NewPage("")
if err == nil {
t.Fatalf("A zero length page name must return an error")
}
}
func TestDegenerateEmptyPage(t *testing.T) {
- _, err := ReadFrom(strings.NewReader(EMPTY_PAGE), "test")
+ _, err := NewPageFrom(strings.NewReader(EMPTY_PAGE), "test")
if err != nil {
t.Fatalf("Empty files should not trigger an error. Should be able to touch a file while watching without erroring out.")
}
-
- //checkError(t, err, "EOF")
}
func checkPageTitle(t *testing.T, page *Page, title string) {
}
func TestCreateNewPage(t *testing.T) {
- p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE), "simple.md")
+ p, _ := NewPage("simple.md")
+ err := p.ReadFrom(strings.NewReader(SIMPLE_PAGE))
p.Convert()
if err != nil {
}
func TestPageWithDelimiter(t *testing.T) {
- p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE_WITH_SUMMARY_DELIMITER), "simple.md")
+ p, _ := NewPage("simple.md")
+ err := p.ReadFrom(strings.NewReader(SIMPLE_PAGE_WITH_SUMMARY_DELIMITER))
p.Convert()
if err != nil {
t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
}
func TestPageWithShortCodeInSummary(t *testing.T) {
- p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE_WITH_SHORTCODE_IN_SUMMARY), "simple.md")
+ p, _ := NewPage("simple.md")
+ err := p.ReadFrom(strings.NewReader(SIMPLE_PAGE_WITH_SHORTCODE_IN_SUMMARY))
p.Convert()
if err != nil {
t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
}
func TestTableOfContents(t *testing.T) {
- p, err := ReadFrom(strings.NewReader(PAGE_WITH_TOC), "tocpage.md")
+ p, _ := NewPage("tocpage.md")
+ err := p.ReadFrom(strings.NewReader(PAGE_WITH_TOC))
p.Convert()
if err != nil {
t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
}
func TestPageWithMoreTag(t *testing.T) {
- p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE_WITH_SUMMARY_DELIMITER_SAME_LINE), "simple.md")
+ p, _ := NewPage("simple.md")
+ err := p.ReadFrom(strings.NewReader(SIMPLE_PAGE_WITH_SUMMARY_DELIMITER_SAME_LINE))
p.Convert()
if err != nil {
t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
}
func TestPageWithDate(t *testing.T) {
- p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE_RFC3339_DATE), "simple")
+ p, _ := NewPage("simple.md")
+ err := p.ReadFrom(strings.NewReader(SIMPLE_PAGE_RFC3339_DATE))
p.Convert()
if err != nil {
t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
}
func TestWordCount(t *testing.T) {
- p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE_WITH_LONG_CONTENT), "simple.md")
+ p, _ := NewPage("simple.md")
+ err := p.ReadFrom(strings.NewReader(SIMPLE_PAGE_WITH_LONG_CONTENT))
p.Convert()
p.analyzePage()
if err != nil {
}
for _, test := range tests {
- if _, err := ReadFrom(strings.NewReader(test.r), "page"); err != nil {
+ p, _ := NewPage("page")
+ if err := p.ReadFrom(strings.NewReader(test.r)); err != nil {
t.Errorf("Unable to parse page: %s", err)
}
}
{INVALID_FRONT_MATTER_SHORT_DELIM_ENDING, "Unable to read frontmatter at filepos 45: EOF"},
}
for _, test := range tests {
- _, err := ReadFrom(strings.NewReader(test.r), "invalid/front/matter/short/delim")
+
+ p, _ := NewPage("invalid/front/matter/short/delim")
+ err := p.ReadFrom(strings.NewReader(test.r))
checkError(t, err, test.err)
}
}
}
for _, test := range tests {
- p := pageMust(ReadFrom(strings.NewReader(test.text), "render/front/matter"))
+
+ p, _ := NewPage("render/front/matter")
+ err := p.ReadFrom(strings.NewReader(test.text))
+ p = pageMust(p, err)
if p.IsRenderable() != test.render {
t.Errorf("expected p.IsRenderable() == %t, got %t", test.render, p.IsRenderable())
}
}
func TestDifferentFrontMatterVarTypes(t *testing.T) {
- page, _ := ReadFrom(strings.NewReader(PAGE_WITH_VARIOUS_FRONTMATTER_TYPES), "test/file1.md")
+ page, _ := NewPage("test/file1.md")
+ _ = page.ReadFrom(strings.NewReader(PAGE_WITH_VARIOUS_FRONTMATTER_TYPES))
dateval, _ := time.Parse(time.RFC3339, "1979-05-27T07:32:00Z")
if page.GetParam("a_string") != "bar" {
}
func TestDegenerateInvalidFrontMatterLeadingWhitespace(t *testing.T) {
- _, err := ReadFrom(strings.NewReader(INVALID_FRONT_MATTER_LEADING_WS), "invalid/front/matter/leading/ws")
+ p, _ := NewPage("invalid/front/matter/leading/ws")
+ err := p.ReadFrom(strings.NewReader(INVALID_FRONT_MATTER_LEADING_WS))
if err != nil {
t.Fatalf("Unable to parse front matter given leading whitespace: %s", err)
}
}
func TestSectionEvaluation(t *testing.T) {
- page, _ := ReadFrom(strings.NewReader(SIMPLE_PAGE), "blue/file1.md")
+ page, _ := NewPage("blue/file1.md")
+ page.ReadFrom(strings.NewReader(SIMPLE_PAGE))
if page.Section != "blue" {
t.Errorf("Section should be %s, got: %s", "blue", page.Section)
}
{SIMPLE_PAGE_TYPE_LAYOUT, path_no_directory, L("barfoo/buzfoo.html", "buzfoo.html")},
}
for _, test := range tests {
- p, err := ReadFrom(strings.NewReader(test.content), test.path)
+ p, _ := NewPage(test.path)
+ err := p.ReadFrom(strings.NewReader(test.content))
if err != nil {
t.Fatalf("Unable to parse content:\n%s\n", test.content)
}
}
func TestDegenerateRenderThingMissingTemplate(t *testing.T) {
- p, _ := ReadFrom(strings.NewReader(PAGE_SIMPLE_TITLE), "content/a/file.md")
+ p, _ := NewPageFrom(strings.NewReader(PAGE_SIMPLE_TITLE), "content/a/file.md")
p.Convert()
s := new(Site)
s.prepTemplates()
s.prepTemplates()
for i, test := range tests {
- p, err := ReadFrom(strings.NewReader(test.content), "content/a/file.md")
+ p, err := NewPageFrom(strings.NewReader(test.content), "content/a/file.md")
p.Convert()
if err != nil {
t.Fatalf("Error parsing buffer: %s", err)
s.prepTemplates()
for i, test := range tests {
- p, err := ReadFrom(strings.NewReader(PAGE_SIMPLE_TITLE), "content/a/file.md")
+ p, err := NewPageFrom(strings.NewReader(PAGE_SIMPLE_TITLE), "content/a/file.md")
if err != nil {
t.Fatalf("Error parsing buffer: %s", err)
}
}
for _, test := range tests {
- p := pageMust(ReadFrom(strings.NewReader(test.content), helpers.AbsPathify(test.doc)))
+ p := pageMust(NewPageFrom(strings.NewReader(test.content), helpers.AbsPathify(test.doc)))
expected := test.expectedOutFile