1
0
Fork 0
mirror of https://github.com/avelino/awesome-go.git synced 2024-11-13 11:14:37 -05:00
go/pkg/markdown/convert_test.go
2022-09-19 06:44:12 -03:00

57 lines
1.3 KiB
Go

package markdown
import (
"strings"
"testing"
)
func TestConvertMarkdownToHTML(t *testing.T) {
input := []byte(
`## some headline
followed by some paragraph with [a link](https://example.local)
and some list:
- first
- second
- nested on second level
- nested on third level
- ~~strikethrough~~
- yet another second level item, **but** with a [a link](https://example.local)
- end
### h3 headline/header
<a href="https://example.local">embedded HTML is allowed</a>
`,
)
expected := []byte(
`<h2 id="some-headline">some headline</h2>
<p>followed by some paragraph with <a href="https://example.local">a link</a>
and some list:</p>
<ul>
<li>first</li>
<li>second
<ul>
<li>nested on second level
<ul>
<li>nested on third level</li>
<li><del>strikethrough</del></li>
</ul>
</li>
<li>yet another second level item, <strong>but</strong> with a <a href="https://example.local">a link</a></li>
</ul>
</li>
<li>end</li>
</ul>
<h3 id="h3-headlineheader">h3 headline/header</h3>
<p><a href="https://example.local">embedded HTML is allowed</a></p>`,
)
got, err := ConvertMarkdownToHTML(input)
if err != nil {
t.Errorf("ConvertMarkdownToHTML() error = %v", err)
return
}
if strings.TrimSpace(string(got)) != strings.TrimSpace(string(expected)) {
t.Errorf("ConvertMarkdownToHTML() got = %v, want %v", string(got), string(expected))
}
}