-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
357 lines (309 loc) · 11.8 KB
/
test.py
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
import nose
from nose.tools import eq_, raises
from unittest import TestCase
from pyorg.org import NestingNotValidError
from pyorg.org import Org, org_to_html
class TestOrg(TestCase):
def test_org(self):
text = ''''''
o = Org(text)
eq_(str(o), 'Org()')
def test_paragraph(self):
text = '''line1
line2'''
o = Org(text)
eq_(str(o), 'Org(Paragraph(Text Text))')
def test_new_paragraph(self):
text = '''para1-1
para1-2
para2-1
para2-2'''
o = Org(text)
eq_(str(o), 'Org(Paragraph(Text Text) Paragraph(Text Text))')
def test_heading(self):
text = '''* Heading1
** Heading2
*** Heading3
**** Heading4
***** Heading5-1
****** Heading6
***** Heading5-2'''
o = Org(text)
eq_(str(o), 'Org(Heading1(Heading2(Heading3(Heading4(Heading5(Heading6()) Heading5())))))')
def test_slided_heading(self):
text = '''* Heading2
** Heading3'''
o = Org(text, default_heading=2)
eq_(str(o), 'Org(Heading2(Heading3()))')
def test_blockquote(self):
text = '''#+BEGIN_QUOTE: http://exapmle.com
quoted line1
quoted line2
#+END_QUOTE'''
o = Org(text)
eq_(str(o), 'Org(Blockquote(Text Text))')
def test_blockquote_with_some_decoration(self):
text = '''#+BEGIN_QUOTE
=quoted line=
#+END_QUOTE'''
o = Org(text)
eq_(str(o), 'Org(Blockquote(Text))')
@raises(NestingNotValidError)
def test_openless_blockquote(self):
text = '''#+END_QUOTE'''
Org(text)
@raises(NestingNotValidError)
def test_endless_blockquote(self):
text = '''#+BEGIN_QUOTE'''
Org(text)
def test_src(self):
text = '''#+BEGIN_SRC
source code
source code
#+END_SRC'''
o = Org(text)
eq_(str(o), 'Org(CodeBlock(Text Text))')
def test_src_with_type(self):
text = '''#+BEGIN_SRC python
source code
source code
#+END_SRC'''
o = Org(text)
eq_(str(o), 'Org(CodeBlock(Text Text))')
def test_src_with_some_decoration(self):
text = '''#+BEGIN_SRC
=source code=
+source code+
#+END_SRC'''
o = Org(text)
eq_(str(o), 'Org(CodeBlock(Text Text))')
@raises(NestingNotValidError)
def test_openless_src(self):
text = '''#+END_SRC'''
Org(text)
@raises(NestingNotValidError)
def test_endless_src(self):
text = '''#+BEGIN_SRC'''
Org(text)
def test_orderedlist(self):
text = '''1. listitem1
2. listitem2
3) listitem3
4) listitem4'''
o = Org(text)
eq_(str(o), 'Org(OrderedList(ListItem ListItem ListItem ListItem))')
def test_nested_orderedlist(self):
text = '''1. listitem1
2. listitem2
1. shallowitem1
2. shallowitem2
1. deepitem1
2. deepitem2
3. shallowitem3
3. listitem3'''
o = Org(text)
eq_(str(o), 'Org(OrderedList(ListItem ListItem OrderedList(ListItem ListItem OrderedList(ListItem ListItem) ListItem) ListItem))')
def test_unorderedlist(self):
text = '''- listitem1
- listitem2
+ listitem3
+ listitem4'''
o = Org(text)
eq_(str(o), 'Org(UnOrderedList(ListItem ListItem ListItem ListItem))')
def test_nested_unorderedlist(self):
text = '''- listitem1
- listitem2
+ shallowitem1
+ shallowitem2
- deepitem1
- deepitem2
+ shallowitem3
- listitem3'''
o = Org(text)
eq_(str(o), 'Org(UnOrderedList(ListItem ListItem UnOrderedList(ListItem ListItem UnOrderedList(ListItem ListItem) ListItem) ListItem))')
def test_definitionlist(self):
text = '''- listtitle1:: listdescription1
- listtitle2::listdescription2
- listtitle3 :: listdescription3
- listtitle4::listdescription4
+ listtitle5:: listdescription5
+ listtitle6::listdescription6
+ listtitle7 :: listdescription7
+ listtitle8::listdescription8'''
o = Org(text)
eq_(str(o), 'Org(DefinitionList(DefinitionListItem(DefinitionListItemTitle DefinitionListItemDescription) DefinitionListItem(DefinitionListItemTitle DefinitionListItemDescription) DefinitionListItem(DefinitionListItemTitle DefinitionListItemDescription) DefinitionListItem(DefinitionListItemTitle DefinitionListItemDescription) DefinitionListItem(DefinitionListItemTitle DefinitionListItemDescription) DefinitionListItem(DefinitionListItemTitle DefinitionListItemDescription) DefinitionListItem(DefinitionListItemTitle DefinitionListItemDescription) DefinitionListItem(DefinitionListItemTitle DefinitionListItemDescription)))')
def text_nested_definitionlist(self):
text = '''- listitem1:: desc1
- listitem2 ::desc2
+ shallowitem1 :: shallowdesc1
+ shallowitem2::shallowdesc2
- deepitem1::deepdesc1
- deepitem2 :: deepdesc2
+ shallowitem3:: shallowdesc3
- listitem3 :: desc3'''
o = Org(text)
eq_(str(o), 'Org(DefinitionList(DefinitionListItem(DefinitionListItemTitle DefinitionListItemDescription) DefinitionListItem(DefinitionListItemTitle DefinitionListItemDescription) DefinitionList(DefinitionListItem(DefinitionListItemTitle DefinitionListItemDescription) DefinitionListItem(DefinitionListItemTitle DefinitionListItemDescription) DefinitionList(DefinitionListItem(DefinitionListItemTitle DefinitionListItemDescription) DefinitionListItem(DefinitionListItemTitle DefinitionListItemDescription)) DefinitionListItem(DefinitionListItemTitle DefinitionListItemDescription)) DefinitionListItem(DefinitionListItemTitle DefinitionListItemDescription)))')
def test_table(self):
text = '''| col1-1 | col2-1|col3-1 |col4-1|
| col1-2|col2-2 |col3-2| col4-2 |
|col1-3 |col2-3| col3-3 | col4-3|
|col1-4| col2-4 | col3-4|col4-4 |'''
o = Org(text)
eq_(str(o), 'Org(Table(TableRow(TableCell(Text) TableCell(Text) TableCell(Text) TableCell(Text)) TableRow(TableCell(Text) TableCell(Text) TableCell(Text) TableCell(Text)) TableRow(TableCell(Text) TableCell(Text) TableCell(Text) TableCell(Text)) TableRow(TableCell(Text) TableCell(Text) TableCell(Text) TableCell(Text))))')
def test_link(self):
text = '''[[http://example.com]]'''
o = Org(text)
eq_(str(o), 'Org(Paragraph(Text))')
eq_(o.children[0].children[0].get_text(), 'Link')
text = '''[[http://example.com][example]]'''
o = Org(text)
eq_(str(o), 'Org(Paragraph(Text))')
eq_(o.children[0].children[0].get_text(), 'Link')
text = '''hoge[[http://example.com]]fuga'''
o = Org(text)
eq_(str(o), 'Org(Paragraph(Text))')
eq_(o.children[0].children[0].get_text(), 'hogeLinkfuga')
def test_image(self):
text = '''[[picture.png]]'''
o = Org(text)
eq_(str(o), 'Org(Paragraph(Text))')
eq_(o.children[0].children[0].get_text(), 'Image')
def test_link_and_image(self):
text = '''hoge[[http://example.com]]fuga[[picture]]piyo'''
o = Org(text)
eq_(str(o), 'Org(Paragraph(Text))')
eq_(o.children[0].children[0].get_text(), 'hogeLinkfugaImagepiyo')
text = '''hoge[[picture]]fuga[[http://example.com]]piyo'''
o = Org(text)
eq_(str(o), 'Org(Paragraph(Text))')
eq_(o.children[0].children[0].get_text(), 'hogeImagefugaLinkpiyo')
def test_bold(self):
text = '''hoge*bold*fuga'''
o = Org(text)
eq_(str(o), 'Org(Paragraph(Text))')
eq_(o.children[0].children[0].get_text(), 'hogeBoldTextfuga')
def test_italic(self):
text = '''hoge/italic/fuga'''
o = Org(text)
eq_(str(o), 'Org(Paragraph(Text))')
eq_(o.children[0].children[0].get_text(), 'hogeItalicTextfuga')
def test_underlined(self):
text = '''hoge_underlined_fuga'''
o = Org(text)
eq_(str(o), 'Org(Paragraph(Text))')
eq_(o.children[0].children[0].get_text(), 'hogeUnderlinedTextfuga')
def test_linethrough(self):
text = '''hoge+linethrough+fuga'''
o = Org(text)
eq_(str(o), 'Org(Paragraph(Text))')
eq_(o.children[0].children[0].get_text(), 'hogeLinethroughTextfuga')
def test_inlinecode(self):
text = '''hoge=code=fuga'''
o = Org(text)
eq_(str(o), 'Org(Paragraph(Text))')
eq_(o.children[0].children[0].get_text(), 'hogeInlineCodeTextfuga')
def test_mix(self):
text = '''* header1
paraparapara
** header2-1
[[image]]
para*para*2[[http://example.com][hyperlink]]
** header2-2
| a | b |
| 1 | 2 |
*** header3
#+BEGIN_QUOTE
quoted
- hoge
- fuga
#+END_QUOTE'''
o = Org(text)
eq_(str(o), 'Org(Heading1(Paragraph(Text) Heading2(Paragraph(Text Text)) Heading2(Table(TableRow(TableCell(Text) TableCell(Text)) TableRow(TableCell(Text) TableCell(Text))) Heading3(Blockquote(Text UnOrderedList(ListItem ListItem))))))')
class TestOrgToHTML(TestCase):
def test_html(self):
text = '''* header1
paraparapara
** header2-1
[[image]]
para*para*2[[http://example.com][hyperlink]]
** header2-2
| a | b |
| 1 | 2 |
*** header3-1
#+BEGIN_QUOTE
quoted
=quoted_decorated=
#+END_QUOTE
*** header3-2
#+BEGIN_SRC python
python code
=hoge=
#+END_SRC'''
o = Org(text)
eq_(o.html(), '<h1>header1</h1><p>paraparapara</p><h2>header2-1</h2><p><img src="image">para<span style="font-weight: bold;">para</span>2<a href="http://example.com">hyperlink</a></p><h2>header2-2</h2><table><tr><td>a</td><td>b</td></tr><tr><td>1</td><td>2</td></tr></table><h3>header3-1</h3><blockquote>quoted<code>quoted_decorated</code></blockquote><h3>header3-2</h3><pre><code class="python">python code=hoge=</code></pre>')
def test_slide_heading_html(self):
text = '''* header1
paraparapara
** header2-1
[[image]]
para*para*2[[http://example.com][hyperlink]]
** header2-2
| a | b |
| 1 | 2 |
*** header3
#+BEGIN_QUOTE
quoted
#+END_QUOTE'''
o = Org(text, default_heading=2)
eq_(o.html(), '<h2>header1</h2><p>paraparapara</p><h3>header2-1</h3><p><img src="image">para<span style="font-weight: bold;">para</span>2<a href="http://example.com">hyperlink</a></p><h3>header2-2</h3><table><tr><td>a</td><td>b</td></tr><tr><td>1</td><td>2</td></tr></table><h4>header3</h4><blockquote>quoted</blockquote>')
def test_inlinecode(self):
text = '=inline text='
o = Org(text)
eq_(o.html(), '<p><code>inline text</code></p>')
text = '=/inline italic text/='
o = Org(text)
eq_(o.html(), '<p><code>/inline italic text/</code></p>')
text = '=<tag>='
o = Org(text)
eq_(o.html(), '<p><code><tag></code></p>')
class TestOrgToHTMLFunction(TestCase):
def test_html(self):
text = '''* header1
paraparapara
** header2-1
[[image]]
para*para*2[[http://example.com][hyperlink]]
** header2-2
| a | b |
| 1 | 2 |
*** header3-1
#+BEGIN_QUOTE
quoted
#+END_QUOTE
*** header3-2
- hoge
- fuga'''
eq_(org_to_html(text), '<h1>header1</h1><p>paraparapara</p><h2>header2-1</h2><p><img src="image">para<span style="font-weight: bold;">para</span>2<a href="http://example.com">hyperlink</a></p><h2>header2-2</h2><table><tr><td>a</td><td>b</td></tr><tr><td>1</td><td>2</td></tr></table><h3>header3-1</h3><blockquote>quoted</blockquote><h3>header3-2</h3><ul><li>hoge</li><li>fuga</li></ul>')
def test_slide_heading_html(self):
text = '''* header1
paraparapara
** header2-1
[[image]]
para*para*2[[http://example.com][hyperlink]]
** header2-2
| a | b |
| 1 | 2 |
*** header3
#+BEGIN_QUOTE
quoted
#+END_QUOTE'''
eq_(org_to_html(text, default_heading=2), '<h2>header1</h2><p>paraparapara</p><h3>header2-1</h3><p><img src="image">para<span style="font-weight: bold;">para</span>2<a href="http://example.com">hyperlink</a></p><h3>header2-2</h3><table><tr><td>a</td><td>b</td></tr><tr><td>1</td><td>2</td></tr></table><h4>header3</h4><blockquote>quoted</blockquote>')
def test_newline_html(self):
text = '''* header1
paraparapara
hogehogehoge
- list1
- list2'''
eq_(org_to_html(text, newline='\n'), '<h1>header1</h1><p>paraparapara\nhogehogehoge</p><ul><li>list1</li><li>list2</li></ul>')
if __name__ == '__main__':
unittest.main()