forked from gomarkdown/markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mmark_test.go
67 lines (58 loc) · 1.46 KB
/
mmark_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
58
59
60
61
62
63
64
65
66
67
package markdown
import (
"bytes"
"io/ioutil"
"path/filepath"
"testing"
"github.com/gomarkdown/markdown/parser"
)
type testData struct {
md []byte
html []byte
}
func testDataToStrArray(tests []*testData) []string {
res := []string{}
for _, td := range tests {
res = append(res, string(td.md))
res = append(res, string(td.html))
}
return res
}
func readTestFile2(t *testing.T, fileName string) []string {
tests := readTestFile(t, fileName)
return testDataToStrArray(tests)
}
func readTestFile(t *testing.T, fileName string) []*testData {
path := filepath.Join("testdata", fileName)
d, err := ioutil.ReadFile(path)
if err != nil {
t.Fatalf("ioutil.ReadFile('%s') failed with %s", path, err)
}
parts := bytes.Split(d, []byte("+++\n"))
if len(parts)%2 != 0 {
t.Fatalf("odd test tuples in file %s: %d", path, len(parts))
}
res := []*testData{}
n := len(parts) / 2
for i := 0; i < n; i++ {
j := i * 2
td := &testData{
md: parts[j],
html: parts[j+1],
}
res = append(res, td)
}
return res
}
func TestMmark(t *testing.T) {
testData := readTestFile(t, "mmark.test")
ext := parser.CommonExtensions | parser.Attributes | parser.OrderedListStart | parser.SuperSubscript | parser.Mmark
for _, td := range testData {
p := parser.NewWithExtensions(ext)
got := ToHTML(td.md, p, nil)
want := td.html
if !bytes.Equal(got, want) {
t.Errorf("want (%d bytes) %s, got (%d bytes) %s, for input %q", len(want), want, len(got), got, td.md)
}
}
}