From c8e10b6c5ab26d8bd34c288a7ce91c320862b58e Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 10 Apr 2026 09:46:59 +0300 Subject: 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 --- internal/processor/txt_test.go | 120 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 internal/processor/txt_test.go (limited to 'internal/processor/txt_test.go') diff --git a/internal/processor/txt_test.go b/internal/processor/txt_test.go new file mode 100644 index 0000000..bb44c28 --- /dev/null +++ b/internal/processor/txt_test.go @@ -0,0 +1,120 @@ +package processor + +import ( + "strings" + "testing" +) + +func TestStripURLTrailing(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + in string + want string + }{ + {name: "plain", in: "https://example.com", want: "https://example.com"}, + {name: "trailing period", in: "https://example.com.", want: "https://example.com"}, + {name: "multiple punctuation", in: "https://a.b/c).", want: "https://a.b/c"}, + {name: "empty", in: "", want: ""}, + {name: "only punctuation", in: "...", want: ""}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got := stripURLTrailing(tt.in) + if got != tt.want { + t.Fatalf("stripURLTrailing(%q) = %q; want %q", tt.in, got, tt.want) + } + }) + } +} + +func TestAutolinkLine(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + in string + want string + }{ + { + name: "no url escapes", + in: `hello `, + want: `hello <world>`, + }, + { + name: "single url", + in: "see https://foo.test ok", + want: `see https://foo.test ok`, + }, + { + name: "url with trailing period in prose", + in: "Visit https://foo.test.", + want: `Visit https://foo.test.`, + }, + { + name: "two urls", + in: "a http://a.com b https://b.org c", + want: `a http://a.com b https://b.org c`, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got := autolinkLine(tt.in) + if got != tt.want { + t.Fatalf("autolinkLine(%q) = %q; want %q", tt.in, got, tt.want) + } + }) + } +} + +func TestFormatParagraph(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + in string + want string + }{ + { + name: "single line", + in: "hello", + want: "hello", + }, + { + name: "line break", + in: "line one\nline two", + want: "line one
\nline two", + }, + { + name: "skips blank lines inside para", + in: "a\n\nb", + want: "a
\nb", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got := formatParagraph(tt.in) + if got != tt.want { + t.Fatalf("formatParagraph(%q) = %q; want %q", tt.in, got, tt.want) + } + }) + } +} + +func TestFormatParagraph_autolinkMultiline(t *testing.T) { + t.Parallel() + got := formatParagraph("u https://x.y\nv") + if !strings.Contains(got, `") { + t.Fatalf("expected br between lines, got %q", got) + } +} -- cgit v1.2.3