Website: add template and basic stylesheet with menu. Update buildhtml.py (and theref...
[docutils.git] / sandbox / gitpull / web_stylesheet_and_menu / test / test_parsers / test_rst / test_substitutions.py
blob50b414abce0d1c2ce271c5a344037140b67a9ded
1 #! /usr/bin/env python
3 # $Id$
4 # Author: David Goodger <goodger@python.org>
5 # Copyright: This module has been placed in the public domain.
7 """
8 Tests for states.py.
9 """
11 from __init__ import DocutilsTestSupport
13 def suite():
14 s = DocutilsTestSupport.ParserTestSuite()
15 s.generateTests(totest)
16 return s
18 totest = {}
20 totest['substitution_definitions'] = [
21 ["""\
22 Here's an image substitution definition:
24 .. |symbol| image:: symbol.png
25 """,
26 """\
27 <document source="test data">
28 <paragraph>
29 Here's an image substitution definition:
30 <substitution_definition names="symbol">
31 <image alt="symbol" uri="symbol.png">
32 """],
33 ["""\
34 Embedded directive starts on the next line:
36 .. |symbol|
37 image:: symbol.png
38 """,
39 """\
40 <document source="test data">
41 <paragraph>
42 Embedded directive starts on the next line:
43 <substitution_definition names="symbol">
44 <image alt="symbol" uri="symbol.png">
45 """],
46 ["""\
47 Trailing spaces should not be significant:
49 .. |symbol| image:: \n\
50 symbol.png
51 """,
52 """\
53 <document source="test data">
54 <paragraph>
55 Trailing spaces should not be significant:
56 <substitution_definition names="symbol">
57 <image alt="symbol" uri="symbol.png">
58 """],
59 ["""\
60 Here's a series of substitution definitions:
62 .. |symbol 1| image:: symbol1.png
63 .. |SYMBOL 2| image:: symbol2.png
64 :height: 50
65 :width: 100
66 .. |symbol 3| image:: symbol3.png
67 """,
68 """\
69 <document source="test data">
70 <paragraph>
71 Here's a series of substitution definitions:
72 <substitution_definition names="symbol\ 1">
73 <image alt="symbol 1" uri="symbol1.png">
74 <substitution_definition names="SYMBOL\ 2">
75 <image alt="SYMBOL 2" height="50" uri="symbol2.png" width="100">
76 <substitution_definition names="symbol\ 3">
77 <image alt="symbol 3" uri="symbol3.png">
78 """],
79 ["""\
80 .. |very long substitution text,
81 split across lines| image:: symbol.png
82 """,
83 """\
84 <document source="test data">
85 <substitution_definition names="very\ long\ substitution\ text,\ split\ across\ lines">
86 <image alt="very long substitution text, split across lines" uri="symbol.png">
87 """],
88 ["""\
89 .. |symbol 1| image:: symbol.png
91 Followed by a block quote.
92 """,
93 """\
94 <document source="test data">
95 <system_message level="3" line="1" source="test data" type="ERROR">
96 <paragraph>
97 Error in "image" directive:
98 no content permitted.
99 <literal_block xml:space="preserve">
100 image:: symbol.png
102 Followed by a block quote.
103 <system_message level="2" line="1" source="test data" type="WARNING">
104 <paragraph>
105 Substitution definition "symbol 1" empty or invalid.
106 <literal_block xml:space="preserve">
107 .. |symbol 1| image:: symbol.png
109 Followed by a block quote.
110 """],
111 ["""\
112 .. |symbol 1| image:: symbol.png
114 Followed by a paragraph.
116 .. |symbol 2| image:: symbol.png
120 Followed by a block quote.
121 """,
122 """\
123 <document source="test data">
124 <substitution_definition names="symbol\ 1">
125 <image alt="symbol 1" uri="symbol.png">
126 <paragraph>
127 Followed by a paragraph.
128 <substitution_definition names="symbol\ 2">
129 <image alt="symbol 2" uri="symbol.png">
130 <comment xml:space="preserve">
131 <block_quote>
132 <paragraph>
133 Followed by a block quote.
134 """],
135 [u"""\
136 Substitutions support case differences:
138 .. |eacute| replace:: \u00E9
139 .. |Eacute| replace:: \u00C9
140 """,
141 u"""\
142 <document source="test data">
143 <paragraph>
144 Substitutions support case differences:
145 <substitution_definition names="eacute">
146 \u00E9
147 <substitution_definition names="Eacute">
148 \u00C9
149 """],
150 ["""\
151 Raw substitution, backslashes should be preserved:
153 .. |alpha| raw:: latex
155 $\\\\alpha$
156 """,
157 """\
158 <document source="test data">
159 <paragraph>
160 Raw substitution, backslashes should be preserved:
161 <substitution_definition names="alpha">
162 <raw format="latex" xml:space="preserve">
163 $\\\\alpha$
164 """],
165 ["""\
166 Here are some duplicate substitution definitions:
168 .. |symbol| image:: symbol.png
169 .. |symbol| image:: symbol.png
170 """,
171 """\
172 <document source="test data">
173 <paragraph>
174 Here are some duplicate substitution definitions:
175 <substitution_definition dupnames="symbol">
176 <image alt="symbol" uri="symbol.png">
177 <system_message level="3" line="4" source="test data" type="ERROR">
178 <paragraph>
179 Duplicate substitution definition name: "symbol".
180 <substitution_definition names="symbol">
181 <image alt="symbol" uri="symbol.png">
182 """],
183 ["""\
184 Here are some bad cases:
186 .. |symbol| image:: symbol.png
187 No blank line after.
189 .. |empty|
191 .. |unknown| directive:: symbol.png
193 .. |invalid 1| there's no directive here
194 .. |invalid 2| there's no directive here
195 With some block quote text, line 1.
196 And some more, line 2.
198 .. |invalid 3| there's no directive here
200 .. | bad name | bad data
202 .. |
203 """,
204 """\
205 <document source="test data">
206 <paragraph>
207 Here are some bad cases:
208 <substitution_definition names="symbol">
209 <image alt="symbol" uri="symbol.png">
210 <system_message level="2" line="4" source="test data" type="WARNING">
211 <paragraph>
212 Explicit markup ends without a blank line; unexpected unindent.
213 <paragraph>
214 No blank line after.
215 <system_message level="2" line="6" source="test data" type="WARNING">
216 <paragraph>
217 Substitution definition "empty" missing contents.
218 <literal_block xml:space="preserve">
219 .. |empty|
220 <system_message level="1" line="8" source="test data" type="INFO">
221 <paragraph>
222 No directive entry for "directive" in module "docutils.parsers.rst.languages.en".
223 Trying "directive" as canonical directive name.
224 <system_message level="3" line="8" source="test data" type="ERROR">
225 <paragraph>
226 Unknown directive type "directive".
227 <literal_block xml:space="preserve">
228 directive:: symbol.png
229 <system_message level="2" line="8" source="test data" type="WARNING">
230 <paragraph>
231 Substitution definition "unknown" empty or invalid.
232 <literal_block xml:space="preserve">
233 .. |unknown| directive:: symbol.png
234 <system_message level="2" line="10" source="test data" type="WARNING">
235 <paragraph>
236 Substitution definition "invalid 1" empty or invalid.
237 <literal_block xml:space="preserve">
238 .. |invalid 1| there's no directive here
239 <system_message level="2" line="11" source="test data" type="WARNING">
240 <paragraph>
241 Substitution definition "invalid 2" empty or invalid.
242 <literal_block xml:space="preserve">
243 .. |invalid 2| there's no directive here
244 With some block quote text, line 1.
245 And some more, line 2.
246 <system_message level="2" line="15" source="test data" type="WARNING">
247 <paragraph>
248 Substitution definition "invalid 3" empty or invalid.
249 <literal_block xml:space="preserve">
250 .. |invalid 3| there's no directive here
251 <comment xml:space="preserve">
252 | bad name | bad data
253 <comment xml:space="preserve">
255 """],
256 ["""\
257 Elements that are prohibited inside of substitution definitions:
259 .. |target| replace:: _`target`
260 .. |reference| replace:: anonymous__
261 .. |auto-numbered footnote| replace:: [#]_
262 """,
263 """\
264 <document source="test data">
265 <paragraph>
266 Elements that are prohibited inside of substitution definitions:
267 <system_message level="3" line="3" source="test data" type="ERROR">
268 <paragraph>
269 Substitution definition contains illegal element:
270 <literal_block xml:space="preserve">
271 <target ids="target" names="target">
272 target
273 <literal_block xml:space="preserve">
274 .. |target| replace:: _`target`
275 <system_message level="3" line="4" source="test data" type="ERROR">
276 <paragraph>
277 Substitution definition contains illegal element:
278 <literal_block xml:space="preserve">
279 <reference anonymous="1" name="anonymous">
280 anonymous
281 <literal_block xml:space="preserve">
282 .. |reference| replace:: anonymous__
283 <system_message level="3" line="5" source="test data" type="ERROR">
284 <paragraph>
285 Substitution definition contains illegal element:
286 <literal_block xml:space="preserve">
287 <footnote_reference auto="1" ids="id1">
288 <literal_block xml:space="preserve">
289 .. |auto-numbered footnote| replace:: [#]_
290 """],
294 if __name__ == '__main__':
295 import unittest
296 unittest.main(defaultTest='suite')