forked from MichaelMure/go-term-markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarkdown_test.go
86 lines (61 loc) · 1.75 KB
/
markdown_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package markdown
import (
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
"testing"
"github.com/fatih/color"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestRender(t *testing.T) {
color.NoColor = false
sourcepath := "testdata_source/"
resultpath := "testdata_result/"
err := filepath.Walk(sourcepath, func(fullpath string, info os.FileInfo, err error) error {
require.NoError(t, err)
if info.IsDir() {
return nil
}
_, file := filepath.Split(fullpath)
name := strings.TrimRight(file, ".md")
t.Run(name, func(t *testing.T) {
source, err := ioutil.ReadFile(path.Join(sourcepath, name+".md"))
require.NoError(t, err)
expected, err := ioutil.ReadFile(path.Join(resultpath, name+".txt"))
require.NoError(t, err)
output := Render(string(source), 40, 4)
assert.Equal(t, string(expected), string(output))
})
return nil
})
require.NoError(t, err)
}
func Test__DoRender(t *testing.T) {
// This is not a real test, it's here to create the output testdata.
// uncomment to generate a new test case
t.SkipNow()
color.NoColor = false
sourcepath := "testdata_source/"
resultpath := "testdata_result/"
err := filepath.Walk(sourcepath, func(fullpath string, info os.FileInfo, err error) error {
require.NoError(t, err)
if info.IsDir() {
return nil
}
_, file := filepath.Split(fullpath)
name := strings.TrimRight(file, ".md")
// if name != "Ordered and unordered lists" {
// return nil
// }
source, err := ioutil.ReadFile(path.Join(sourcepath, name+".md"))
require.NoError(t, err)
output := Render(string(source), 40, 4)
err = ioutil.WriteFile(path.Join(resultpath, name+".txt"), output, 0666)
require.NoError(t, err)
return nil
})
require.NoError(t, err)
}