File: test_renderer.py

package info (click to toggle)
python-m2r 0.3.1-0.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 344 kB
  • sloc: python: 1,409; makefile: 287; sh: 1
file content (768 lines) | stat: -rw-r--r-- 22,292 bytes parent folder | download
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
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from __future__ import print_function, unicode_literals

from unittest import TestCase, skip

from docutils.core import Publisher
from docutils import io

from m2r import prolog, convert


class RendererTestBase(TestCase):
    def conv(self, src, **kwargs):
        out = convert(src, **kwargs)
        self.check_rst(out)
        return out

    def conv_no_check(self, src, **kwargs):
        out = convert(src, **kwargs)
        return out

    def check_rst(self, rst):
        pub = Publisher(reader=None, parser=None, writer=None, settings=None,
                        source_class=io.StringInput,
                        destination_class=io.StringOutput)
        pub.set_components(reader_name='standalone',
                           parser_name='restructuredtext',
                           writer_name='pseudoxml')
        pub.process_programmatic_settings(
            settings_spec=None,
            settings_overrides={'output_encoding': 'unicode'},
            config_section=None,
        )
        pub.set_source(rst, source_path=None)
        pub.set_destination(destination=None, destination_path=None)
        output = pub.publish(enable_exit_status=False)
        self.assertLess(pub.document.reporter.max_level, 0)
        return output, pub


class TestBasic(RendererTestBase):
    def test_fail_rst(self):
        with self.assertRaises(AssertionError):
            # This check should be failed and report warning
            self.check_rst('```')

    def test_simple_paragraph(self):
        src = 'this is a sentence.\n'
        out = self.conv(src)
        self.assertEqual(out, '\n' + src)

    def test_multiline_paragraph(self):
        src = '\n'.join([
            'first sentence.',
            'second sentence.',
        ])
        out = self.conv(src)
        self.assertEqual(out, '\n' + src + '\n')

    def test_multi_paragraph(self):
        src = '\n'.join([
            'first paragraph.',
            '',
            'second paragraph.',
        ])
        out = self.conv(src)
        self.assertEqual(out, '\n' + src + '\n')

    def test_hr(self):
        src = 'a\n\n---\n\nb'
        out = self.conv(src)
        self.assertEqual(out, '\na\n\n----\n\nb\n')

    def test_linebreak(self):
        src = 'abc def  \nghi'
        out = self.conv(src)
        self.assertEqual(
            out,
            prolog + '\nabc def\\ :raw-html-m2r:`<br>`\nghi' + '\n',
        )


