mirror of
https://github.com/avelino/awesome-go.git
synced 2024-11-07 16:33:40 +00:00
add tests for new packages
This commit is contained in:
parent
85cd71ec7d
commit
3e62b1e787
57
pkg/markdown/convert_test.go
Normal file
57
pkg/markdown/convert_test.go
Normal 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))
|
||||||
|
}
|
||||||
|
}
|
39
pkg/slug/generator_test.go
Normal file
39
pkg/slug/generator_test.go
Normal 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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user