summaryrefslogtreecommitdiff
path: root/main_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'main_test.go')
-rw-r--r--main_test.go30
1 files changed, 23 insertions, 7 deletions
diff --git a/main_test.go b/main_test.go
index cf40a29..91f432b 100644
--- a/main_test.go
+++ b/main_test.go
@@ -24,7 +24,7 @@ func writeTestFile(t *testing.T, root, name, contents string) {
func testLayouts() string {
return `{{define "page"}}<html><head><title>{{.Title}}</title></head><body>{{joinSections .Sections}}</body></html>{{end}}
{{define "weblog"}}<html><head><title>{{.Title}}</title></head><body>{{joinSections .Sections}}</body></html>{{end}}
-{{define "note"}}{{template "page" .}}{{end}}`
+{{define "notes"}}{{template "page" .}}{{end}}`
}
func TestMarkdownGFMFrontmatterTitleSectionsAndLinks(t *testing.T) {
@@ -121,6 +121,10 @@ func TestOutputCollision(t *testing.T) {
func TestRelativePath(t *testing.T) {
cases := map[string]string{
relativePath("index.html", "style.css"): "style.css",
+ relativePath("index.html", "/"): "./",
+ relativePath("about/index.html", "/"): "../",
+ relativePath("index.html", "/notes/"): "notes/",
+ relativePath("about/index.html", "/notes/"): "../notes/",
relativePath("notes/deep/page.html", "style.css"): "../../style.css",
relativePath("notes/page.html", "/feed.xml"): "../feed.xml",
relativePath("notes/page.html", "https://example.com"): "https://example.com",
@@ -132,16 +136,28 @@ func TestRelativePath(t *testing.T) {
}
}
-func TestPathSelectsMarkdownLayout(t *testing.T) {
+func TestMarkdownTemplateFallsThroughPathThenFallback(t *testing.T) {
root := t.TempDir()
- writeTestFile(t, root, "layouts.tmpl", `{{define "page"}}page:{{.Title}}{{end}}{{define "weblog"}}post:{{.Title}}{{end}}{{define "note"}}note:{{.Title}}{{end}}`)
+ writeTestFile(t, root, "layouts.tmpl", `{{define "default"}}default:{{.Title}}{{end}}
+{{define "notes"}}notes:{{.Title}}{{end}}
+{{define "notes/recipes"}}recipes:{{.Title}}{{end}}
+{{define "notes/recipes/cocktails"}}cocktails:{{.Title}}{{end}}
+{{define "notes/recipes/cocktails/old_fashioned"}}exact:{{.Title}}{{end}}`)
writeTestFile(t, root, "about.md", "# About\n")
- writeTestFile(t, root, "weblog/post.md", "# Post\n")
- writeTestFile(t, root, "notes/item.md", "# Item\n")
- if err := build(root); err != nil {
+ writeTestFile(t, root, "notes/todo.md", "# Todo\n")
+ writeTestFile(t, root, "notes/recipes/bread.md", "# Bread\n")
+ writeTestFile(t, root, "notes/recipes/cocktails/stirred.md", "# Stirred\n")
+ writeTestFile(t, root, "notes/recipes/cocktails/old_fashioned.md", "# Old Fashioned\n")
+ if err := buildWithFallback(root, "default"); err != nil {
t.Fatal(err)
}
- for name, want := range map[string]string{"about.html": "page:About", "weblog/post.html": "post:Post", "notes/item.html": "note:Item"} {
+ for name, want := range map[string]string{
+ "about.html": "default:About",
+ "notes/todo.html": "notes:Todo",
+ "notes/recipes/bread.html": "recipes:Bread",
+ "notes/recipes/cocktails/stirred.html": "cocktails:Stirred",
+ "notes/recipes/cocktails/old_fashioned.html": "exact:Old Fashioned",
+ } {
raw, err := os.ReadFile(filepath.Join(root, filepath.FromSlash(name)))
if err != nil {
t.Fatal(err)