| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
""" |
| 8 |
Tests for the body.py 'line-block' directive. |
| 9 |
""" |
| 10 |
|
| 11 |
from pathlib import Path |
| 12 |
import sys |
| 13 |
import unittest |
| 14 |
|
| 15 |
if __name__ == '__main__': |
| 16 |
|
| 17 |
|
| 18 |
sys.path.insert(0, str(Path(__file__).resolve().parents[4])) |
| 19 |
|
| 20 |
from docutils.frontend import get_default_settings |
| 21 |
from docutils.parsers.rst import Parser |
| 22 |
from docutils.utils import new_document |
| 23 |
|
| 24 |
|
| 25 |
class ParserTestCase(unittest.TestCase): |
| 26 |
def test_parser(self): |
| 27 |
parser = Parser() |
| 28 |
settings = get_default_settings(Parser) |
| 29 |
settings.warning_stream = '' |
| 30 |
for name, cases in totest.items(): |
| 31 |
for casenum, (case_input, case_expected) in enumerate(cases): |
| 32 |
with self.subTest(id=f'totest[{name!r}][{casenum}]'): |
| 33 |
document = new_document('test data', settings.copy()) |
| 34 |
parser.parse(case_input, document) |
| 35 |
output = document.pformat() |
| 36 |
self.assertEqual(case_expected, output) |
| 37 |
|
| 38 |
|
| 39 |
totest = {} |
| 40 |
|
| 41 |
totest['line_blocks'] = [ |
| 42 |
["""\ |
| 43 |
.. line-block:: |
| 44 |
|
| 45 |
This is a line block. |
| 46 |
Newlines are *preserved*. |
| 47 |
As is initial whitespace. |
| 48 |
""", |
| 49 |
"""\ |
| 50 |
<document source="test data"> |
| 51 |
<line_block> |
| 52 |
<line> |
| 53 |
This is a line block. |
| 54 |
<line> |
| 55 |
Newlines are \n\ |
| 56 |
<emphasis> |
| 57 |
preserved |
| 58 |
. |
| 59 |
<line_block> |
| 60 |
<line> |
| 61 |
As is initial whitespace. |
| 62 |
"""], |
| 63 |
["""\ |
| 64 |
.. line-block:: |
| 65 |
:class: linear |
| 66 |
:name: cit:short |
| 67 |
|
| 68 |
This is a line block with options. |
| 69 |
""", |
| 70 |
"""\ |
| 71 |
<document source="test data"> |
| 72 |
<line_block classes="linear" ids="cit-short" names="cit:short"> |
| 73 |
<line> |
| 74 |
This is a line block with options. |
| 75 |
"""], |
| 76 |
["""\ |
| 77 |
.. line-block:: |
| 78 |
|
| 79 |
Inline markup *may not span |
| 80 |
multiple lines* of a line block. |
| 81 |
""", |
| 82 |
"""\ |
| 83 |
<document source="test data"> |
| 84 |
<line_block> |
| 85 |
<line> |
| 86 |
Inline markup \n\ |
| 87 |
<problematic ids="problematic-1" refid="system-message-1"> |
| 88 |
* |
| 89 |
may not span |
| 90 |
<line_block> |
| 91 |
<line> |
| 92 |
multiple lines* of a line block. |
| 93 |
<system_message backrefs="problematic-1" ids="system-message-1" level="2" line="3" source="test data" type="WARNING"> |
| 94 |
<paragraph> |
| 95 |
Inline emphasis start-string without end-string. |
| 96 |
"""], |
| 97 |
["""\ |
| 98 |
.. line-block:: |
| 99 |
""", |
| 100 |
"""\ |
| 101 |
<document source="test data"> |
| 102 |
<system_message level="3" line="1" source="test data" type="ERROR"> |
| 103 |
<paragraph> |
| 104 |
Content block expected for the "line-block" directive; none found. |
| 105 |
<literal_block xml:space="preserve"> |
| 106 |
.. line-block:: |
| 107 |
"""], |
| 108 |
] |
| 109 |
|
| 110 |
|
| 111 |
if __name__ == '__main__': |
| 112 |
unittest.main() |