-
Notifications
You must be signed in to change notification settings - Fork 45
/
mmark_man_test.go
63 lines (53 loc) · 1.52 KB
/
mmark_man_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
package main
import (
"bytes"
"io/ioutil"
"path/filepath"
"testing"
"github.com/gomarkdown/markdown"
"github.com/gomarkdown/markdown/parser"
"github.com/google/go-cmp/cmp"
"github.com/mmarkdown/mmark/v2/mparser"
"github.com/mmarkdown/mmark/v2/render/man"
)
func TestMmarkMan(t *testing.T) {
dir := "testdata/man"
testFiles, err := ioutil.ReadDir(dir)
if err != nil {
t.Fatalf("could not read %s: %q", dir, err)
}
for _, f := range testFiles {
if f.IsDir() {
continue
}
if filepath.Ext(f.Name()) != ".md" {
continue
}
base := f.Name()[:len(f.Name())-3]
opts := man.RendererOptions{Flags: man.ManFragment}
renderer := man.NewRenderer(opts)
doTestMan(t, dir, base, renderer)
}
}
func doTestMan(t *testing.T, dir, basename string, renderer markdown.Renderer) {
filename := filepath.Join(dir, basename+".md")
input, err := ioutil.ReadFile(filename)
if err != nil {
t.Errorf("couldn't open '%s', error: %v\n", filename, err)
return
}
filename = filepath.Join(dir, basename+".fmt")
expected, err := ioutil.ReadFile(filename)
if err != nil {
t.Errorf("couldn't open '%s', error: %v\n", filename, err)
}
expected = bytes.TrimSpace(expected)
p := parser.NewWithExtensions(mparser.Extensions)
doc := markdown.Parse(input, p)
actual := markdown.Render(doc, renderer)
actual = bytes.TrimSpace(actual)
if diff := cmp.Diff(string(expected), string(actual)); diff != "" {
t.Errorf("%s: differs: (-want +got)\n%s", basename+".md", diff)
t.Logf("\n%s\n%s\n%s\n", "---", string(actual), "---")
}
}