summaryrefslogtreecommitdiff
path: root/creole/tests/test_cross_compare_rest.py
blob: a475e06e36640ba04ac61f3289dae060337e81b3 (plain)
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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424


"""
    cross compare reStructuredText unittest
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Compare all similarities between:
        * rest2html (used docutils)
        * html2rest

    :copyleft: 2011-2012 by python-creole team, see AUTHORS for more details.
    :license: GNU GPL v3 or above, see LICENSE for more details.
"""


import unittest

from creole.tests.utils.base_unittest import BaseCreoleTest


class CrossCompareReStTests(BaseCreoleTest):
    def test_entities(self):
        self.cross_compare_rest(
            rest_string="""
                less-than sign: <

                greater-than sign: >
            """,
            html_string="""
                <p>less-than sign: &lt;</p>
                <p>greater-than sign: &gt;</p>
            """,
            # debug=True
        )

    def test_bullet_lists_basic(self):
        self.cross_compare_rest(
            rest_string="""
                * item 1

                * item 2

                * item 3
            """,
            html_string="""
                <ul>
                <li>item 1</li>
                <li>item 2</li>
                <li>item 3</li>
                </ul>
            """,
            # debug=True
        )

    def test_numbered_lists(self):
        self.cross_compare_rest(
            rest_string="""
            #. item 1

            #. item 2

                #. item 2.1

                #. a `link in </url/>`_ list item 2.2

            #. item 3
            """,
            html_string="""
            <ol>
            <li><p>item 1</p>
            </li>
            <li><p>item 2</p>
            <ol>
            <li>item 2.1</li>
            <li>a <a href="/url/">link in</a> list item 2.2</li>
            </ol>
            </li>
            <li><p>item 3</p>
            </li>
            </ol>
            """,
            # debug=True
        )

    def test_bullet_lists_nested(self):
        self.cross_compare_rest(
            rest_string="""
                A nested bullet lists:

                * item 1

                    * A **bold subitem 1.1** here.

                        * subsubitem 1.1.1

                        * subsubitem 1.1.2 with inline |substitution text| image.

                    * subitem 1.2

                * item 2

                    * subitem 2.1

                    * *bold 2.2*

                .. |substitution text| image:: /url/to/image.png

                Text under list.
            """,
            html_string="""
                <p>A nested bullet lists:</p>
                <ul>
                <li><p>item 1</p>
                <ul>
                <li><p>A <strong>bold subitem 1.1</strong> here.</p>
                <ul>
                <li>subsubitem 1.1.1</li>
                <li>subsubitem 1.1.2 with inline <img alt="substitution text" src="/url/to/image.png" /> image.</li>
                </ul>
                </li>
                <li><p>subitem 1.2</p>
                </li>
                </ul>
                </li>
                <li><p>item 2</p>
                <ul>
                <li>subitem 2.1</li>
                <li><em>bold 2.2</em></li>
                </ul>
                </li>
                </ul>
                <p>Text under list.</p>
            """,
            # debug=True
        )

    def test_typeface_basic(self):
        """
        http://docutils.sourceforge.net/docs/user/rst/quickref.html#inline-markup
        """
        self.cross_compare_rest(
            rest_string="""
                *emphasis* **strong**
            """,
            html_string="""
                <p><em>emphasis</em> <strong>strong</strong></p>
            """
        )

    def test_substitution_image_with_alt(self):
        self.cross_compare_rest(
            rest_string="""
                A inline |substitution text| image.

                .. |substitution text| image:: /url/to/image.png

                ...and some text below.
            """,
            html_string="""
                <p>A inline <img alt="substitution text" src="/url/to/image.png" /> image.</p>
                <p>...and some text below.</p>
            """
        )

    def test_table(self):
        self.cross_compare(
            rest_string="""
                before table.

                +------------+
                | table item |
                +------------+

                After table.
            """,
            html_string="""
                <p>before table.</p>
                <table>
                <colgroup>
                <col width="100%" />
                </colgroup>
                <tr><td>table item</td>
                </tr>
                </table>
                <p>After table.</p>
            """
        )

    def test_link_in_table1(self):
        self.cross_compare(
            rest_string="""
                +---------------+
                | `table item`_ |
                +---------------+

                .. _table item: foo/bar
            """,
            html_string="""
                <table>
                <colgroup>
                <col width="100%" />
                </colgroup>
                <tr><td><a href="foo/bar">table item</a></td>
                </tr>
                </table>
            """
        )

    def test_link_in_table2(self):
        self.cross_compare(
            rest_string="""
                +-----------------------+
                | foo `table item`_ bar |
                +-----------------------+

                .. _table item: foo/bar
            """,
            html_string="""
                <table>
                <colgroup>
                <col width="100%" />
                </colgroup>
                <tr><td>foo <a href="foo/bar">table item</a> bar</td>
                </tr>
                </table>
            """
        )

    def test_link_in_table3(self):
        self.cross_compare(
            rest_string="""
                +-----------------------------+
                | * foo `table item 1`_ bar 1 |
                +-----------------------------+
                | * foo `table item 2`_ bar 2 |
                +-----------------------------+

                .. _table item 1: foo/bar/1/
                .. _table item 2: foo/bar/2/
            """,
            html_string="""
                <table>
                <colgroup>
                <col width="100%" />
                </colgroup>
                <tr><td><ul>
                <li>foo <a href="foo/bar/1/">table item 1</a> bar 1</li>
                </ul>
                </td>
                </tr>
                <tr><td><ul>
                <li>foo <a href="foo/bar/2/">table item 2</a> bar 2</li>
                </ul>
                </td>
                </tr>
                </table>
            """
        )

    def test_paragraph_bwlow_table_links(self):
        self.cross_compare(
            rest_string="""
                +-----------------+
                | `table item 1`_ |
                +-----------------+
                | `table item 2`_ |
                +-----------------+

                .. _table item 1: foo/bar/1/
                .. _table item 2: foo/bar/2/

                Text after table.
            """,
            html_string="""
                <table>
                <colgroup>
                <col width="100%" />
                </colgroup>
                <tr><td><a href="foo/bar/1/">table item 1</a></td>
                </tr>
                <tr><td><a href="foo/bar/2/">table item 2</a></td>
                </tr>
                </table>
                <p>Text after table.</p>
            """,
            # debug=True
        )

    def test_reuse_link_substitution1(self):
        self.cross_compare(
            rest_string="""
                +--------------------------------+
                | this is `foo bar`_ first time. |
                +--------------------------------+
                | and here `foo bar`_ again.     |
                +--------------------------------+

                .. _foo bar: foo/bar/

                Text after table.
            """,
            html_string="""
                <table>
                <colgroup>
                <col width="100%" />
                </colgroup>
                <tr><td>this is <a href="foo/bar/">foo bar</a> first time.</td>
                </tr>
                <tr><td>and here <a href="foo/bar/">foo bar</a> again.</td>
                </tr>
                </table>
                <p>Text after table.</p>
            """,
            # debug=True
        )

    def test_reuse_link_substitution2(self):
        self.cross_compare(
            rest_string="""
                +--------------------------------+
                | this is `foo bar`_ first time. |
                +--------------------------------+

                .. _foo bar: foo/bar/

                and here `foo bar`_ again, after table.
            """,
            html_string="""
                <table>
                <colgroup>
                <col width="100%" />
                </colgroup>
                <tr><td>this is <a href="foo/bar/">foo bar</a> first time.</td>
                </tr>
                </table>
                <p>and here <a href="foo/bar/">foo bar</a> again, after table.</p>
            """,
            # debug=True
        )

    def test_reuse_image_substitution(self):
        self.cross_compare(
            rest_string="""
                +----------------------+
                | first |image| here   |
                +----------------------+
                | second |image| there |
                +----------------------+

                .. |image| image:: /picture.png
            """,
            html_string="""
                <table>
                <colgroup>
                <col width="100%" />
                </colgroup>
                <tr><td>first <img alt="image" src="/picture.png" /> here</td>
                </tr>
                <tr><td>second <img alt="image" src="/picture.png" /> there</td>
                </tr>
                </table>
            """,
            # debug=True
        )

    def test_duplicate_image_substitution(self):
        self.cross_compare(
            rest_string="""
                +----------------------+
                | a |same| image here  |
                +----------------------+
                | a `same`_ link there |
                +----------------------+

                .. |same| image:: /image.png
                .. _same: /url/foo/

                again: the |same| image and `same`_ link!
            """,
            html_string="""
                <table>
                <colgroup>
                <col width="100%" />
                </colgroup>
                <tr><td>a <img alt="same" src="/image.png" /> image here</td>
                </tr>
                <tr><td>a <a href="/url/foo/">same</a> link there</td>
                </tr>
                </table>
                <p>again: the <img alt="same" src="/image.png" /> image and <a href="/url/foo/">same</a> link!</p>
            """,
            # debug=True
        )


#    def test_inline_literal(self):
#        """ TODO
#        http://docutils.sourceforge.net/docs/user/rst/quickref.html#inline-markup
#        """
#        self.cross_compare_rest(
#            rest_string="""
#                ``inline literal``
#            """,
#            html_string="""
#                <p><code>inline&nbsp;literal</code></p>
#            """
#        )

#    def test_escape_in_pre(self):
#        self.cross_compare_rest(
#            textile_string="""
#                <pre>
#                <html escaped>
#                </pre>
#            """,
#            html_string="""
#                <pre>
#                &#60;html escaped&#62;
#                </pre>
#            """)
if __name__ == '__main__':
    unittest.main(
        #        defaultTest="CrossCompareReStTests.test_paragraph_bwlow_table_links",
    )