-
Notifications
You must be signed in to change notification settings - Fork 259
/
commonmark_test.go
57 lines (52 loc) · 1.16 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
package goldmark_test
import (
"encoding/json"
"os"
"testing"
. "github.com/yuin/goldmark"
"github.com/yuin/goldmark/renderer/html"
"github.com/yuin/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 := os.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{}
nos := testutil.ParseCliCaseArg()
for _, c := range testCases {
shouldAdd := len(nos) == 0
if !shouldAdd {
for _, no := range nos {
if c.Example == no {
shouldAdd = true
break
}
}
}
if shouldAdd {
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)
}