-
Notifications
You must be signed in to change notification settings - Fork 5
/
hoedown_test.go
115 lines (103 loc) · 2.42 KB
/
hoedown_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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package hoedown
import (
"bytes"
. "github.com/r7kamura/gospel"
"testing"
)
func TestHowdown(t *testing.T) {
Describe(t, "hoedown.Markdown", func() {
Context("when a headline passed", func() {
hoedown := NewHoedown(map[string]uint{
"extensions": 0,
"renderModes": 0,
})
buffer := bytes.NewBuffer([]byte{})
hoedown.Markdown(buffer, []byte("# Hoedown"))
It("should render HTML from markdown string", func() {
Expect(buffer.String()).To(Equal, "<h1 id=\"toc_0\">Hoedown</h1>\n")
})
})
Context("when UTF-8 strings are passed", func() {
hoedown := NewHoedown(map[string]uint{
"extensions": 0,
"renderModes": 0,
})
buffer := bytes.NewBuffer([]byte{})
hoedown.Markdown(buffer, []byte("# あいう"))
It("should render HTML from markdown string", func() {
Expect(buffer.String()).To(Equal, "<h1 id=\"toc_0\">あいう</h1>\n")
})
})
Context("when a extension is passed", func() {
hoedown := NewHoedown(map[string]uint{
"extensions": EXT_AUTOLINK,
"renderModes": 0,
})
buffer := bytes.NewBuffer([]byte{})
hoedown.Markdown(buffer, []byte("http://example.com/"))
It("should render HTML from markdown string", func() {
Expect(buffer.String()).To(Equal, "<p><a href=\"http://example.com/\">http://example.com/</a></p>\n")
})
})
Context("when a render mode is passed", func() {
hoedown := NewHoedown(map[string]uint{
"extensions": 0,
"renderModes": HTML_USE_XHTML,
})
buffer := bytes.NewBuffer([]byte{})
hoedown.Markdown(buffer, []byte("![test](http://example.com/test.jpg)"))
It("should render HTML from markdown string", func() {
Expect(buffer.String()).To(Equal, "<p><img src=\"http://example.com/test.jpg\" alt=\"test\"/></p>\n")
})
})
})
Describe(t, "hoedown.MarkdownTOC", func() {
src := []byte(`
# 1
## 1.1
### 1.1.1
## 1.2
### 1.2.1
# 2
## 2.2`)
Context("when some a toc passed", func() {
hoedown := NewHoedown(map[string]uint{})
buffer := bytes.NewBuffer([]byte{})
hoedown.MarkdownTOC(buffer, src)
It("should render the toc as a list", func() {
Expect(buffer.String()).To(Equal, `<ul>
<li>
<a href="#toc_0">1</a>
<ul>
<li>
<a href="#toc_1">1.1</a>
<ul>
<li>
<a href="#toc_2">1.1.1</a>
</li>
</ul>
</li>
<li>
<a href="#toc_3">1.2</a>
<ul>
<li>
<a href="#toc_4">1.2.1</a>
</li>
</ul>
</li>
</ul>
</li>
<li>
<a href="#toc_5">2</a>
<ul>
<li>
<a href="#toc_6">2.2</a>
</li>
</ul>
</li>
</ul>
`)
})
})
})
}