1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-12-03 14:17:47 +01:00
gojekyll/renderers/markdown_test.go

40 lines
1.3 KiB
Go
Raw Normal View History

2017-08-18 17:07:01 +02:00
package renderers
2017-08-11 23:16:49 +02:00
import (
2017-08-22 16:47:34 +02:00
"log"
2017-08-11 23:16:49 +02:00
"testing"
"github.com/stretchr/testify/require"
)
2017-08-22 16:47:34 +02:00
func TestRenderMarkdown(t *testing.T) {
require.Equal(t, "<p><em>b</em></p>\n", mustMarkdownString("*b*"))
require.Equal(t, "<div>*b*</div>\n", mustMarkdownString("<div>*b*</div>"))
require.Equal(t, "<div a=1><p><em>b</em></p>\n</div>\n", mustMarkdownString(`<div a=1 markdown="1">*b*</div>`))
require.Equal(t, "<div a=1><p><em>b</em></p>\n</div>\n", mustMarkdownString(`<div a=1 markdown='1'>*b*</div>`))
require.Equal(t, "<div a=1><p><em>b</em></p>\n</div>\n", mustMarkdownString(`<div a=1 markdown=1>*b*</div>`))
_, err := renderMarkdownString(`<div a=1 markdown=1><p></div>`)
require.NotNil(t, err)
require.Contains(t, err.Error(), "EOF")
require.Contains(t, mustMarkdownString(`<div markdown=1><user@example.com></div>`), `<a href="mailto:user@example.com">user@example.com</a>`)
require.Contains(t, mustMarkdownString(`<div markdown=1><http://example.com></div>`), `<a href="http://example.com">http://example.com</a>`)
2017-08-11 23:16:49 +02:00
}
2017-08-22 16:47:34 +02:00
func mustMarkdownString(md string) string {
s, err := renderMarkdown([]byte(md))
if err != nil {
log.Fatal(err)
}
return string(s)
}
func renderMarkdownString(md string) (string, error) {
s, err := renderMarkdown([]byte(md))
if err != nil {
return "", err
}
return string(s), err
2017-08-11 23:16:49 +02:00
}