diff --git a/pkg/markdown/convert_test.go b/pkg/markdown/convert_test.go new file mode 100644 index 00000000..0efdf84e --- /dev/null +++ b/pkg/markdown/convert_test.go @@ -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 + +embedded HTML is allowed + `, + ) + expected := []byte( + `

some headline

+

followed by some paragraph with a link +and some list:

+ +

h3 headline/header

+

embedded HTML is allowed

`, + ) + + 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)) + } +} diff --git a/pkg/slug/generator_test.go b/pkg/slug/generator_test.go new file mode 100644 index 00000000..680ee332 --- /dev/null +++ b/pkg/slug/generator_test.go @@ -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) + } + }) + } +}