goldmark/commonmark_test.go

42 lines
888 B
Go

package goldmark
import (
"encoding/json"
"io/ioutil"
"testing"
"github.com/yuin/goldmark/renderer/html"
)
type commonmarkSpecTestCase struct {
Markdown string `json:"markdown"`
HTML string `json:"html"`
Example int `json:"example"`
StartLine int `json:"start_line"`
EndLine int `json:"end_line"`
Section string `json:"section"`
}
func TestSpec(t *testing.T) {
bs, err := ioutil.ReadFile("_test/spec.json")
if err != nil {
panic(err)
}
var testCases []commonmarkSpecTestCase
if err := json.Unmarshal(bs, &testCases); err != nil {
panic(err)
}
cases := []MarkdownTestCase{}
for _, c := range testCases {
cases = append(cases, MarkdownTestCase{
No: c.Example,
Markdown: c.Markdown,
Expected: c.HTML,
})
}
markdown := New(WithRendererOptions(
html.WithXHTML(),
html.WithUnsafe(),
))
DoTestCases(markdown, cases, t)
}