translations de: pull-quote = Seitenansprache, use utf8 for umlauts
[docutils.git] / test / test_transforms / test_footnotes.py
blobc07843a15910befb9a0959b4c381ee6f233f2931
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 docutils.transforms.references.Footnotes.
9 """
11 from __init__ import DocutilsTestSupport
12 from docutils.transforms.references import Footnotes
13 from docutils.parsers.rst import Parser
16 def suite():
17 parser = Parser()
18 s = DocutilsTestSupport.TransformTestSuite(parser)
19 s.generateTests(totest)
20 return s
22 totest = {}
24 totest['footnotes'] = ((Footnotes,), [
25 ["""\
26 [#autolabel]_
28 .. [#autolabel] text
29 """,
30 """\
31 <document source="test data">
32 <paragraph>
33 <footnote_reference auto="1" ids="id1" refid="autolabel">
35 <footnote auto="1" backrefs="id1" ids="autolabel" names="autolabel">
36 <label>
38 <paragraph>
39 text
40 """],
41 ["""\
42 autonumber: [#]_
44 .. [#] text
45 """,
46 """\
47 <document source="test data">
48 <paragraph>
49 autonumber: \n\
50 <footnote_reference auto="1" ids="id1" refid="id2">
52 <footnote auto="1" backrefs="id1" ids="id2" names="1">
53 <label>
55 <paragraph>
56 text
57 """],
58 ["""\
59 [#]_ is the first auto-numbered footnote reference.
60 [#]_ is the second auto-numbered footnote reference.
62 .. [#] Auto-numbered footnote 1.
63 .. [#] Auto-numbered footnote 2.
64 .. [#] Auto-numbered footnote 3.
66 [#]_ is the third auto-numbered footnote reference.
67 """,
68 """\
69 <document source="test data">
70 <paragraph>
71 <footnote_reference auto="1" ids="id1" refid="id3">
73 is the first auto-numbered footnote reference.
74 <footnote_reference auto="1" ids="id2" refid="id4">
76 is the second auto-numbered footnote reference.
77 <footnote auto="1" backrefs="id1" ids="id3" names="1">
78 <label>
80 <paragraph>
81 Auto-numbered footnote 1.
82 <footnote auto="1" backrefs="id2" ids="id4" names="2">
83 <label>
85 <paragraph>
86 Auto-numbered footnote 2.
87 <footnote auto="1" backrefs="id6" ids="id5" names="3">
88 <label>
90 <paragraph>
91 Auto-numbered footnote 3.
92 <paragraph>
93 <footnote_reference auto="1" ids="id6" refid="id5">
95 is the third auto-numbered footnote reference.
96 """],
97 ["""\
98 [#third]_ is a reference to the third auto-numbered footnote.
100 .. [#first] First auto-numbered footnote.
101 .. [#second] Second auto-numbered footnote.
102 .. [#third] Third auto-numbered footnote.
104 [#second]_ is a reference to the second auto-numbered footnote.
105 [#first]_ is a reference to the first auto-numbered footnote.
106 [#third]_ is another reference to the third auto-numbered footnote.
108 Here are some internal cross-references to the implicit targets
109 generated by the footnotes: first_, second_, third_.
110 """,
111 """\
112 <document source="test data">
113 <paragraph>
114 <footnote_reference auto="1" ids="id1" refid="third">
116 is a reference to the third auto-numbered footnote.
117 <footnote auto="1" backrefs="id3" ids="first" names="first">
118 <label>
120 <paragraph>
121 First auto-numbered footnote.
122 <footnote auto="1" backrefs="id2" ids="second" names="second">
123 <label>
125 <paragraph>
126 Second auto-numbered footnote.
127 <footnote auto="1" backrefs="id1 id4" ids="third" names="third">
128 <label>
130 <paragraph>
131 Third auto-numbered footnote.
132 <paragraph>
133 <footnote_reference auto="1" ids="id2" refid="second">
135 is a reference to the second auto-numbered footnote.
136 <footnote_reference auto="1" ids="id3" refid="first">
138 is a reference to the first auto-numbered footnote.
139 <footnote_reference auto="1" ids="id4" refid="third">
141 is another reference to the third auto-numbered footnote.
142 <paragraph>
143 Here are some internal cross-references to the implicit targets
144 generated by the footnotes: \n\
145 <reference name="first" refname="first">
146 first
147 , \n\
148 <reference name="second" refname="second">
149 second
150 , \n\
151 <reference name="third" refname="third">
152 third
154 """],
155 ["""\
156 Mixed anonymous and labelled auto-numbered footnotes:
158 [#four]_ should be 4, [#]_ should be 1,
159 [#]_ should be 3, [#]_ is one too many,
160 [#two]_ should be 2, and [#six]_ doesn't exist.
162 .. [#] Auto-numbered footnote 1.
163 .. [#two] Auto-numbered footnote 2.
164 .. [#] Auto-numbered footnote 3.
165 .. [#four] Auto-numbered footnote 4.
166 .. [#five] Auto-numbered footnote 5.
167 .. [#five] Auto-numbered footnote 5 again (duplicate).
168 """,
169 """\
170 <document source="test data">
171 <paragraph>
172 Mixed anonymous and labelled auto-numbered footnotes:
173 <paragraph>
174 <footnote_reference auto="1" ids="id1" refid="four">
176 should be 4, \n\
177 <footnote_reference auto="1" ids="id2" refid="id7">
179 should be 1,
180 <footnote_reference auto="1" ids="id3" refid="id8">
182 should be 3, \n\
183 <problematic ids="id11 id4" refid="id10">
184 [#]_
185 is one too many,
186 <footnote_reference auto="1" ids="id5" refid="two">
188 should be 2, and \n\
189 <footnote_reference auto="1" ids="id6" refname="six">
190 doesn't exist.
191 <footnote auto="1" backrefs="id2" ids="id7" names="1">
192 <label>
194 <paragraph>
195 Auto-numbered footnote 1.
196 <footnote auto="1" backrefs="id5" ids="two" names="two">
197 <label>
199 <paragraph>
200 Auto-numbered footnote 2.
201 <footnote auto="1" backrefs="id3" ids="id8" names="3">
202 <label>
204 <paragraph>
205 Auto-numbered footnote 3.
206 <footnote auto="1" backrefs="id1" ids="four" names="four">
207 <label>
209 <paragraph>
210 Auto-numbered footnote 4.
211 <footnote auto="1" dupnames="five" ids="five">
212 <label>
214 <paragraph>
215 Auto-numbered footnote 5.
216 <footnote auto="1" dupnames="five" ids="id9">
217 <label>
219 <system_message backrefs="id9" level="2" line="12" source="test data" type="WARNING">
220 <paragraph>
221 Duplicate explicit target name: "five".
222 <paragraph>
223 Auto-numbered footnote 5 again (duplicate).
224 <system_message backrefs="id11" ids="id10" level="3" line="3" source="test data" type="ERROR">
225 <paragraph>
226 Too many autonumbered footnote references: only 2 corresponding footnotes available.
227 """],
228 ["""\
229 Mixed auto-numbered and manual footnotes:
231 .. [1] manually numbered
232 .. [#] auto-numbered
233 .. [#label] autonumber-labeled
234 """,
235 """\
236 <document source="test data">
237 <paragraph>
238 Mixed auto-numbered and manual footnotes:
239 <footnote ids="id1" names="1">
240 <label>
242 <paragraph>
243 manually numbered
244 <footnote auto="1" ids="id2" names="2">
245 <label>
247 <paragraph>
248 auto-numbered
249 <footnote auto="1" ids="label" names="label">
250 <label>
252 <paragraph>
253 autonumber-labeled
254 """],
255 ["""\
256 A labeled autonumbered footnote referece: [#footnote]_.
258 An unlabeled autonumbered footnote referece: [#]_.
260 .. [#] Unlabeled autonumbered footnote.
261 .. [#footnote] Labeled autonumbered footnote.
262 Note that the footnotes are not in the same
263 order as the references.
264 """,
265 """\
266 <document source="test data">
267 <paragraph>
268 A labeled autonumbered footnote referece: \n\
269 <footnote_reference auto="1" ids="id1" refid="footnote">
272 <paragraph>
273 An unlabeled autonumbered footnote referece: \n\
274 <footnote_reference auto="1" ids="id2" refid="id3">
277 <footnote auto="1" backrefs="id2" ids="id3" names="1">
278 <label>
280 <paragraph>
281 Unlabeled autonumbered footnote.
282 <footnote auto="1" backrefs="id1" ids="footnote" names="footnote">
283 <label>
285 <paragraph>
286 Labeled autonumbered footnote.
287 Note that the footnotes are not in the same
288 order as the references.
289 """],
290 ["""\
291 Mixed manually-numbered, anonymous auto-numbered,
292 and labelled auto-numbered footnotes:
294 [#four]_ should be 4, [#]_ should be 2,
295 [1]_ is 1, [3]_ is 3,
296 [#]_ should be 6, [#]_ is one too many,
297 [#five]_ should be 5, and [#eight]_ doesn't exist.
299 .. [1] Manually-numbered footnote 1.
300 .. [#] Auto-numbered footnote 2.
301 .. [#four] Auto-numbered footnote 4.
302 .. [3] Manually-numbered footnote 3
303 .. [#five] Auto-numbered footnote 5.
304 .. [#] Auto-numbered footnote 6.
305 .. [#five] Auto-numbered footnote 5 again (duplicate).
306 """,
307 """\
308 <document source="test data">
309 <paragraph>
310 Mixed manually-numbered, anonymous auto-numbered,
311 and labelled auto-numbered footnotes:
312 <paragraph>
313 <footnote_reference auto="1" ids="id1" refid="four">
315 should be 4, \n\
316 <footnote_reference auto="1" ids="id2" refid="id10">
318 should be 2,
319 <footnote_reference ids="id3" refid="id9">
321 is 1, \n\
322 <footnote_reference ids="id4" refid="id11">
324 is 3,
325 <footnote_reference auto="1" ids="id5" refid="id12">
327 should be 6, \n\
328 <problematic ids="id15 id6" refid="id14">
329 [#]_
330 is one too many,
331 <footnote_reference auto="1" ids="id7" refname="five">
332 should be 5, and \n\
333 <footnote_reference auto="1" ids="id8" refname="eight">
334 doesn't exist.
335 <footnote backrefs="id3" ids="id9" names="1">
336 <label>
338 <paragraph>
339 Manually-numbered footnote 1.
340 <footnote auto="1" backrefs="id2" ids="id10" names="2">
341 <label>
343 <paragraph>
344 Auto-numbered footnote 2.
345 <footnote auto="1" backrefs="id1" ids="four" names="four">
346 <label>
348 <paragraph>
349 Auto-numbered footnote 4.
350 <footnote backrefs="id4" ids="id11" names="3">
351 <label>
353 <paragraph>
354 Manually-numbered footnote 3
355 <footnote auto="1" dupnames="five" ids="five">
356 <label>
358 <paragraph>
359 Auto-numbered footnote 5.
360 <footnote auto="1" backrefs="id5" ids="id12" names="6">
361 <label>
363 <paragraph>
364 Auto-numbered footnote 6.
365 <footnote auto="1" dupnames="five" ids="id13">
366 <label>
368 <system_message backrefs="id13" level="2" line="15" source="test data" type="WARNING">
369 <paragraph>
370 Duplicate explicit target name: "five".
371 <paragraph>
372 Auto-numbered footnote 5 again (duplicate).
373 <system_message backrefs="id15" ids="id14" level="3" line="4" source="test data" type="ERROR">
374 <paragraph>
375 Too many autonumbered footnote references: only 2 corresponding footnotes available.
376 """],
377 ["""\
378 Referencing a footnote by symbol [*]_.
380 .. [*] This is an auto-symbol footnote.
381 """,
382 """\
383 <document source="test data">
384 <paragraph>
385 Referencing a footnote by symbol \n\
386 <footnote_reference auto="*" ids="id1" refid="id2">
389 <footnote auto="*" backrefs="id1" ids="id2">
390 <label>
392 <paragraph>
393 This is an auto-symbol footnote.
394 """],
395 ["""\
396 A sequence of symbol footnote references:
397 [*]_ [*]_ [*]_ [*]_ [*]_ [*]_ [*]_ [*]_ [*]_ [*]_ [*]_ [*]_.
399 .. [*] Auto-symbol footnote 1.
400 .. [*] Auto-symbol footnote 2.
401 .. [*] Auto-symbol footnote 3.
402 .. [*] Auto-symbol footnote 4.
403 .. [*] Auto-symbol footnote 5.
404 .. [*] Auto-symbol footnote 6.
405 .. [*] Auto-symbol footnote 7.
406 .. [*] Auto-symbol footnote 8.
407 .. [*] Auto-symbol footnote 9.
408 .. [*] Auto-symbol footnote 10.
409 .. [*] Auto-symbol footnote 11.
410 .. [*] Auto-symbol footnote 12.
411 """,
412 u"""\
413 <document source="test data">
414 <paragraph>
415 A sequence of symbol footnote references:
416 <footnote_reference auto="*" ids="id1" refid="id13">
419 <footnote_reference auto="*" ids="id2" refid="id14">
420 \u2020
422 <footnote_reference auto="*" ids="id3" refid="id15">
423 \u2021
425 <footnote_reference auto="*" ids="id4" refid="id16">
426 \u00A7
428 <footnote_reference auto="*" ids="id5" refid="id17">
429 \u00B6
431 <footnote_reference auto="*" ids="id6" refid="id18">
434 <footnote_reference auto="*" ids="id7" refid="id19">
435 \u2660
437 <footnote_reference auto="*" ids="id8" refid="id20">
438 \u2665
440 <footnote_reference auto="*" ids="id9" refid="id21">
441 \u2666
443 <footnote_reference auto="*" ids="id10" refid="id22">
444 \u2663
446 <footnote_reference auto="*" ids="id11" refid="id23">
449 <footnote_reference auto="*" ids="id12" refid="id24">
450 \u2020\u2020
452 <footnote auto="*" backrefs="id1" ids="id13">
453 <label>
455 <paragraph>
456 Auto-symbol footnote 1.
457 <footnote auto="*" backrefs="id2" ids="id14">
458 <label>
459 \u2020
460 <paragraph>
461 Auto-symbol footnote 2.
462 <footnote auto="*" backrefs="id3" ids="id15">
463 <label>
464 \u2021
465 <paragraph>
466 Auto-symbol footnote 3.
467 <footnote auto="*" backrefs="id4" ids="id16">
468 <label>
469 \u00A7
470 <paragraph>
471 Auto-symbol footnote 4.
472 <footnote auto="*" backrefs="id5" ids="id17">
473 <label>
474 \u00B6
475 <paragraph>
476 Auto-symbol footnote 5.
477 <footnote auto="*" backrefs="id6" ids="id18">
478 <label>
480 <paragraph>
481 Auto-symbol footnote 6.
482 <footnote auto="*" backrefs="id7" ids="id19">
483 <label>
484 \u2660
485 <paragraph>
486 Auto-symbol footnote 7.
487 <footnote auto="*" backrefs="id8" ids="id20">
488 <label>
489 \u2665
490 <paragraph>
491 Auto-symbol footnote 8.
492 <footnote auto="*" backrefs="id9" ids="id21">
493 <label>
494 \u2666
495 <paragraph>
496 Auto-symbol footnote 9.
497 <footnote auto="*" backrefs="id10" ids="id22">
498 <label>
499 \u2663
500 <paragraph>
501 Auto-symbol footnote 10.
502 <footnote auto="*" backrefs="id11" ids="id23">
503 <label>
505 <paragraph>
506 Auto-symbol footnote 11.
507 <footnote auto="*" backrefs="id12" ids="id24">
508 <label>
509 \u2020\u2020
510 <paragraph>
511 Auto-symbol footnote 12.
512 """],
513 ["""\
514 Duplicate manual footnote labels:
516 .. [1] Footnote.
518 .. [1] Footnote.
519 """,
520 """\
521 <document source="test data">
522 <paragraph>
523 Duplicate manual footnote labels:
524 <footnote dupnames="1" ids="id1">
525 <label>
527 <paragraph>
528 Footnote.
529 <footnote dupnames="1" ids="id2">
530 <label>
532 <system_message backrefs="id2" level="2" line="5" source="test data" type="WARNING">
533 <paragraph>
534 Duplicate explicit target name: "1".
535 <paragraph>
536 Footnote.
537 """],
541 if __name__ == '__main__':
542 import unittest
543 unittest.main(defaultTest='suite')