Debian Codegraph @

test/test_parsers/test_recommonmark/test_bullet_lists.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # :Copyright: © 2020 Günter Milde.
3 # :License: Released under the terms of the `2-Clause BSD license`_, in short:
4 #
5 # Copying and distribution of this file, with or without modification,
6 # are permitted in any medium without royalty provided the copyright
7 # notice and this notice are preserved.
8 # This file is offered as-is, without any warranty.
9 #
10 # .. _2-Clause BSD license: https://opensource.org/licenses/BSD-2-Clause
11
12 """
13 Test for bullet lists in CommonMark parsers.
14 Cf. the `CommonMark Specification <https://spec.commonmark.org/>`__
15 """
16
17 from pathlib import Path
18 import sys
19 import unittest
20
21 if __name__ == '__main__':
22 # prepend the "docutils root" to the Python library path
23 # so we import the local `docutils` package.
24 sys.path.insert(0, str(Path(__file__).resolve().parents[3]))
25
26 from docutils.frontend import get_default_settings
27 from docutils.parsers.recommonmark_wrapper import Parser
28 from docutils.utils import new_document
29
30
31 class RecommonmarkParserTestCase(unittest.TestCase):
32 def test_parser(self):
33 parser = Parser()
34 settings = get_default_settings(Parser)
35 for name, cases in totest.items():
36 for casenum, (case_input, case_expected) in enumerate(cases):
37 with self.subTest(id=f'totest[{name!r}][{casenum}]'):
38 document = new_document('test data', settings.copy())
39 parser.parse(case_input, document)
40 output = document.pformat()
41 self.assertEqual(case_expected, output)
42
43
44 totest = {}
45
46 totest['bullet_lists'] = [
47 ["""\
48 - item
49 """,
50 """\
51 <document source="test data">
52 <bullet_list>
53 <list_item>
54 <paragraph>
55 item
56 """],
57 ["""\
58 * item 1
59
60 * item 2
61 """,
62 """\
63 <document source="test data">
64 <bullet_list>
65 <list_item>
66 <paragraph>
67 item 1
68 <list_item>
69 <paragraph>
70 item 2
71 """],
72 ["""\
73 No blank line between:
74
75 + item 1
76 + item 2
77 """,
78 """\
79 <document source="test data">
80 <paragraph>
81 No blank line between:
82 <bullet_list>
83 <list_item>
84 <paragraph>
85 item 1
86 <list_item>
87 <paragraph>
88 item 2
89 """],
90 ["""\
91 - item 1, paragraph 1.
92
93 item 1, paragraph 2.
94
95 - item 2
96 """,
97 """\
98 <document source="test data">
99 <bullet_list>
100 <list_item>
101 <paragraph>
102 item 1, paragraph 1.
103 <paragraph>
104 item 1, paragraph 2.
105 <list_item>
106 <paragraph>
107 item 2
108 """],
109 ["""\
110 - item 1, line 1
111 item 1, line 2
112 - item 2
113 """,
114 """\
115 <document source="test data">
116 <bullet_list>
117 <list_item>
118 <paragraph>
119 item 1, line 1
120 item 1, line 2
121 <list_item>
122 <paragraph>
123 item 2
124 """],
125 ["""\
126 Different bullets start different lists:
127
128 - item 1
129
130 + item 1
131
132 * no blank line
133 - required between lists
134 """,
135 """\
136 <document source="test data">
137 <paragraph>
138 Different bullets start different lists:
139 <bullet_list>
140 <list_item>
141 <paragraph>
142 item 1
143 <bullet_list>
144 <list_item>
145 <paragraph>
146 item 1
147 <bullet_list>
148 <list_item>
149 <paragraph>
150 no blank line
151 <bullet_list>
152 <list_item>
153 <paragraph>
154 required between lists
155 """],
156 ["""\
157 - item 1
158 continuation of item 1
159 """,
160 """\
161 <document source="test data">
162 <bullet_list>
163 <list_item>
164 <paragraph>
165 item 1
166 continuation of item 1
167 """],
168 ["""\
169 -
170
171 empty item above
172 """,
173 """\
174 <document source="test data">
175 <bullet_list>
176 <list_item>
177 <paragraph>
178 empty item above
179 """],
180 ["""\
181 -
182 empty item above, no blank line
183 """,
184 """\
185 <document source="test data">
186 <bullet_list>
187 <list_item>
188 <paragraph>
189 empty item above, no blank line
190 """],
191 ["""\
192 Unicode bullets are not supported by CommonMark.
193
194 • BULLET
195
196 ‣ TRIANGULAR BULLET
197
198 ⁃ HYPHEN BULLET
199 """,
200 """\
201 <document source="test data">
202 <paragraph>
203 Unicode bullets are not supported by CommonMark.
204 <paragraph>
205 • BULLET
206 <paragraph>
207 ‣ TRIANGULAR BULLET
208 <paragraph>
209 ⁃ HYPHEN BULLET
210 """],
211 ]
212
213 if __name__ == '__main__':
214 unittest.main()