1
0
Fork 0
timelinize/timeline/processor_test.go
Sergio Rubio 304f8638c5
Test for couldBeMarkdown (#46)
* Test for couldBeMarkdown

couldBeMarkdown is greedy, and makes the processing[^1] step set the content
type of HTML and plain text files as text/markdown.

This has the side effect of excluding text file from in database
storage, since that only happens for text/plain files[^2]

[^1]: 8f0f491ad5/timeline/processing.go (L1479)
[^2]: https://github.com/timelinize/timelinize/pull/45#issuecomment-2325018564

* Add HTML test

* gofmt
2024-09-04 09:21:49 -06:00

56 lines
1 KiB
Go

package timeline
import "testing"
func TestCouldBeMarkdown(t *testing.T) {
tests := []struct {
name string
input string
expected bool
}{
{
name: "Empty string",
input: "",
expected: false,
},
{
name: "Plain text",
input: "Hello, world!",
expected: false,
},
{
name: "Markdown headers",
input: "# Header 1\n## Header 2",
expected: true,
},
{
name: "Markdown list",
input: "- Item 1\n- Item 2\n- Item 3",
expected: true,
},
{
name: "Markdown link",
input: "[Link text](https://example.com)",
expected: true,
},
{
name: "Markdown code block",
input: "```\ncode block\n```",
expected: true,
},
{
name: "HTML",
input: `<!DOCTYPE html><html lang="en"></html>`,
expected: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := couldBeMarkdown([]byte(tt.input))
if result != tt.expected {
t.Errorf("couldBeMarkdown(%q) = %v, want %v", tt.input, result, tt.expected)
}
})
}
}