draft shits
This commit is contained in:
52
internal/render/render_test.go
Normal file
52
internal/render/render_test.go
Normal file
@ -0,0 +1,52 @@
|
||||
package render
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRenderMarkdown(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
markdown string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "Markdown, no link",
|
||||
markdown: `# Test
|
||||
|
||||
## 01/24/26 09:14:20 - some entry
|
||||
check this out`,
|
||||
want: `<h1>Test</h1><h2>01/24/26 09:14:20 - some entry</h2><p>check this out</p>`,
|
||||
},
|
||||
{
|
||||
name: "Markdown, some link",
|
||||
markdown: `# Test 2
|
||||
## 01/24/26 09:14:20 - some entry (bare link)
|
||||
Check this out http://tatata.toto here
|
||||
`,
|
||||
want: `<h1>Test 2</h1><h2>01/24/26 09:14:20 - some entry (bare link)</h2><p>Check this out <a href="http://tatata.toto" target="_blank">http://tatata.toto</a> here</p>`,
|
||||
},
|
||||
{
|
||||
name: "Markdown, some link with description",
|
||||
markdown: `# Test 2
|
||||
## 01/24/26 09:14:20 - some entry (bare link)
|
||||
Check this out [here](http://tatata.toto)
|
||||
`,
|
||||
want: `<h1>Test 2</h1><h2>01/24/26 09:14:20 - some entry (bare link)</h2><p>Check this out <a href="http://tatata.toto" target="_blank">here</a></p>`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range cases {
|
||||
got, err := RenderMarkdown([]byte(test.markdown))
|
||||
if err != nil {
|
||||
t.Errorf("Error rendering markdown: '%s'\n", err)
|
||||
}
|
||||
strip := strings.ReplaceAll(string(got), "\n", "")
|
||||
strip = strings.Trim(strip, " ")
|
||||
|
||||
if strip != test.want {
|
||||
t.Errorf("Rendering markdown: Wanted '%s', got '%s'.\n", test.want, strip)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user