1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
|
#! /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')
|