class TestInlineMarkdown(RendererTestBase):
    def test_inline_code(self):
        src = '`a`'
        out = self.conv(src)
        self.assertEqual(out.replace('\n', ''), '``a``')

    def test_inline_code_with_backticks(self):
        src = '```a``a```'
        out = self.conv(src)
        self.assertEqual(out.strip(),
                         '.. role:: raw-html-m2r(raw)\n'
                         '   :format: html\n\n\n'
                         ':raw-html-m2r:`<code class="docutils literal">'
                         '<span class="pre">a&#96;&#96;a</span></code>`'
                         )

    def test_strikethrough(self):
        src = ('~~a~~')
        self.conv(src)

    def test_emphasis(self):
        src = '*a*'
        out = self.conv(src)
        self.assertEqual(out.replace('\n', ''), '*a*')

    def test_emphasis_(self):
        src = '_a_'
        out = self.conv(src)
        self.assertEqual(out.replace('\n', ''), '*a*')

    def test_emphasis_no_(self):
        src = '_a_'
        out = self.conv(src, no_underscore_emphasis=True)
        self.assertEqual(out.replace('\n', ''), '_a_')

    def test_double_emphasis(self):
        src = '**a**'
        out = self.conv(src)
        self.assertEqual(out.replace('\n', ''), '**a**')

    def test_double_emphasis__(self):
        src = '__a__'
        out = self.conv(src)
        self.assertEqual(out.replace('\n', ''), '**a**')

    def test_emphasis_no__(self):
        src = '__a__'
        out = self.conv(src, no_underscore_emphasis=True)
        self.assertEqual(out.replace('\n', ''), '__a__')

    def test_autolink(self):
        src = 'link to http://example.com/ in sentence.'
        out = self.conv(src)
        self.assertEqual(out, '\n' + src + '\n')

    def test_link(self):
        src = 'this is a [link](http://example.com/).'
        out = self.conv(src)
        self.assertEqual(
            out, '\nthis is a `link <http://example.com/>`_.\n')

    def test_anonymous_link(self):
        src = 'this is a [link](http://example.com/).'
        out = self.conv(src, anonymous_references=True)
        self.assertEqual(
            out, '\nthis is a `link <http://example.com/>`__.\n')

    def test_link_with_rel_link_enabled(self):
        src = 'this is a [link](http://example.com/).'
        out = self.conv_no_check(
            src,
            parse_relative_links=True
        )
        self.assertEqual(
            out, '\nthis is a `link <http://example.com/>`_.\n')

    def test_anonymous_link_with_rel_link_enabled(self):
        src = 'this is a [link](http://example.com/).'
        out = self.conv_no_check(
            src,
            parse_relative_links=True,
            anonymous_references=True
        )
        self.assertEqual(
            out, '\nthis is a `link <http://example.com/>`__.\n')

    def test_anchor(self):
        src = 'this is an [anchor](#anchor).'
        out = self.conv_no_check(
            src,
            parse_relative_links=True
        )
        self.assertEqual(
            out, '\nthis is an :ref:`anchor <anchor>`.\n')

    def test_relative_link(self):
        src = 'this is a [relative link](a_file.md).'
        out = self.conv_no_check(
            src,
            parse_relative_links=True
        )
        self.assertEqual(
            out, '\nthis is a :doc:`relative link <a_file>`.\n')

    def test_relative_link_with_anchor(self):
        src = 'this is a [relative link](a_file.md#anchor).'
        out = self.conv_no_check(
            src,
            parse_relative_links=True
        )
        self.assertEqual(
            out, '\nthis is a :doc:`relative link <a_file>`.\n')

    def test_link_title(self):
        src = 'this is a [link](http://example.com/ "example").'
        out = self.conv(src)
        self.assertEqual(
            out,
            '.. role:: raw-html-m2r(raw)\n'
            '   :format: html\n\n\n'
            'this is a :raw-html-m2r:'
            '`<a href="http://example.com/" title="example">link</a>`.\n'
        )

    def test_image_link(self):
        src = '[![Alt Text](image_taget_url)](link_target_url)'
        out = self.conv(src)
        self.assertEqual(
            out,
            '\n\n.. image:: image_taget_url\n'
            '   :target: link_target_url\n   :alt: Alt Text\n\n',
        )

    def test_rest_role(self):
        src = 'a :code:`some code` inline.'
        out = self.conv(src)
        self.assertEqual(out, '\n' + src + '\n')

    def test_rest_role2(self):
        src = 'a `some code`:code: inline.'
        out = self.conv(src)
        self.assertEqual(out, '\n' + src + '\n')

    def test_rest_link(self):
        src = 'a `RefLink <http://example.com>`_ here.'
        out = self.conv(src)
        self.assertEqual(out, '\n' + src + '\n')

    def test_rest_link_and_role(self):
        src = 'a :code:`a` and `RefLink <http://example.com>`_ here.'
        out = self.conv(src)
        self.assertEqual(out, '\n' + src + '\n')

    def test_rest_link_and_role2(self):
        src = 'a `a`:code: and `RefLink <http://example.com>`_ here.'
        out = self.conv(src)
        self.assertEqual(out, '\n' + src + '\n')

    def test_rest_role_incomplete(self):
        src = 'a co:`de` and `RefLink <http://example.com>`_ here.'
        out = self.conv(src)
        self.assertEqual(
            out,
            '\na co:\\ ``de`` and `RefLink <http://example.com>`_ here.\n',
        )

    def test_rest_role_incomplete2(self):
        src = 'a `RefLink <http://example.com>`_ and co:`de` here.'
        out = self.conv(src)
        self.assertEqual(
            out,
            '\na `RefLink <http://example.com>`_ and co:\\ ``de`` here.\n',
        )

    def test_rest_role_with_code(self):
        src = 'a `code` and :code:`rest` here.'
        out = self.conv(src)
        self.assertEqual(out, '\na ``code`` and :code:`rest` here.\n')

    def test_rest2_role_with_code(self):
        src = 'a `code` and `rest`:code: here.'
        out = self.conv(src)
        self.assertEqual(out, '\na ``code`` and `rest`:code: here.\n')

    def test_code_with_rest_role(self):
        src = 'a :code:`rest` and `code` here.'
        out = self.conv(src)
        self.assertEqual(out, '\na :code:`rest` and ``code`` here.\n')

    def test_code_with_rest_role2(self):
        src = 'a `rest`:code: and `code` here.'
        out = self.conv(src)
        self.assertEqual(out, '\na `rest`:code: and ``code`` here.\n')

    def test_rest_link_with_code(self):
        src = 'a `RefLink <a>`_ and `code` here.'
        out = self.conv(src)
        self.assertEqual(out, '\na `RefLink <a>`_ and ``code`` here.\n')

    def test_code_with_rest_link(self):
        src = 'a `code` and `RefLink <a>`_ here.'
        out = self.conv(src)
        self.assertEqual(out, '\na ``code`` and `RefLink <a>`_ here.\n')

    def test_inline_math(self):
        src = 'this is `$E = mc^2$` inline math.'
        out = self.conv(src)
        self.assertEqual(out, '\nthis is :math:`E = mc^2` inline math.\n')

    def test_disable_inline_math(self):
        src = 'this is `$E = mc^2$` inline math.'
        out = self.conv(src, disable_inline_math=True)
        self.assertEqual(out, '\nthis is ``$E = mc^2$`` inline math.\n')

    def test_inline_html(self):
        src = 'this is <s>html</s>.'
        out = self.conv(src)
        self.assertEqual(
            out, prolog + '\nthis is :raw-html-m2r:`<s>html</s>`.\n')

    def test_block_html(self):
        src = '<h1>title</h1>'
        out = self.conv(src)
        self.assertEqual(out, '\n\n.. raw:: html\n\n   <h1>title</h1>\n\n')


