52 lines
2.5 KiB
Go
52 lines
2.5 KiB
Go
package markdown_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.akyoto.dev/go/assert"
|
|
"git.akyoto.dev/go/markdown"
|
|
)
|
|
|
|
func TestEmpty(t *testing.T) {
|
|
assert.Equal(t, markdown.Render(""), "")
|
|
}
|
|
|
|
func TestParagraph(t *testing.T) {
|
|
assert.Equal(t, markdown.Render("Text"), "<p>Text</p>")
|
|
assert.Equal(t, markdown.Render("Text\n"), "<p>Text</p>")
|
|
assert.Equal(t, markdown.Render("Text\n\n"), "<p>Text</p>")
|
|
assert.Equal(t, markdown.Render("Text\n\n\n"), "<p>Text</p>")
|
|
assert.Equal(t, markdown.Render("Line 1\nLine 2"), "<p>Line 1 Line 2</p>")
|
|
}
|
|
|
|
func TestHeader(t *testing.T) {
|
|
assert.Equal(t, markdown.Render("# Header"), "<h1>Header</h1>")
|
|
assert.Equal(t, markdown.Render("## Header"), "<h2>Header</h2>")
|
|
assert.Equal(t, markdown.Render("### Header"), "<h3>Header</h3>")
|
|
assert.Equal(t, markdown.Render("#### Header"), "<h4>Header</h4>")
|
|
assert.Equal(t, markdown.Render("##### Header"), "<h5>Header</h5>")
|
|
assert.Equal(t, markdown.Render("###### Header"), "<h6>Header</h6>")
|
|
}
|
|
|
|
func TestLink(t *testing.T) {
|
|
assert.Equal(t, markdown.Render("[text](https://example.com/)"), "<p><a href=\"https://example.com/\">text</a></p>")
|
|
assert.Equal(t, markdown.Render("[text](https://example.com/"), "<p>[text](https://example.com/</p>")
|
|
assert.Equal(t, markdown.Render("[text]https://example.com/)"), "<p>[text]https://example.com/)</p>")
|
|
assert.Equal(t, markdown.Render("[text(https://example.com/)"), "<p>[text(https://example.com/)</p>")
|
|
assert.Equal(t, markdown.Render("text](https://example.com/)"), "<p>text](https://example.com/)</p>")
|
|
assert.Equal(t, markdown.Render("Prefix [text](https://example.com/) suffix."), "<p>Prefix <a href=\"https://example.com/\">text</a> suffix.</p>")
|
|
}
|
|
|
|
func TestCombined(t *testing.T) {
|
|
assert.Equal(t, markdown.Render("# Header\nLine 1.\nLine 2.\nLine 3."), "<h1>Header</h1><p>Line 1. Line 2. Line 3.</p>")
|
|
assert.Equal(t, markdown.Render("# Header 1\nLine 1.\n# Header 2\nLine 2."), "<h1>Header 1</h1><p>Line 1.</p><h1>Header 2</h1><p>Line 2.</p>")
|
|
assert.Equal(t, markdown.Render("# [Header Link](https://example.com/)"), "<h1><a href=\"https://example.com/\">Header Link</a></h1>")
|
|
}
|
|
|
|
func TestSecurity(t *testing.T) {
|
|
assert.Equal(t, markdown.Render("[text](javascript:alert(\"xss\"))"), "<p><a href=\"\">text</a></p>")
|
|
assert.Equal(t, markdown.Render("[text](javAscRipt:alert(\"xss\"))"), "<p><a href=\"\">text</a></p>")
|
|
assert.Equal(t, markdown.Render("[text](\"><div>html</div>)"), "<p><a href=\""><div>html</div>\">text</a></p>")
|
|
assert.Equal(t, markdown.Render("[<div>html</div>]()"), "<p><a href=\"\"><div>html</div></a></p>")
|
|
}
|