diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-10 09:46:59 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-10 09:46:59 +0300 |
| commit | c8e10b6c5ab26d8bd34c288a7ce91c320862b58e (patch) | |
| tree | 107e842ca542c80cdf187017251ef6d4d63d597a /internal/processor/markdown_test.go | |
| parent | 53ad6846aa7506b621cd38f4933442379638a01d (diff) | |
test: add table-driven unit tests for post, processor, generator
Cover NewID; txt autolink helpers; markdown local image discovery;
pagination, page filenames, JSON script literals, time formatting,
and buildPageData nav links.
Made-with: Cursor
Diffstat (limited to 'internal/processor/markdown_test.go')
| -rw-r--r-- | internal/processor/markdown_test.go | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/internal/processor/markdown_test.go b/internal/processor/markdown_test.go new file mode 100644 index 0000000..a17b704 --- /dev/null +++ b/internal/processor/markdown_test.go @@ -0,0 +1,90 @@ +package processor + +import ( + "os" + "path/filepath" + "testing" +) + +func TestFindLocalImages(t *testing.T) { + t.Parallel() + + t.Run("remote skipped", func(t *testing.T) { + t.Parallel() + dir := t.TempDir() + got := findLocalImages(` `, dir) + if len(got) != 0 { + t.Fatalf("expected no locals, got %v", got) + } + }) + + t.Run("missing file ignored", func(t *testing.T) { + t.Parallel() + dir := t.TempDir() + got := findLocalImages(``, dir) + if len(got) != 0 { + t.Fatalf("expected no locals, got %v", got) + } + }) + + t.Run("picks existing basename", func(t *testing.T) { + t.Parallel() + dir := t.TempDir() + if err := os.WriteFile(filepath.Join(dir, "shot.png"), []byte("x"), 0o644); err != nil { + t.Fatal(err) + } + got := findLocalImages(``, dir) + if len(got) != 1 || got[0] != "shot.png" { + t.Fatalf("got %v; want [shot.png]", got) + } + }) + + tests := []struct { + name string + md string + files []string + want []string + wantLen int + }{ + { + name: "multiple locals order", + md: ` `, + files: []string{"a.png", "b.png"}, + wantLen: 2, + }, + { + name: "alt with spaces", + md: ``, + files: []string{"z.gif"}, + want: []string{"z.gif"}, + wantLen: 1, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + dir := t.TempDir() + for _, f := range tt.files { + if err := os.WriteFile(filepath.Join(dir, f), []byte("x"), 0o644); err != nil { + t.Fatal(err) + } + } + got := findLocalImages(tt.md, dir) + if tt.want != nil { + if len(got) != len(tt.want) { + t.Fatalf("got %v; want %v", got, tt.want) + } + for i := range tt.want { + if got[i] != tt.want[i] { + t.Fatalf("got %v; want %v", got, tt.want) + } + } + return + } + if len(got) != tt.wantLen { + t.Fatalf("len(got)=%d; want %d (%v)", len(got), tt.wantLen, got) + } + }) + } +} |