class TestBlockQuote(RendererTestBase):
    def test_block_quote(self):
        src = '> q1\n> q2'
        out = self.conv(src)
        self.assertEqual(out, '\n..\n\n   q1\n   q2\n\n')

    def test_block_quote_nested(self):
        src = '> q1\n> > q2'
        out = self.conv(src)
        # one extra empty line is inserted, but still valid rst anyway
        self.assertEqual(out, '\n..\n\n   q1\n\n   ..\n\n      q2\n\n')

    @skip('markdown does not support dedent in block quote')
    def test_block_quote_nested_2(self):
        src = '> q1\n> > q2\n> q3'
        out = self.conv(src)
        self.assertEqual(out, '\n..\n\n   q1\n\n   ..\n      q2\n\n   q3\n\n')


class TestCodeBlock(RendererTestBase):
    def test_plain_code_block(self):
        src = '\n'.join([
            '```',
            'pip install sphinx',
            '```',
        ])
        out = self.conv(src)
        self.assertEqual(out, '\n.. code-block::\n\n   pip install sphinx\n')

    def test_plain_code_block_tilda(self):
        src = '\n'.join([
            '~~~',
            'pip install sphinx',
            '~~~',
        ])
        out = self.conv(src)
        self.assertEqual(out, '\n.. code-block::\n\n   pip install sphinx\n')

    def test_code_block_math(self):
        src = '\n'.join([
            '```math',
            'E = mc^2',
            '```',
        ])
        out = self.conv(src)
        self.assertEqual(out, '\n.. math::\n\n   E = mc^2\n')

    def test_plain_code_block_indent(self):
        src = '\n'.join([
            '```',
            'pip install sphinx',
            '    new line',
            '```',
        ])
        out = self.conv(src)
        self.assertEqual(
            out,
            '\n.. code-block::\n\n   pip install sphinx\n       new line\n',
        )

    def test_python_code_block(self):
        src = '\n'.join([
            '```python',
            'print(1)',
            '```',
        ])
        out = self.conv(src)
        self.assertEqual(out, '\n.. code-block:: python\n\n   print(1)\n')

    def test_python_code_block_indent(self):
        src = '\n'.join([
            '```python',
            'def a(i):',
            '    print(i)',
            '```',
        ])
        out = self.conv(src)
        self.assertEqual(
            out,
            '\n.. code-block:: python\n\n   def a(i):\n       print(i)\n',
        )


class TestImage(RendererTestBase):
    def test_image(self):
        src = '![alt text](a.png)'
        out = self.conv(src)
        # first and last newline is inserted by paragraph
        self.assertEqual(
            out,
            '\n\n.. image:: a.png\n   :target: a.png\n   :alt: alt text\n\n',
        )

    def test_image_title(self):
        src = '![alt text](a.png "title")'
        self.conv(src)
        # title is not supported now


