-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtextile_test.go
171 lines (163 loc) · 3.54 KB
/
textile_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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package gotextile
import (
"log"
"testing"
"launchpad.net/gocheck"
)
func Test(t *testing.T) { gocheck.TestingT(t) }
type TestSuite struct {}
var _ = gocheck.Suite(&TestSuite{})
type TestCase struct {
Source string
Expected string
}
var tests = []TestCase{
TestCase{
`p. paragraph`,
`<p>paragraph</p>`,
},
TestCase{
`p. paragraph
next line`,
`<p>paragraph<br>next line</p>`,
},
TestCase{
`paragraph`,
`<p>paragraph</p>`,
},
TestCase{
`with entities < " ' >`,
`<p>with entities < " ' ></p>`,
},
TestCase{
`_emphasis_ __italic__ *strong* **bold** ^sup^ ~sub~`,
`<p><em>emphasis</em> <i>italic</i> <strong>strong</strong> <b>bold</b> <sup>sup</sup> <sub>sub</sub></p>`,
},
TestCase{
`e[_m_]phasis i[__t__]alic s[*t*]rong b[**o**]ld s[^u^]p s[~u~]b`,
`<p>e<em>m</em>phasis i<i>t</i>alic s<strong>t</strong>rong b<b>o</b>ld s<sup>u</sup>p s<sub>u</sub>b</p>`,
},
TestCase{
`e_m_phasis i__t__alic s*t*rong b**old** s^u^p s~u~b`,
`<p>e_m_phasis i__t__alic s*t*rong b**old** s^u^p s~u~b</p>`,
},
TestCase{
`*strong strong* *stron*g strong* strong*`,
`<p><strong>strong strong</strong> <strong>stron*g strong</strong> strong*</p>`,
},
TestCase{
`_emphasis emphasis_ _emphasi_s emphasis_ emphasis_`,
`<p><em>emphasis emphasis</em> <em>emphasi_s emphasis</em> emphasis_</p>`,
},
TestCase{
`@code code@ c@o@de @cod@e code@ code@`,
`<p><code>code code</code> c@o@de <code>cod@e code</code> code@</p>`,
},
TestCase{
`h1. paragraph`,
`<h1>paragraph</h1>`,
},
TestCase{
`h1. paragraph
next line`,
`<h1>paragraph<br>next line</h1>`,
},
TestCase{
`* list`,
`<ul><li>list</li></ul>`,
},
TestCase{
`* list1
* list2`,
`<ul><li>list1</li><li>list2</li></ul>`,
},
TestCase{
`* list1
** list1.1
** list1.2
* list2`,
`<ul><li>list1<ul><li>list1.1</li><li>list1.2</li></ul></li><li>list2</li></ul>`,
},
TestCase{
`** list1.1
** list1.2
* list2`,
`<ul><li><ul><li>list1.1</li><li>list1.2</li></ul></li><li>list2</li></ul>`,
},
TestCase{
`# list`,
`<ol><li>list</li></ol>`,
},
TestCase{
`# list1
# list2`,
`<ol><li>list1</li><li>list2</li></ol>`,
},
TestCase{
`# list1
## list1.1
## list1.2
# list2`,
`<ol><li>list1<ol><li>list1.1</li><li>list1.2</li></ol></li><li>list2</li></ol>`,
},
TestCase{
`## list1.1
## list1.2
# list2`,
`<ol><li><ol><li>list1.1</li><li>list1.2</li></ol></li><li>list2</li></ol>`,
},
TestCase{
`- name := definition`,
`<dl><dt>name</dt><dd>definition</dd></dl>`,
},
TestCase{
`- name1 := definition1
- name2 := definition2`,
`<dl><dt>name1</dt><dd>definition1</dd><dt>name2</dt><dd>definition2</dd></dl>`,
},
TestCase{
`- name1 := definition1
- name2 := definition2
line2 =:`,
`<dl><dt>name1</dt><dd>definition1</dd><dt>name2</dt><dd>definition2<br>line2</dd></dl>`,
},
TestCase{
`bc. line1
line2`,
`<pre><code>line1
line2</code></pre>`,
},
TestCase{
`pre. line1
line2`,
`<pre>line1
line2</pre>`,
},
TestCase{
`###. line1
line2`,
``,
},
TestCase{
`??cite??`,
`<p><cite>cite</cite></p>`,
},
TestCase{
`??cite1??
??cite2??
-- Author`,
`<p><cite>cite1</cite><br><cite>cite2</cite><br>-- Author</p>`,
},
TestCase{
`|cell1.1|cell1.2|cell1.3|
|cell2.1|cell2.2|cell2.3|`,
`<table><tr><td>cell1.1</td><td>cell1.2</td><td>cell1.3</td></tr><tr><td>cell2.1</td><td>cell2.2</td><td>cell2.3</td></tr></table>`,
},
}
func (s *TestSuite) TestTextile(c *gocheck.C) {
for _, t := range tests {
log.Printf("==== %#v ====", t.Source)
txt, _ := TextileToHtml(t.Source)
c.Assert(txt, gocheck.Equals, t.Expected, gocheck.Commentf(t.Source))
}
}