forked from yuin/goldmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commonmark_test.go
44 lines (40 loc) · 996 Bytes
/
commonmark_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package goldmark_test
import (
"encoding/json"
"io/ioutil"
"testing"
. "github.com/pgavlin/goldmark"
"github.com/pgavlin/goldmark/renderer/html"
"github.com/pgavlin/goldmark/testutil"
)
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 := []testutil.MarkdownTestCase{}
for _, c := range testCases {
cases = append(cases, testutil.MarkdownTestCase{
No: c.Example,
Markdown: c.Markdown,
Expected: c.HTML,
})
}
markdown := New(WithRendererOptions(
html.WithXHTML(),
html.WithUnsafe(),
))
testutil.DoTestCases(markdown, cases, t)
}