class TestHeading(RendererTestBase):
    def test_heading(self):
        src = '# head 1'
        out = self.conv(src)
        self.assertEqual(out, '\nhead 1\n' + '=' * 6 + '\n')

    def test_heading_multibyte(self):
        src = '# マルチバイト文字\n'
        out = self.conv(src)
        self.assertEqual(out, '\nマルチバイト文字\n' + '=' * 16 + '\n')


class TestList(RendererTestBase):
    def test_ul(self):
        src = '* list'
        out = self.conv(src)
        self.assertEqual(out, '\n\n* list\n')

    def test_ol(self):
        src = '1. list'
        out = self.conv(src)
        self.assertEqual(out, '\n\n#. list\n')

    def test_nested_ul(self):
        src = '\n'.join([
            '* list 1',
            '* list 2',
            '  * list 2.1',
            '  * list 2.2',
            '* list 3',
        ])
        out = self.conv(src)
        self.assertEqual(
            out,
            '\n\n* list 1\n'
            '* list 2\n\n'
            '  * list 2.1\n'
            '  * list 2.2\n\n'
            '* list 3\n',
        )

    def test_nested_ul_2(self):
        src = '\n'.join([
            '* list 1',
            '* list 2',
            '  * list 2.1',
            '  * list 2.2',
            '    * list 2.2.1',
            '    * list 2.2.2',
            '* list 3',
        ])
        out = self.conv(src)
        self.assertEqual(
            out,
            '\n\n* list 1\n'
            '* list 2\n\n'
            '  * list 2.1\n'
            '  * list 2.2\n\n'
            '    * list 2.2.1\n'
            '    * list 2.2.2\n\n'
            '* list 3\n'
        )

    def test_nested_ol(self):
        src = '\n'.join([
            '1. list 1',
            '2. list 2',
            '  2. list 2.1',
            '  3. list 2.2',
            '3. list 3',
        ])
        out = self.conv(src)
        self.assertEqual(
            out,
            '\n\n#. list 1\n'
            '#. list 2\n'
            '\n'
            '   #. list 2.1\n'
            '   #. list 2.2\n'
            '\n'
            '#. list 3\n',
        )

    def test_nested_ol_2(self):
        src = '\n'.join([
            '1. list 1',
            '2. list 2',
            '  3. list 2.1',
            '  4. list 2.2',
            '    5. list 2.2.1',
            '    6. list 2.2.2',
            '7. list 3',
        ])
        out = self.conv(src)
        self.assertEqual(
            out,
            '\n'.join([
                '\n\n#. list 1',
                '#. list 2',
                '',
                '   #. list 2.1',
                '   #. list 2.2',
                '',
                '      #. list 2.2.1',
                '      #. list 2.2.2',
                '',
                '#. list 3\n',
            ])
        )

    def test_nested_mixed_1(self):
        src = '\n'.join([
            '1. list 1',
            '2. list 2',
            '  * list 2.1',
            '  * list 2.2',
            '    1. list 2.2.1',
            '    2. list 2.2.2',
            '7. list 3',
        ])
        out = self.conv(src)
        self.assertEqual(
            out,
            '\n'.join([
                '\n\n#. list 1',
                '#. list 2',
                '',
                '   * list 2.1',
                '   * list 2.2',
                '',
                '     #. list 2.2.1',
                '     #. list 2.2.2',
                '',
                '#. list 3\n',
            ])
        )

    def test_nested_multiline_1(self):
        src = '\n'.join([
            '* list 1',
            '  list 1 cont',
            '* list 2',
            '  list 2 cont',
            '  * list 2.1',
            '    list 2.1 cont',
            '  * list 2.2',
            '    list 2.2 cont',
            '    * list 2.2.1',
            '    * list 2.2.2',
            '* list 3',
        ])
        out = self.conv(src)
        self.assertEqual(
            out,
            '\n'.join([
                '\n\n* list 1',
                '  list 1 cont',
                '* list 2',
                '  list 2 cont',
                '',
                '  * list 2.1',
                '    list 2.1 cont',
                '  * list 2.2',
                '    list 2.2 cont',
                '',
                '    * list 2.2.1',
                '    * list 2.2.2',
                '',
                '* list 3\n',
            ])
        )

    def test_nested_multiline_2(self):
        src = '\n'.join([
            '1. list 1',
            '  list 1 cont',
            '1. list 2',
            '  list 2 cont',
            '  1. list 2.1',
            '    list 2.1 cont',
            '  1. list 2.2',
            '    list 2.2 cont',
            '    1. list 2.2.1',
            '    1. list 2.2.2',
            '1. list 3',
        ])
        out = self.conv(src)
        self.assertEqual(
            out,
            '\n'.join([
                '\n\n#. list 1',
                '   list 1 cont',
                '#. list 2',
                '   list 2 cont',
                '',
                '   #. list 2.1',
                '      list 2.1 cont',
                '   #. list 2.2',
                '      list 2.2 cont',
                '',
                '      #. list 2.2.1',
                '      #. list 2.2.2',
                '',
                '#. list 3\n',
            ])
        )

    def test_nested_multiline_3(self):
        src = '\n'.join([
            '1. list 1',
            '  list 1 cont',
            '1. list 2',
            '  list 2 cont',
            '  * list 2.1',
            '    list 2.1 cont',
            '  * list 2.2',
            '    list 2.2 cont',
            '    1. list 2.2.1',
            '    1. list 2.2.2',
            '1. list 3',
        ])
        out = self.conv(src)
        self.assertEqual(
            out,
            '\n'.join([
                '\n\n#. list 1',
                '   list 1 cont',
                '#. list 2',
                '   list 2 cont',
                '',
                '   * list 2.1',
                '     list 2.1 cont',
                '   * list 2.2',
                '     list 2.2 cont',
                '',
                '     #. list 2.2.1',
                '     #. list 2.2.2',
                '',
                '#. list 3\n',
            ])
        )


