-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmd_test.go
73 lines (68 loc) · 1.63 KB
/
md_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
package main
import (
"io/ioutil"
"reflect"
"testing"
bf "github.com/gbmor-forks/blackfriday.v2-patched"
)
var mdTestData1, _ = ioutil.ReadFile("pages/example.md")
var mdTestData2, _ = ioutil.ReadFile("pages/test1.md")
var markdownTests = []struct {
name string
css string
title string
data []byte
}{
{
name: "one",
css: "assets/wiki.css",
title: "Example Page",
data: mdTestData1,
},
{
name: "two",
css: "assets/wiki.css",
title: "No Description",
data: mdTestData2,
},
}
// Make sure setupMarkdown is returning a valid
// blackfriday.HTMLRenderer type
func Test_setupMarkdown(t *testing.T) {
for _, tt := range markdownTests {
t.Run(string(tt.name), func(t *testing.T) {
var got interface{} = setupMarkdown(tt.css, tt.title)
if _, ok := got.(*bf.HTMLRenderer); !ok {
t.Errorf("setupMarkdown() returned incorrect type: %v", reflect.TypeOf(got))
}
})
}
}
func Benchmark_setupMarkdown(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, c := range markdownTests {
setupMarkdown(c.css, c.title)
}
}
}
// Previously, I was using bytes.Equal(a, b) to test the
// output of render. However, I can't control for variations
// in blackfriday's output, so I'm just testing to make sure
// it's returning *something*
func Test_render(t *testing.T) {
for _, tt := range markdownTests {
t.Run(string(tt.name), func(t *testing.T) {
var got []byte
if got = render(tt.data, tt.title); got == nil {
t.Errorf("render() outputting nil bytes\n")
}
})
}
}
func Benchmark_render(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, c := range markdownTests {
render(c.data, c.title)
}
}
}