You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
544 lines
15 KiB
544 lines
15 KiB
7 years ago
|
#! /usr/bin/env python
|
||
|
|
||
|
# $Id: test_footnotes.py 4564 2006-05-21 20:44:42Z wiemann $
|
||
|
# Author: David Goodger <goodger@python.org>
|
||
|
# Copyright: This module has been placed in the public domain.
|
||
|
|
||
|
"""
|
||
|
Tests for docutils.transforms.references.Footnotes.
|
||
|
"""
|
||
|
|
||
|
from __init__ import DocutilsTestSupport
|
||
|
from docutils.transforms.references import Footnotes
|
||
|
from docutils.parsers.rst import Parser
|
||
|
|
||
|
|
||
|
def suite():
|
||
|
parser = Parser()
|
||
|
s = DocutilsTestSupport.TransformTestSuite(parser)
|
||
|
s.generateTests(totest)
|
||
|
return s
|
||
|
|
||
|
totest = {}
|
||
|
|
||
|
totest['footnotes'] = ((Footnotes,), [
|
||
|
["""\
|
||
|
[#autolabel]_
|
||
|
|
||
|
.. [#autolabel] text
|
||
|
""",
|
||
|
"""\
|
||
|
<document source="test data">
|
||
|
<paragraph>
|
||
|
<footnote_reference auto="1" ids="id1" refid="autolabel">
|
||
|
1
|
||
|
<footnote auto="1" backrefs="id1" ids="autolabel" names="autolabel">
|
||
|
<label>
|
||
|
1
|
||
|
<paragraph>
|
||
|
text
|
||
|
"""],
|
||
|
["""\
|
||
|
autonumber: [#]_
|
||
|
|
||
|
.. [#] text
|
||
|
""",
|
||
|
"""\
|
||
|
<document source="test data">
|
||
|
<paragraph>
|
||
|
autonumber: \n\
|
||
|
<footnote_reference auto="1" ids="id1" refid="id2">
|
||
|
1
|
||
|
<footnote auto="1" backrefs="id1" ids="id2" names="1">
|
||
|
<label>
|
||
|
1
|
||
|
<paragraph>
|
||
|
text
|
||
|
"""],
|
||
|
["""\
|
||
|
[#]_ is the first auto-numbered footnote reference.
|
||
|
[#]_ is the second auto-numbered footnote reference.
|
||
|
|
||
|
.. [#] Auto-numbered footnote 1.
|
||
|
.. [#] Auto-numbered footnote 2.
|
||
|
.. [#] Auto-numbered footnote 3.
|
||
|
|
||
|
[#]_ is the third auto-numbered footnote reference.
|
||
|
""",
|
||
|
"""\
|
||
|
<document source="test data">
|
||
|
<paragraph>
|
||
|
<footnote_reference auto="1" ids="id1" refid="id3">
|
||
|
1
|
||
|
is the first auto-numbered footnote reference.
|
||
|
<footnote_reference auto="1" ids="id2" refid="id4">
|
||
|
2
|
||
|
is the second auto-numbered footnote reference.
|
||
|
<footnote auto="1" backrefs="id1" ids="id3" names="1">
|
||
|
<label>
|
||
|
1
|
||
|
<paragraph>
|
||
|
Auto-numbered footnote 1.
|
||
|
<footnote auto="1" backrefs="id2" ids="id4" names="2">
|
||
|
<label>
|
||
|
2
|
||
|
<paragraph>
|
||
|
Auto-numbered footnote 2.
|
||
|
<footnote auto="1" backrefs="id6" ids="id5" names="3">
|
||
|
<label>
|
||
|
3
|
||
|
<paragraph>
|
||
|
Auto-numbered footnote 3.
|
||
|
<paragraph>
|
||
|
<footnote_reference auto="1" ids="id6" refid="id5">
|
||
|
3
|
||
|
is the third auto-numbered footnote reference.
|
||
|
"""],
|
||
|
["""\
|
||
|
[#third]_ is a reference to the third auto-numbered footnote.
|
||
|
|
||
|
.. [#first] First auto-numbered footnote.
|
||
|
.. [#second] Second auto-numbered footnote.
|
||
|
.. [#third] Third auto-numbered footnote.
|
||
|
|
||
|
[#second]_ is a reference to the second auto-numbered footnote.
|
||
|
[#first]_ is a reference to the first auto-numbered footnote.
|
||
|
[#third]_ is another reference to the third auto-numbered footnote.
|
||
|
|
||
|
Here are some internal cross-references to the implicit targets
|
||
|
generated by the footnotes: first_, second_, third_.
|
||
|
""",
|
||
|
"""\
|
||
|
<document source="test data">
|
||
|
<paragraph>
|
||
|
<footnote_reference auto="1" ids="id1" refid="third">
|
||
|
3
|
||
|
is a reference to the third auto-numbered footnote.
|
||
|
<footnote auto="1" backrefs="id3" ids="first" names="first">
|
||
|
<label>
|
||
|
1
|
||
|
<paragraph>
|
||
|
First auto-numbered footnote.
|
||
|
<footnote auto="1" backrefs="id2" ids="second" names="second">
|
||
|
<label>
|
||
|
2
|
||
|
<paragraph>
|
||
|
Second auto-numbered footnote.
|
||
|
<footnote auto="1" backrefs="id1 id4" ids="third" names="third">
|
||
|
<label>
|
||
|
3
|
||
|
<paragraph>
|
||
|
Third auto-numbered footnote.
|
||
|
<paragraph>
|
||
|
<footnote_reference auto="1" ids="id2" refid="second">
|
||
|
2
|
||
|
is a reference to the second auto-numbered footnote.
|
||
|
<footnote_reference auto="1" ids="id3" refid="first">
|
||
|
1
|
||
|
is a reference to the first auto-numbered footnote.
|
||
|
<footnote_reference auto="1" ids="id4" refid="third">
|
||
|
3
|
||
|
is another reference to the third auto-numbered footnote.
|
||
|
<paragraph>
|
||
|
Here are some internal cross-references to the implicit targets
|
||
|
generated by the footnotes: \n\
|
||
|
<reference name="first" refname="first">
|
||
|
first
|
||
|
, \n\
|
||
|
<reference name="second" refname="second">
|
||
|
second
|
||
|
, \n\
|
||
|
<reference name="third" refname="third">
|
||
|
third
|
||
|
.
|
||
|
"""],
|
||
|
["""\
|
||
|
Mixed anonymous and labelled auto-numbered footnotes:
|
||
|
|
||
|
[#four]_ should be 4, [#]_ should be 1,
|
||
|
[#]_ should be 3, [#]_ is one too many,
|
||
|
[#two]_ should be 2, and [#six]_ doesn't exist.
|
||
|
|
||
|
.. [#] Auto-numbered footnote 1.
|
||
|
.. [#two] Auto-numbered footnote 2.
|
||
|
.. [#] Auto-numbered footnote 3.
|
||
|
.. [#four] Auto-numbered footnote 4.
|
||
|
.. [#five] Auto-numbered footnote 5.
|
||
|
.. [#five] Auto-numbered footnote 5 again (duplicate).
|
||
|
""",
|
||
|
"""\
|
||
|
<document source="test data">
|
||
|
<paragraph>
|
||
|
Mixed anonymous and labelled auto-numbered footnotes:
|
||
|
<paragraph>
|
||
|
<footnote_reference auto="1" ids="id1" refid="four">
|
||
|
4
|
||
|
should be 4, \n\
|
||
|
<footnote_reference auto="1" ids="id2" refid="id7">
|
||
|
1
|
||
|
should be 1,
|
||
|
<footnote_reference auto="1" ids="id3" refid="id8">
|
||
|
3
|
||
|
should be 3, \n\
|
||
|
<problematic ids="id11 id4" refid="id10">
|
||
|
[#]_
|
||
|
is one too many,
|
||
|
<footnote_reference auto="1" ids="id5" refid="two">
|
||
|
2
|
||
|
should be 2, and \n\
|
||
|
<footnote_reference auto="1" ids="id6" refname="six">
|
||
|
doesn't exist.
|
||
|
<footnote auto="1" backrefs="id2" ids="id7" names="1">
|
||
|
<label>
|
||
|
1
|
||
|
<paragraph>
|
||
|
Auto-numbered footnote 1.
|
||
|
<footnote auto="1" backrefs="id5" ids="two" names="two">
|
||
|
<label>
|
||
|
2
|
||
|
<paragraph>
|
||
|
Auto-numbered footnote 2.
|
||
|
<footnote auto="1" backrefs="id3" ids="id8" names="3">
|
||
|
<label>
|
||
|
3
|
||
|
<paragraph>
|
||
|
Auto-numbered footnote 3.
|
||
|
<footnote auto="1" backrefs="id1" ids="four" names="four">
|
||
|
<label>
|
||
|
4
|
||
|
<paragraph>
|
||
|
Auto-numbered footnote 4.
|
||
|
<footnote auto="1" dupnames="five" ids="five">
|
||
|
<label>
|
||
|
5
|
||
|
<paragraph>
|
||
|
Auto-numbered footnote 5.
|
||
|
<footnote auto="1" dupnames="five" ids="id9">
|
||
|
<label>
|
||
|
6
|
||
|
<system_message backrefs="id9" level="2" line="12" source="test data" type="WARNING">
|
||
|
<paragraph>
|
||
|
Duplicate explicit target name: "five".
|
||
|
<paragraph>
|
||
|
Auto-numbered footnote 5 again (duplicate).
|
||
|
<system_message backrefs="id11" ids="id10" level="3" line="3" source="test data" type="ERROR">
|
||
|
<paragraph>
|
||
|
Too many autonumbered footnote references: only 2 corresponding footnotes available.
|
||
|
"""],
|
||
|
["""\
|
||
|
Mixed auto-numbered and manual footnotes:
|
||
|
|
||
|
.. [1] manually numbered
|
||
|
.. [#] auto-numbered
|
||
|
.. [#label] autonumber-labeled
|
||
|
""",
|
||
|
"""\
|
||
|
<document source="test data">
|
||
|
<paragraph>
|
||
|
Mixed auto-numbered and manual footnotes:
|
||
|
<footnote ids="id1" names="1">
|
||
|
<label>
|
||
|
1
|
||
|
<paragraph>
|
||
|
manually numbered
|
||
|
<footnote auto="1" ids="id2" names="2">
|
||
|
<label>
|
||
|
2
|
||
|
<paragraph>
|
||
|
auto-numbered
|
||
|
<footnote auto="1" ids="label" names="label">
|
||
|
<label>
|
||
|
3
|
||
|
<paragraph>
|
||
|
autonumber-labeled
|
||
|
"""],
|
||
|
["""\
|
||
|
A labeled autonumbered footnote referece: [#footnote]_.
|
||
|
|
||
|
An unlabeled autonumbered footnote referece: [#]_.
|
||
|
|
||
|
.. [#] Unlabeled autonumbered footnote.
|
||
|
.. [#footnote] Labeled autonumbered footnote.
|
||
|
Note that the footnotes are not in the same
|
||
|
order as the references.
|
||
|
""",
|
||
|
"""\
|
||
|
<document source="test data">
|
||
|
<paragraph>
|
||
|
A labeled autonumbered footnote referece: \n\
|
||
|
<footnote_reference auto="1" ids="id1" refid="footnote">
|
||
|
2
|
||
|
.
|
||
|
<paragraph>
|
||
|
An unlabeled autonumbered footnote referece: \n\
|
||
|
<footnote_reference auto="1" ids="id2" refid="id3">
|
||
|
1
|
||
|
.
|
||
|
<footnote auto="1" backrefs="id2" ids="id3" names="1">
|
||
|
<label>
|
||
|
1
|
||
|
<paragraph>
|
||
|
Unlabeled autonumbered footnote.
|
||
|
<footnote auto="1" backrefs="id1" ids="footnote" names="footnote">
|
||
|
<label>
|
||
|
2
|
||
|
<paragraph>
|
||
|
Labeled autonumbered footnote.
|
||
|
Note that the footnotes are not in the same
|
||
|
order as the references.
|
||
|
"""],
|
||
|
["""\
|
||
|
Mixed manually-numbered, anonymous auto-numbered,
|
||
|
and labelled auto-numbered footnotes:
|
||
|
|
||
|
[#four]_ should be 4, [#]_ should be 2,
|
||
|
[1]_ is 1, [3]_ is 3,
|
||
|
[#]_ should be 6, [#]_ is one too many,
|
||
|
[#five]_ should be 5, and [#eight]_ doesn't exist.
|
||
|
|
||
|
.. [1] Manually-numbered footnote 1.
|
||
|
.. [#] Auto-numbered footnote 2.
|
||
|
.. [#four] Auto-numbered footnote 4.
|
||
|
.. [3] Manually-numbered footnote 3
|
||
|
.. [#five] Auto-numbered footnote 5.
|
||
|
.. [#] Auto-numbered footnote 6.
|
||
|
.. [#five] Auto-numbered footnote 5 again (duplicate).
|
||
|
""",
|
||
|
"""\
|
||
|
<document source="test data">
|
||
|
<paragraph>
|
||
|
Mixed manually-numbered, anonymous auto-numbered,
|
||
|
and labelled auto-numbered footnotes:
|
||
|
<paragraph>
|
||
|
<footnote_reference auto="1" ids="id1" refid="four">
|
||
|
4
|
||
|
should be 4, \n\
|
||
|
<footnote_reference auto="1" ids="id2" refid="id10">
|
||
|
2
|
||
|
should be 2,
|
||
|
<footnote_reference ids="id3" refid="id9">
|
||
|
1
|
||
|
is 1, \n\
|
||
|
<footnote_reference ids="id4" refid="id11">
|
||
|
3
|
||
|
is 3,
|
||
|
<footnote_reference auto="1" ids="id5" refid="id12">
|
||
|
6
|
||
|
should be 6, \n\
|
||
|
<problematic ids="id15 id6" refid="id14">
|
||
|
[#]_
|
||
|
is one too many,
|
||
|
<footnote_reference auto="1" ids="id7" refname="five">
|
||
|
should be 5, and \n\
|
||
|
<footnote_reference auto="1" ids="id8" refname="eight">
|
||
|
doesn't exist.
|
||
|
<footnote backrefs="id3" ids="id9" names="1">
|
||
|
<label>
|
||
|
1
|
||
|
<paragraph>
|
||
|
Manually-numbered footnote 1.
|
||
|
<footnote auto="1" backrefs="id2" ids="id10" names="2">
|
||
|
<label>
|
||
|
2
|
||
|
<paragraph>
|
||
|
Auto-numbered footnote 2.
|
||
|
<footnote auto="1" backrefs="id1" ids="four" names="four">
|
||
|
<label>
|
||
|
4
|
||
|
<paragraph>
|
||
|
Auto-numbered footnote 4.
|
||
|
<footnote backrefs="id4" ids="id11" names="3">
|
||
|
<label>
|
||
|
3
|
||
|
<paragraph>
|
||
|
Manually-numbered footnote 3
|
||
|
<footnote auto="1" dupnames="five" ids="five">
|
||
|
<label>
|
||
|
5
|
||
|
<paragraph>
|
||
|
Auto-numbered footnote 5.
|
||
|
<footnote auto="1" backrefs="id5" ids="id12" names="6">
|
||
|
<label>
|
||
|
6
|
||
|
<paragraph>
|
||
|
Auto-numbered footnote 6.
|
||
|
<footnote auto="1" dupnames="five" ids="id13">
|
||
|
<label>
|
||
|
7
|
||
|
<system_message backrefs="id13" level="2" line="15" source="test data" type="WARNING">
|
||
|
<paragraph>
|
||
|
Duplicate explicit target name: "five".
|
||
|
<paragraph>
|
||
|
Auto-numbered footnote 5 again (duplicate).
|
||
|
<system_message backrefs="id15" ids="id14" level="3" line="4" source="test data" type="ERROR">
|
||
|
<paragraph>
|
||
|
Too many autonumbered footnote references: only 2 corresponding footnotes available.
|
||
|
"""],
|
||
|
["""\
|
||
|
Referencing a footnote by symbol [*]_.
|
||
|
|
||
|
.. [*] This is an auto-symbol footnote.
|
||
|
""",
|
||
|
"""\
|
||
|
<document source="test data">
|
||
|
<paragraph>
|
||
|
Referencing a footnote by symbol \n\
|
||
|
<footnote_reference auto="*" ids="id1" refid="id2">
|
||
|
*
|
||
|
.
|
||
|
<footnote auto="*" backrefs="id1" ids="id2">
|
||
|
<label>
|
||
|
*
|
||
|
<paragraph>
|
||
|
This is an auto-symbol footnote.
|
||
|
"""],
|
||
|
["""\
|
||
|
A sequence of symbol footnote references:
|
||
|
[*]_ [*]_ [*]_ [*]_ [*]_ [*]_ [*]_ [*]_ [*]_ [*]_ [*]_ [*]_.
|
||
|
|
||
|
.. [*] Auto-symbol footnote 1.
|
||
|
.. [*] Auto-symbol footnote 2.
|
||
|
.. [*] Auto-symbol footnote 3.
|
||
|
.. [*] Auto-symbol footnote 4.
|
||
|
.. [*] Auto-symbol footnote 5.
|
||
|
.. [*] Auto-symbol footnote 6.
|
||
|
.. [*] Auto-symbol footnote 7.
|
||
|
.. [*] Auto-symbol footnote 8.
|
||
|
.. [*] Auto-symbol footnote 9.
|
||
|
.. [*] Auto-symbol footnote 10.
|
||
|
.. [*] Auto-symbol footnote 11.
|
||
|
.. [*] Auto-symbol footnote 12.
|
||
|
""",
|
||
|
u"""\
|
||
|
<document source="test data">
|
||
|
<paragraph>
|
||
|
A sequence of symbol footnote references:
|
||
|
<footnote_reference auto="*" ids="id1" refid="id13">
|
||
|
*
|
||
|
\n\
|
||
|
<footnote_reference auto="*" ids="id2" refid="id14">
|
||
|
\u2020
|
||
|
\n\
|
||
|
<footnote_reference auto="*" ids="id3" refid="id15">
|
||
|
\u2021
|
||
|
\n\
|
||
|
<footnote_reference auto="*" ids="id4" refid="id16">
|
||
|
\u00A7
|
||
|
\n\
|
||
|
<footnote_reference auto="*" ids="id5" refid="id17">
|
||
|
\u00B6
|
||
|
\n\
|
||
|
<footnote_reference auto="*" ids="id6" refid="id18">
|
||
|
#
|
||
|
\n\
|
||
|
<footnote_reference auto="*" ids="id7" refid="id19">
|
||
|
\u2660
|
||
|
\n\
|
||
|
<footnote_reference auto="*" ids="id8" refid="id20">
|
||
|
\u2665
|
||
|
\n\
|
||
|
<footnote_reference auto="*" ids="id9" refid="id21">
|
||
|
\u2666
|
||
|
\n\
|
||
|
<footnote_reference auto="*" ids="id10" refid="id22">
|
||
|
\u2663
|
||
|
\n\
|
||
|
<footnote_reference auto="*" ids="id11" refid="id23">
|
||
|
**
|
||
|
\n\
|
||
|
<footnote_reference auto="*" ids="id12" refid="id24">
|
||
|
\u2020\u2020
|
||
|
.
|
||
|
<footnote auto="*" backrefs="id1" ids="id13">
|
||
|
<label>
|
||
|
*
|
||
|
<paragraph>
|
||
|
Auto-symbol footnote 1.
|
||
|
<footnote auto="*" backrefs="id2" ids="id14">
|
||
|
<label>
|
||
|
\u2020
|
||
|
<paragraph>
|
||
|
Auto-symbol footnote 2.
|
||
|
<footnote auto="*" backrefs="id3" ids="id15">
|
||
|
<label>
|
||
|
\u2021
|
||
|
<paragraph>
|
||
|
Auto-symbol footnote 3.
|
||
|
<footnote auto="*" backrefs="id4" ids="id16">
|
||
|
<label>
|
||
|
\u00A7
|
||
|
<paragraph>
|
||
|
Auto-symbol footnote 4.
|
||
|
<footnote auto="*" backrefs="id5" ids="id17">
|
||
|
<label>
|
||
|
\u00B6
|
||
|
<paragraph>
|
||
|
Auto-symbol footnote 5.
|
||
|
<footnote auto="*" backrefs="id6" ids="id18">
|
||
|
<label>
|
||
|
#
|
||
|
<paragraph>
|
||
|
Auto-symbol footnote 6.
|
||
|
<footnote auto="*" backrefs="id7" ids="id19">
|
||
|
<label>
|
||
|
\u2660
|
||
|
<paragraph>
|
||
|
Auto-symbol footnote 7.
|
||
|
<footnote auto="*" backrefs="id8" ids="id20">
|
||
|
<label>
|
||
|
\u2665
|
||
|
<paragraph>
|
||
|
Auto-symbol footnote 8.
|
||
|
<footnote auto="*" backrefs="id9" ids="id21">
|
||
|
<label>
|
||
|
\u2666
|
||
|
<paragraph>
|
||
|
Auto-symbol footnote 9.
|
||
|
<footnote auto="*" backrefs="id10" ids="id22">
|
||
|
<label>
|
||
|
\u2663
|
||
|
<paragraph>
|
||
|
Auto-symbol footnote 10.
|
||
|
<footnote auto="*" backrefs="id11" ids="id23">
|
||
|
<label>
|
||
|
**
|
||
|
<paragraph>
|
||
|
Auto-symbol footnote 11.
|
||
|
<footnote auto="*" backrefs="id12" ids="id24">
|
||
|
<label>
|
||
|
\u2020\u2020
|
||
|
<paragraph>
|
||
|
Auto-symbol footnote 12.
|
||
|
"""],
|
||
|
["""\
|
||
|
Duplicate manual footnote labels:
|
||
|
|
||
|
.. [1] Footnote.
|
||
|
|
||
|
.. [1] Footnote.
|
||
|
""",
|
||
|
"""\
|
||
|
<document source="test data">
|
||
|
<paragraph>
|
||
|
Duplicate manual footnote labels:
|
||
|
<footnote dupnames="1" ids="id1">
|
||
|
<label>
|
||
|
1
|
||
|
<paragraph>
|
||
|
Footnote.
|
||
|
<footnote dupnames="1" ids="id2">
|
||
|
<label>
|
||
|
1
|
||
|
<system_message backrefs="id2" level="2" line="5" source="test data" type="WARNING">
|
||
|
<paragraph>
|
||
|
Duplicate explicit target name: "1".
|
||
|
<paragraph>
|
||
|
Footnote.
|
||
|
"""],
|
||
|
])
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
import unittest
|
||
|
unittest.main(defaultTest='suite')
|