4 # Author: David Goodger <goodger@python.org>
5 # Copyright: This module has been placed in the public domain.
8 Tests for docutils.transforms.references.Substitutions.
11 from __init__
import DocutilsTestSupport
12 from docutils
.transforms
.references
import Substitutions
13 from docutils
.parsers
.rst
import Parser
18 s
= DocutilsTestSupport
.TransformTestSuite(parser
)
19 s
.generateTests(totest
)
24 totest
['substitutions'] = ((Substitutions
,), [
26 The |biohazard| symbol is deservedly scary-looking.
28 .. |biohazard| image:: biohazard.png
31 <document source="test data">
34 <image alt="biohazard" uri="biohazard.png">
35 symbol is deservedly scary-looking.
36 <substitution_definition names="biohazard">
37 <image alt="biohazard" uri="biohazard.png">
40 Here's an |unknown| substitution.
43 <document source="test data">
46 <problematic ids="id2" refid="id1">
49 <system_message backrefs="id2" ids="id1" level="3" line="1" source="test data" type="ERROR">
51 Undefined substitution referenced: "unknown".
54 Substitutions support case differences:
56 .. |eacute| replace:: \u00E9
57 .. |Eacute| replace:: \u00C9
59 |Eacute|\\t\\ |eacute|, and even |EACUTE|.
62 <document source="test data">
64 Substitutions support case differences:
65 <substitution_definition names="eacute">
67 <substitution_definition names="Eacute">
78 Indirect substitution definitions with multiple references:
80 |substitute| my coke for gin
81 |substitute| you for my mum
82 at least I'll get my washing done
84 .. |substitute| replace:: |replace|
85 .. |replace| replace:: swap
88 <document source="test data">
90 Indirect substitution definitions with multiple references:
96 at least I'll get my washing done
97 <substitution_definition names="substitute">
99 <substitution_definition names="replace">
103 .. |l| unicode:: U+00AB .. left chevron
104 .. |r| unicode:: U+00BB .. right chevron
105 .. |.| replace:: |l|\ ``.``\ |r|
107 .. Delete either of the following lines, and there is no error.
109 Regular expression |.| will match any character
111 .. Note:: Note that |.| matches *exactly* one character
114 <document source="test data">
115 <substitution_definition names="l">
117 <substitution_definition names="r">
119 <substitution_definition names=".">
124 <comment xml:space="preserve">
125 Delete either of the following lines, and there is no error.
127 Regular expression \n\
132 will match any character
146 .. |sub| replace:: |sub|
149 <document source="test data">
150 <system_message level="3" line="1" names="sub" source="test data" type="ERROR">
152 Circular substitution definition detected:
153 <literal_block xml:space="preserve">
154 .. |sub| replace:: |sub|
157 .. |sub| replace:: |indirect1|
158 .. |indirect1| replace:: |indirect2|
159 .. |indirect2| replace:: |Sub|
162 <document source="test data">
163 <system_message level="3" line="1" names="sub" source="test data" type="ERROR">
165 Circular substitution definition detected:
166 <literal_block xml:space="preserve">
167 .. |sub| replace:: |indirect1|
168 <system_message level="3" line="2" names="indirect1" source="test data" type="ERROR">
170 Circular substitution definition detected:
171 <literal_block xml:space="preserve">
172 .. |indirect1| replace:: |indirect2|
173 <system_message level="3" line="3" names="indirect2" source="test data" type="ERROR">
175 Circular substitution definition detected:
176 <literal_block xml:space="preserve">
177 .. |indirect2| replace:: |Sub|
180 .. |indirect1| replace:: |indirect2|
181 .. |indirect2| replace:: |Sub|
182 .. |sub| replace:: |indirect1|
184 Use |sub| and |indirect1| and |sub| again (and |sub| one more time).
187 <document source="test data">
188 <system_message level="3" line="1" names="indirect1" source="test data" type="ERROR">
190 Circular substitution definition detected:
191 <literal_block xml:space="preserve">
192 .. |indirect1| replace:: |indirect2|
193 <system_message level="3" line="2" names="indirect2" source="test data" type="ERROR">
195 Circular substitution definition detected:
196 <literal_block xml:space="preserve">
197 .. |indirect2| replace:: |Sub|
198 <system_message level="3" line="3" names="sub" source="test data" type="ERROR">
200 Circular substitution definition detected:
201 <literal_block xml:space="preserve">
202 .. |sub| replace:: |indirect1|
205 <problematic ids="id8" refid="id7">
207 <problematic ids="id2" refid="id1">
210 <problematic ids="id4" refid="id3">
213 <problematic ids="id6" refid="id5">
216 <system_message backrefs="id2" ids="id1" level="3" line="5" source="test data" type="ERROR">
218 Circular substitution definition referenced: "indirect1".
219 <system_message backrefs="id4" ids="id3" level="3" line="5" source="test data" type="ERROR">
221 Circular substitution definition referenced: "sub".
222 <system_message backrefs="id6" ids="id5" level="3" line="5" source="test data" type="ERROR">
224 Circular substitution definition referenced: "sub".
225 <system_message backrefs="id8" ids="id7" level="3" source="test data" type="ERROR">
227 Circular substitution definition referenced: "Sub".
231 totest
['unicode'] = ((Substitutions
,), [
233 Insert an em-dash (|mdash|), a copyright symbol (|copy|), a non-breaking
234 space (|nbsp|), a backwards-not-equals (|bne|), and a captial omega (|Omega|).
236 .. |mdash| unicode:: 0x02014
237 .. |copy| unicode:: \\u00A9
238 .. |nbsp| unicode::  
239 .. |bne| unicode:: U0003D U020E5
240 .. |Omega| unicode:: U+003A9
243 <document source="test data">
247 ), a copyright symbol (
252 ), a backwards-not-equals (
255 ), and a captial omega (
258 <substitution_definition names="mdash">
260 <substitution_definition names="copy">
262 <substitution_definition names="nbsp">
264 <substitution_definition names="bne">
267 <substitution_definition names="Omega">
271 Testing comments and extra text.
273 Copyright |copy| 2003, |BogusMegaCorp (TM)|.
275 .. |copy| unicode:: 0xA9 .. copyright sign
276 .. |BogusMegaCorp (TM)| unicode:: BogusMegaCorp U+2122
277 .. with trademark sign
280 <document source="test data">
282 Testing comments and extra text.
290 <substitution_definition names="copy">
292 <substitution_definition names="BogusMegaCorp\ (TM)">
297 Insert an em-dash |---| automatically trimming whitespace.
298 Some substitutions |TM| only need |rarrow| trimming on one side.
300 .. |---| unicode:: U+02014
302 .. |TM| unicode:: U+02122
304 .. |rarrow| unicode:: U+2192
308 <document source="test data">
312 automatically trimming whitespace.
317 trimming on one side.
318 <substitution_definition ltrim="1" names="---" rtrim="1">
320 <substitution_definition ltrim="1" names="TM">
322 <substitution_definition names="rarrow" rtrim="1">
326 Substitution definition with an illegal element:
328 .. |target| replace:: _`target`
330 Make sure this substitution definition is not registered: |target|
333 <document source="test data">
335 Substitution definition with an illegal element:
336 <system_message level="3" line="3" source="test data" type="ERROR">
338 Substitution definition contains illegal element:
339 <literal_block xml:space="preserve">
340 <target ids="target" names="target">
342 <literal_block xml:space="preserve">
343 .. |target| replace:: _`target`
345 Make sure this substitution definition is not registered: \n\
346 <problematic ids="id2" refid="id1">
348 <system_message backrefs="id2" ids="id1" level="3" line="5" source="test data" type="ERROR">
350 Undefined substitution referenced: "target".
355 if __name__
== '__main__':
357 unittest
.main(defaultTest
='suite')