summaryrefslogtreecommitdiff
path: root/main_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'main_test.go')
-rw-r--r--main_test.go19
1 files changed, 14 insertions, 5 deletions
diff --git a/main_test.go b/main_test.go
index f2aae0a..a1eda14 100644
--- a/main_test.go
+++ b/main_test.go
@@ -38,6 +38,8 @@ func TestMarkdownGFMFrontmatterTitleSectionsAndLinks(t *testing.T) {
writeTestFile(t, root, "page.md", `---
summary: hello
---
+> Read this first.
+
# My *Page*
First paragraph with [local](other.md#part), [web](https://example.com/a.md), and [fragment](#part).
@@ -56,13 +58,16 @@ First paragraph with [local](other.md#part), [web](https://example.com/a.md), an
t.Fatal(err)
}
got := string(raw)
- for _, want := range []string{"<title>My Page</title>", `href="other.html#part"`, `href="https://example.com/a.md"`, `href="#part"`, "<table>"} {
+ for _, want := range []string{"<title>My Page</title>", "<blockquote>", "<h1", `href="other.html#part"`, `href="https://example.com/a.md"`, `href="#part"`, "<table>"} {
if !strings.Contains(got, want) {
t.Errorf("output missing %q:\n%s", want, got)
}
}
- if strings.Contains(got, "<h1") || strings.Contains(got, "<script>") {
- t.Errorf("H1 duplicated or raw HTML rendered:\n%s", got)
+ if strings.Index(got, "<blockquote>") > strings.Index(got, "<h1") {
+ t.Errorf("sections rendered out of source order:\n%s", got)
+ }
+ if strings.Contains(got, "<script>") {
+ t.Errorf("raw HTML rendered:\n%s", got)
}
s := &site{root: root, pages: map[string][]*Page{}}
@@ -75,7 +80,7 @@ First paragraph with [local](other.md#part), [web](https://example.com/a.md), an
page = src.page
}
}
- if page == nil || page.Meta["summary"] != "hello" || len(page.Sections) != 3 {
+ if page == nil || page.Meta["summary"] != "hello" || len(page.Sections) != 5 {
t.Fatalf("unexpected page model: %#v", page)
}
}
@@ -350,10 +355,14 @@ func TestGitignoreTracksOnlyCurrentGeneratedOutputs(t *testing.T) {
func TestSortingFilteringSlicing(t *testing.T) {
a := &Page{Title: "A", Meta: map[string]any{"post_date": "2024-01-01", "kind": "x"}, ModTime: time.Unix(1, 0)}
- b := &Page{Title: "B", Meta: map[string]any{"post_date": "2025-01-01", "kind": "y"}, ModTime: time.Unix(2, 0)}
+ b := &Page{Title: "B", Meta: map[string]any{"post_date": "2025-01-01", "kind": "y"}, ModTime: time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)}
if got := sortPages([]*Page{a, b}, "post_date"); got[0] != b {
t.Fatal("date sort")
}
+ b.Meta["post_date"] = "invalid"
+ if got := sortPages([]*Page{a, b}, "post_date", "mod_time"); got[0] != b {
+ t.Fatal("date fallback sort")
+ }
if got := filterPages([]*Page{a, b}, "kind", "x"); len(got) != 1 || got[0] != a {
t.Fatal("filter")
}