1
0
Fork 0
mirror of https://github.com/avelino/awesome-go.git synced 2024-11-20 11:16:22 -05:00

add tests for new packages

This commit is contained in:
Benjamin Schoch 2022-08-31 17:02:21 +02:00 committed by Avelino
parent 85cd71ec7d
commit 3e62b1e787
2 changed files with 96 additions and 0 deletions

View file

@ -0,0 +1,57 @@
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))
}
}

View file

@ -0,0 +1,39 @@
package slug
import "testing"
func TestGenerate(t *testing.T) {
tests := []struct {
name string
input string
expected string
}{
{
name: "with spaces",
input: "some string with spaces",
expected: "some-string-with-spaces",
},
{
name: "with out any non-literal chars",
input: "inputstring",
expected: "inputstring",
},
{
name: "with whitespace prefix and suffix",
input: " inputstring ",
expected: "inputstring",
},
{
name: "a mix of special characters",
input: " an input string (with.special/chars,such_as:§\\?$/§&!) ",
expected: "an-input-string-with-specialchars-such-as",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Generate(tt.input); got != tt.expected {
t.Errorf("Generate() = %v, want %v", got, tt.expected)
}
})
}
}