class TestConplexText(RendererTestBase):
    def test_code(self):
        src = '''
some sentence
```python
print(1)
```
some sentence

# title
```python
print(1)
```
---
end
'''
        self.conv(src)


class TestTable(RendererTestBase):
    def test_table(self):
        src = '''h1 | h2 | h3\n--- | --- | ---\n1 | 2 | 3\n4 | 5 | 6'''
        out = self.conv(src)
        self.assertEqual(out, '\n'.join([
            '',
            '.. list-table::',
            '   :header-rows: 1',
            '',
            '   * - h1',
            '     - h2',
            '     - h3',
            '   * - 1',
            '     - 2',
            '     - 3',
            '   * - 4',
            '     - 5',
            '     - 6',
            '',
            '',
        ]))


class TestFootNote(RendererTestBase):
    def test_footnote(self):
        src = '\n'.join([
            'This is a[^1] footnote[^2] ref[^ref] with rst [#a]_.',
            '',
            '[^1]: note 1',
            '[^2]: note 2',
            '[^ref]: note ref',
            '.. [#a] note rst',
        ])
        out = self.conv(src)
        self.assertEqual(out, '\n'.join([
            '',
            'This is a\\ [#fn-1]_ '
            'footnote\\ [#fn-2]_ ref\\ [#fn-ref]_ with rst [#a]_.',
            '',
            '.. [#a] note rst',  # one empty line inserted...
            '',
            '.. [#fn-1] note 1',
            '.. [#fn-2] note 2',
            '.. [#fn-ref] note ref',
            '',
        ]))

    def test_sphinx_ref(self):
        src = 'This is a sphinx [ref]_ global ref.\n\n.. [ref] ref text'
        out = self.conv(src)
        self.assertEqual(out, '\n' + src)


class TestDirective(RendererTestBase):
    def test_comment_oneline(self):
        src = '.. a'
        out = self.conv(src)
        self.assertEqual(out, '\n.. a')

    def test_comment_indented(self):
        src = '    .. a'
        out = self.conv(src)
        self.assertEqual(out, '\n    .. a')

    def test_comment_newline(self):
        src = '..\n\n   comment\n\nnewline'
        out = self.conv(src)
        self.assertEqual(out, '\n..\n\n   comment\n\nnewline\n')

    def test_comment_multiline(self):
        comment = (
            '.. this is comment.\n'
            '   this is also comment.\n'
            '\n'
            '\n'
            '    comment may include empty line.\n'
            '\n\n')
        src = comment + '`eoc`'
        out = self.conv(src)
        self.assertEqual(out, '\n' + comment + '``eoc``\n')


class TestRestCode(RendererTestBase):
    def test_rest_code_block_empty(self):
        src = '\n\n::\n\n'
        out = self.conv(src)
        self.assertEqual(out, '\n\n')

    def test_eol_marker(self):
        src = 'a::\n\n    code\n'
        out = self.conv(src)
        self.assertEqual(out, '\na:\n\n.. code-block::\n\n   code\n')

    def test_eol_marker_remove(self):
        src = 'a ::\n\n    code\n'
        out = self.conv(src)
        self.assertEqual(out, '\na\n\n.. code-block::\n\n   code\n')