| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
""" |
| 8 |
Tests for states.py. |
| 9 |
""" |
| 10 |
|
| 11 |
from pathlib import Path |
| 12 |
import sys |
| 13 |
import unittest |
| 14 |
|
| 15 |
if __name__ == '__main__': |
| 16 |
|
| 17 |
|
| 18 |
sys.path.insert(0, str(Path(__file__).resolve().parents[3])) |
| 19 |
|
| 20 |
from docutils.frontend import get_default_settings |
| 21 |
from docutils.parsers.rst import Parser |
| 22 |
from docutils.utils import new_document |
| 23 |
|
| 24 |
|
| 25 |
class ParserTestCase(unittest.TestCase): |
| 26 |
|
| 27 |
maxDiff = None |
| 28 |
mysettings = get_default_settings(Parser) |
| 29 |
mysettings.legacy_ids = False |
| 30 |
mysettings.warning_stream = '' |
| 31 |
|
| 32 |
def test_parser(self): |
| 33 |
parser = Parser() |
| 34 |
for name, (settings_overrides, cases) in totest.items(): |
| 35 |
settings = self.mysettings.copy() |
| 36 |
for k, v in settings_overrides.items(): |
| 37 |
setattr(settings, k, v) |
| 38 |
for casenum, (case_input, case_expected) in enumerate(cases): |
| 39 |
with self.subTest(id=f'totest[{name!r}][{casenum}]'): |
| 40 |
document = new_document('test data', settings) |
| 41 |
parser.parse(case_input, document) |
| 42 |
output = document.pformat() |
| 43 |
self.assertEqual(case_expected, output) |
| 44 |
|
| 45 |
|
| 46 |
totest = {} |
| 47 |
|
| 48 |
totest['targets'] = ({}, [ |
| 49 |
["""\ |
| 50 |
.. _target: |
| 51 |
|
| 52 |
(Internal hyperlink target.) |
| 53 |
""", |
| 54 |
"""\ |
| 55 |
<document source="test data"> |
| 56 |
<target ids="target" names="target"> |
| 57 |
<paragraph> |
| 58 |
(Internal hyperlink target.) |
| 59 |
"""], |
| 60 |
["""\ |
| 61 |
.. _optional space before colon : |
| 62 |
""", |
| 63 |
"""\ |
| 64 |
<document source="test data"> |
| 65 |
<target ids="optional-space-before-colon" names="optional\\ space\\ before\\ colon"> |
| 66 |
"""], |
| 67 |
[r""" |
| 68 |
External hyperlink targets: |
| 69 |
|
| 70 |
.. _one-liner: http://structuredtext.sourceforge.net |
| 71 |
|
| 72 |
.. _starts-on-this-line: http:// |
| 73 |
structuredtext. |
| 74 |
sourceforge.net |
| 75 |
|
| 76 |
.. _entirely-below: |
| 77 |
http://structuredtext. |
| 78 |
sourceforge.net |
| 79 |
|
| 80 |
.. _escaped-whitespace: http://example.org/a\ path\ with\ |
| 81 |
spaces.html |
| 82 |
|
| 83 |
.. _not-indirect: uri\_ |
| 84 |
""", |
| 85 |
"""\ |
| 86 |
<document source="test data"> |
| 87 |
<paragraph> |
| 88 |
External hyperlink targets: |
| 89 |
<target ids="one-liner" names="one-liner" refuri="http://structuredtext.sourceforge.net"> |
| 90 |
<target ids="starts-on-this-line" names="starts-on-this-line" refuri="http://structuredtext.sourceforge.net"> |
| 91 |
<target ids="entirely-below" names="entirely-below" refuri="http://structuredtext.sourceforge.net"> |
| 92 |
<target ids="escaped-whitespace" names="escaped-whitespace" refuri="http://example.org/a path with spaces.html"> |
| 93 |
<target ids="not-indirect" names="not-indirect" refuri="uri_"> |
| 94 |
"""], |
| 95 |
["""\ |
| 96 |
Indirect hyperlink targets: |
| 97 |
|
| 98 |
.. _target1: reference_ |
| 99 |
|
| 100 |
.. _target2: `phrase-link reference`_ |
| 101 |
""", |
| 102 |
"""\ |
| 103 |
<document source="test data"> |
| 104 |
<paragraph> |
| 105 |
Indirect hyperlink targets: |
| 106 |
<target ids="target1" names="target1" refname="reference"> |
| 107 |
<target ids="target2" names="target2" refname="phrase-link reference"> |
| 108 |
"""], |
| 109 |
["""\ |
| 110 |
.. _a long target name: |
| 111 |
|
| 112 |
.. _`a target name: including a colon (quoted)`: |
| 113 |
|
| 114 |
.. _a target name\\: including a colon (escaped): |
| 115 |
""", |
| 116 |
"""\ |
| 117 |
<document source="test data"> |
| 118 |
<target ids="a-long-target-name" names="a\\ long\\ target\\ name"> |
| 119 |
<target ids="a-target-name-including-a-colon-quoted" names="a\\ target\\ name:\\ including\\ a\\ colon\\ (quoted)"> |
| 120 |
<target ids="a-target-name-including-a-colon-escaped" names="a\\ target\\ name:\\ including\\ a\\ colon\\ (escaped)"> |
| 121 |
"""], |
| 122 |
["""\ |
| 123 |
.. _`target: No matching backquote. |
| 124 |
.. _`: No matching backquote either. |
| 125 |
""", |
| 126 |
"""\ |
| 127 |
<document source="test data"> |
| 128 |
<comment xml:space="preserve"> |
| 129 |
_`target: No matching backquote. |
| 130 |
<system_message level="2" line="1" source="test data" type="WARNING"> |
| 131 |
<paragraph> |
| 132 |
malformed hyperlink target. |
| 133 |
<comment xml:space="preserve"> |
| 134 |
_`: No matching backquote either. |
| 135 |
<system_message level="2" line="2" source="test data" type="WARNING"> |
| 136 |
<paragraph> |
| 137 |
malformed hyperlink target. |
| 138 |
"""], |
| 139 |
["""\ |
| 140 |
.. _a very long target name, |
| 141 |
split across lines: |
| 142 |
.. _`and another, |
| 143 |
with backquotes`: |
| 144 |
""", |
| 145 |
"""\ |
| 146 |
<document source="test data"> |
| 147 |
<target ids="a-very-long-target-name-split-across-lines" names="a\\ very\\ long\\ target\\ name,\\ split\\ across\\ lines"> |
| 148 |
<target ids="and-another-with-backquotes" names="and\\ another,\\ with\\ backquotes"> |
| 149 |
"""], |
| 150 |
["""\ |
| 151 |
External hyperlink: |
| 152 |
|
| 153 |
.. _target: http://www.python.org/ |
| 154 |
""", |
| 155 |
"""\ |
| 156 |
<document source="test data"> |
| 157 |
<paragraph> |
| 158 |
External hyperlink: |
| 159 |
<target ids="target" names="target" refuri="http://www.python.org/"> |
| 160 |
"""], |
| 161 |
["""\ |
| 162 |
.. _email: [email protected] |
| 163 |
|
| 164 |
.. _multi-line email: jdoe |
| 165 |
@example.com |
| 166 |
""", |
| 167 |
"""\ |
| 168 |
<document source="test data"> |
| 169 |
<target ids="email" names="email" refuri="mailto:[email protected]"> |
| 170 |
<target ids="multi-line-email" names="multi-line\\ email" refuri="mailto:[email protected]"> |
| 171 |
"""], |
| 172 |
["""\ |
| 173 |
Malformed target: |
| 174 |
|
| 175 |
.. __malformed: no good |
| 176 |
|
| 177 |
Target beginning with an underscore: |
| 178 |
|
| 179 |
.. _`_target`: OK |
| 180 |
""", |
| 181 |
"""\ |
| 182 |
<document source="test data"> |
| 183 |
<paragraph> |
| 184 |
Malformed target: |
| 185 |
<comment xml:space="preserve"> |
| 186 |
__malformed: no good |
| 187 |
<system_message level="2" line="3" source="test data" type="WARNING"> |
| 188 |
<paragraph> |
| 189 |
malformed hyperlink target. |
| 190 |
<paragraph> |
| 191 |
Target beginning with an underscore: |
| 192 |
<target ids="target" names="_target" refuri="OK"> |
| 193 |
"""], |
| 194 |
["""\ |
| 195 |
Duplicate external targets (different URIs): |
| 196 |
|
| 197 |
.. _target: first |
| 198 |
|
| 199 |
.. _target: second |
| 200 |
""", |
| 201 |
"""\ |
| 202 |
<document source="test data"> |
| 203 |
<paragraph> |
| 204 |
Duplicate external targets (different URIs): |
| 205 |
<target dupnames="target" ids="target" refuri="first"> |
| 206 |
<system_message level="2" line="5" source="test data" type="WARNING"> |
| 207 |
<paragraph> |
| 208 |
Duplicate explicit target name: "target". |
| 209 |
<target dupnames="target" ids="target-1" refuri="second"> |
| 210 |
"""], |
| 211 |
["""\ |
| 212 |
Duplicate external targets (same URIs): |
| 213 |
|
| 214 |
.. _target: first |
| 215 |
|
| 216 |
.. _target: first |
| 217 |
""", |
| 218 |
"""\ |
| 219 |
<document source="test data"> |
| 220 |
<paragraph> |
| 221 |
Duplicate external targets (same URIs): |
| 222 |
<target ids="target" names="target" refuri="first"> |
| 223 |
<system_message level="1" line="5" source="test data" type="INFO"> |
| 224 |
<paragraph> |
| 225 |
Duplicate name "target" for external target "first". |
| 226 |
<target dupnames="target" ids="target-1" refuri="first"> |
| 227 |
"""], |
| 228 |
["""\ |
| 229 |
Duplicate external targets (embedded/explicit, same URIs): |
| 230 |
|
| 231 |
See the `example <example.rst>`_ |
| 232 |
|
| 233 |
See the example_ |
| 234 |
|
| 235 |
.. _example: example.rst |
| 236 |
""", |
| 237 |
"""\ |
| 238 |
<document source="test data"> |
| 239 |
<paragraph> |
| 240 |
Duplicate external targets (embedded/explicit, same URIs): |
| 241 |
<paragraph> |
| 242 |
See the \n\ |
| 243 |
<reference name="example" refuri="example.rst"> |
| 244 |
example |
| 245 |
<target names="example" refuri="example.rst"> |
| 246 |
<paragraph> |
| 247 |
See the \n\ |
| 248 |
<reference name="example" refname="example"> |
| 249 |
example |
| 250 |
<system_message level="1" line="7" source="test data" type="INFO"> |
| 251 |
<paragraph> |
| 252 |
Duplicate name "example" for external target "example.rst". |
| 253 |
<target dupnames="example" ids="example-1" refuri="example.rst"> |
| 254 |
"""], |
| 255 |
["""\ |
| 256 |
Duplicate indirect _`targets` (same refname): |
| 257 |
|
| 258 |
.. _link: targets_ |
| 259 |
|
| 260 |
.. _link: targets_ |
| 261 |
|
| 262 |
do not conflict. The reference name can be used in a link_. |
| 263 |
""", |
| 264 |
"""\ |
| 265 |
<document source="test data"> |
| 266 |
<paragraph> |
| 267 |
Duplicate indirect \n\ |
| 268 |
<target ids="targets" names="targets"> |
| 269 |
targets |
| 270 |
(same refname): |
| 271 |
<target ids="link" names="link" refname="targets"> |
| 272 |
<system_message level="1" line="5" source="test data" type="INFO"> |
| 273 |
<paragraph> |
| 274 |
Duplicate name "link" for external target "targets". |
| 275 |
<target dupnames="link" ids="link-1" refname="targets"> |
| 276 |
<paragraph> |
| 277 |
do not conflict. The reference name can be used in a \n\ |
| 278 |
<reference name="link" refname="link"> |
| 279 |
link |
| 280 |
. |
| 281 |
"""], |
| 282 |
["""\ |
| 283 |
Duplicate implicit targets. |
| 284 |
|
| 285 |
Title |
| 286 |
===== |
| 287 |
|
| 288 |
Paragraph. |
| 289 |
|
| 290 |
Title |
| 291 |
===== |
| 292 |
|
| 293 |
Paragraph. |
| 294 |
""", |
| 295 |
"""\ |
| 296 |
<document source="test data"> |
| 297 |
<paragraph> |
| 298 |
Duplicate implicit targets. |
| 299 |
<section dupnames="title" ids="title-1"> |
| 300 |
<title> |
| 301 |
Title |
| 302 |
<paragraph> |
| 303 |
Paragraph. |
| 304 |
<section dupnames="title" ids="title-2"> |
| 305 |
<title> |
| 306 |
Title |
| 307 |
<system_message backrefs="title-2" level="1" line="9" source="test data" type="INFO"> |
| 308 |
<paragraph> |
| 309 |
Duplicate implicit target name: "title". |
| 310 |
<paragraph> |
| 311 |
Paragraph. |
| 312 |
"""], |
| 313 |
["""\ |
| 314 |
Duplicate implicit/explicit targets. |
| 315 |
|
| 316 |
Title |
| 317 |
===== |
| 318 |
|
| 319 |
.. _title: |
| 320 |
|
| 321 |
Paragraph. |
| 322 |
""", |
| 323 |
"""\ |
| 324 |
<document source="test data"> |
| 325 |
<paragraph> |
| 326 |
Duplicate implicit/explicit targets. |
| 327 |
<section dupnames="title"> |
| 328 |
<title> |
| 329 |
Title |
| 330 |
<system_message level="1" line="6" source="test data" type="INFO"> |
| 331 |
<paragraph> |
| 332 |
Target name overrides implicit target name "title". |
| 333 |
<target ids="title" names="title"> |
| 334 |
<paragraph> |
| 335 |
Paragraph. |
| 336 |
"""], |
| 337 |
["""\ |
| 338 |
Duplicate implicit/directive targets. |
| 339 |
|
| 340 |
Title |
| 341 |
===== |
| 342 |
|
| 343 |
.. note:: remember remember |
| 344 |
:name: title |
| 345 |
""", |
| 346 |
"""\ |
| 347 |
<document source="test data"> |
| 348 |
<paragraph> |
| 349 |
Duplicate implicit/directive targets. |
| 350 |
<section dupnames="title"> |
| 351 |
<title> |
| 352 |
Title |
| 353 |
<note ids="title" names="title"> |
| 354 |
<system_message backrefs="title" level="1" line="7" source="test data" type="INFO"> |
| 355 |
<paragraph> |
| 356 |
Target name overrides implicit target name "title". |
| 357 |
<paragraph> |
| 358 |
remember remember |
| 359 |
"""], |
| 360 |
["""\ |
| 361 |
Duplicate explicit targets. |
| 362 |
|
| 363 |
.. _title: |
| 364 |
|
| 365 |
First. |
| 366 |
|
| 367 |
.. _title: |
| 368 |
|
| 369 |
Second. |
| 370 |
|
| 371 |
.. _title: |
| 372 |
|
| 373 |
Third. |
| 374 |
""", |
| 375 |
"""\ |
| 376 |
<document source="test data"> |
| 377 |
<paragraph> |
| 378 |
Duplicate explicit targets. |
| 379 |
<target dupnames="title" ids="title"> |
| 380 |
<paragraph> |
| 381 |
First. |
| 382 |
<system_message level="2" line="7" source="test data" type="WARNING"> |
| 383 |
<paragraph> |
| 384 |
Duplicate explicit target name: "title". |
| 385 |
<target dupnames="title" ids="title-1"> |
| 386 |
<paragraph> |
| 387 |
Second. |
| 388 |
<system_message level="2" line="11" source="test data" type="WARNING"> |
| 389 |
<paragraph> |
| 390 |
Duplicate explicit target name: "title". |
| 391 |
<target dupnames="title" ids="title-2"> |
| 392 |
<paragraph> |
| 393 |
Third. |
| 394 |
"""], |
| 395 |
["""\ |
| 396 |
Duplicate explicit/directive targets. |
| 397 |
|
| 398 |
.. _title: |
| 399 |
|
| 400 |
First. |
| 401 |
|
| 402 |
.. rubric:: this is a title too |
| 403 |
:name: title |
| 404 |
|
| 405 |
The system message is left dangling |
| 406 |
(to be handled by the "universal.Messages" transform). |
| 407 |
""", |
| 408 |
"""\ |
| 409 |
<document source="test data"> |
| 410 |
<paragraph> |
| 411 |
Duplicate explicit/directive targets. |
| 412 |
<target dupnames="title" ids="title"> |
| 413 |
<paragraph> |
| 414 |
First. |
| 415 |
<rubric dupnames="title" ids="title-1"> |
| 416 |
this is a title too |
| 417 |
<paragraph> |
| 418 |
The system message is left dangling |
| 419 |
(to be handled by the "universal.Messages" transform). |
| 420 |
"""], |
| 421 |
["""\ |
| 422 |
Duplicate targets: |
| 423 |
|
| 424 |
Target |
| 425 |
====== |
| 426 |
|
| 427 |
Implicit section header target. |
| 428 |
|
| 429 |
.. [TARGET] Citation target. |
| 430 |
|
| 431 |
.. [#target] Autonumber-labeled footnote target. |
| 432 |
|
| 433 |
.. _target: |
| 434 |
|
| 435 |
Explicit internal target. |
| 436 |
|
| 437 |
.. _target: Explicit_external_target |
| 438 |
|
| 439 |
| Do not insert <system_message> element for duplicate |
| 440 |
| _`target`, if this results in an invalid doctree. |
| 441 |
|
| 442 |
.. rubric:: directive with target |
| 443 |
:name: Target |
| 444 |
|
| 445 |
:field list: with |
| 446 |
:_`target`: in a field name |
| 447 |
""", |
| 448 |
"""\ |
| 449 |
<document source="test data"> |
| 450 |
<paragraph> |
| 451 |
Duplicate targets: |
| 452 |
<section dupnames="target"> |
| 453 |
<title> |
| 454 |
Target |
| 455 |
<paragraph> |
| 456 |
Implicit section header target. |
| 457 |
<citation dupnames="target" ids="target"> |
| 458 |
<label> |
| 459 |
TARGET |
| 460 |
<system_message backrefs="target" level="1" line="8" source="test data" type="INFO"> |
| 461 |
<paragraph> |
| 462 |
Target name overrides implicit target name "target". |
| 463 |
<paragraph> |
| 464 |
Citation target. |
| 465 |
<footnote auto="1" dupnames="target" ids="target-1"> |
| 466 |
<system_message backrefs="target-1" level="2" line="10" source="test data" type="WARNING"> |
| 467 |
<paragraph> |
| 468 |
Duplicate explicit target name: "target". |
| 469 |
<paragraph> |
| 470 |
Autonumber-labeled footnote target. |
| 471 |
<system_message level="2" line="12" source="test data" type="WARNING"> |
| 472 |
<paragraph> |
| 473 |
Duplicate explicit target name: "target". |
| 474 |
<target dupnames="target" ids="target-2"> |
| 475 |
<paragraph> |
| 476 |
Explicit internal target. |
| 477 |
<system_message level="2" line="16" source="test data" type="WARNING"> |
| 478 |
<paragraph> |
| 479 |
Duplicate explicit target name: "target". |
| 480 |
<target dupnames="target" ids="target-3" refuri="Explicit_external_target"> |
| 481 |
<line_block> |
| 482 |
<line> |
| 483 |
Do not insert <system_message> element for duplicate |
| 484 |
<line> |
| 485 |
<target dupnames="target" ids="target-4"> |
| 486 |
target |
| 487 |
, if this results in an invalid doctree. |
| 488 |
<rubric dupnames="target" ids="target-5"> |
| 489 |
directive with target |
| 490 |
<field_list> |
| 491 |
<field> |
| 492 |
<field_name> |
| 493 |
field list |
| 494 |
<field_body> |
| 495 |
<paragraph> |
| 496 |
with |
| 497 |
<field> |
| 498 |
<field_name> |
| 499 |
<target dupnames="target" ids="target-6"> |
| 500 |
target |
| 501 |
<field_body> |
| 502 |
<paragraph> |
| 503 |
in a field name |
| 504 |
"""], |
| 505 |
["""\ |
| 506 |
.. _unescaped colon at end:: no good |
| 507 |
|
| 508 |
.. _:: no good either |
| 509 |
|
| 510 |
.. _escaped colon\\:: OK |
| 511 |
|
| 512 |
.. _`unescaped colon, quoted:`: OK |
| 513 |
""", |
| 514 |
"""\ |
| 515 |
<document source="test data"> |
| 516 |
<comment xml:space="preserve"> |
| 517 |
_unescaped colon at end:: no good |
| 518 |
<system_message level="2" line="1" source="test data" type="WARNING"> |
| 519 |
<paragraph> |
| 520 |
malformed hyperlink target. |
| 521 |
<comment xml:space="preserve"> |
| 522 |
_:: no good either |
| 523 |
<system_message level="2" line="3" source="test data" type="WARNING"> |
| 524 |
<paragraph> |
| 525 |
malformed hyperlink target. |
| 526 |
<target ids="escaped-colon" names="escaped\\ colon:" refuri="OK"> |
| 527 |
<target ids="unescaped-colon-quoted" names="unescaped\\ colon,\\ quoted:" refuri="OK"> |
| 528 |
"""], |
| 529 |
]) |
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
totest['legacy-ids'] = ({'legacy_ids': True}, [ |
| 534 |
["""\ |
| 535 |
Duplicate external targets (embedded/explicit, same URIs): |
| 536 |
|
| 537 |
See the `example <example.rst>`_ |
| 538 |
|
| 539 |
See the example_ |
| 540 |
|
| 541 |
.. _example: example.rst |
| 542 |
""", |
| 543 |
"""\ |
| 544 |
<document source="test data"> |
| 545 |
<paragraph> |
| 546 |
Duplicate external targets (embedded/explicit, same URIs): |
| 547 |
<paragraph> |
| 548 |
See the \n\ |
| 549 |
<reference name="example" refuri="example.rst"> |
| 550 |
example |
| 551 |
<target ids="example" names="example" refuri="example.rst"> |
| 552 |
<paragraph> |
| 553 |
See the \n\ |
| 554 |
<reference name="example" refname="example"> |
| 555 |
example |
| 556 |
<system_message level="1" line="7" source="test data" type="INFO"> |
| 557 |
<paragraph> |
| 558 |
Duplicate name "example" for external target "example.rst". |
| 559 |
<target dupnames="example" ids="example-1" refuri="example.rst"> |
| 560 |
"""], |
| 561 |
["""\ |
| 562 |
Duplicate implicit targets. |
| 563 |
|
| 564 |
Title |
| 565 |
===== |
| 566 |
|
| 567 |
Paragraph. |
| 568 |
|
| 569 |
Title |
| 570 |
===== |
| 571 |
|
| 572 |
Paragraph. |
| 573 |
""", |
| 574 |
"""\ |
| 575 |
<document source="test data"> |
| 576 |
<paragraph> |
| 577 |
Duplicate implicit targets. |
| 578 |
<section dupnames="title" ids="title"> |
| 579 |
<title> |
| 580 |
Title |
| 581 |
<paragraph> |
| 582 |
Paragraph. |
| 583 |
<section dupnames="title" ids="title-1"> |
| 584 |
<title> |
| 585 |
Title |
| 586 |
<system_message backrefs="title-1" level="1" line="9" source="test data" type="INFO"> |
| 587 |
<paragraph> |
| 588 |
Duplicate implicit target name: "title". |
| 589 |
<paragraph> |
| 590 |
Paragraph. |
| 591 |
"""], |
| 592 |
["""\ |
| 593 |
Duplicate implicit/explicit targets. |
| 594 |
|
| 595 |
Title |
| 596 |
===== |
| 597 |
|
| 598 |
.. _title: |
| 599 |
|
| 600 |
Paragraph. |
| 601 |
""", |
| 602 |
"""\ |
| 603 |
<document source="test data"> |
| 604 |
<paragraph> |
| 605 |
Duplicate implicit/explicit targets. |
| 606 |
<section dupnames="title" ids="title"> |
| 607 |
<title> |
| 608 |
Title |
| 609 |
<system_message level="1" line="6" source="test data" type="INFO"> |
| 610 |
<paragraph> |
| 611 |
Target name overrides implicit target name "title". |
| 612 |
<target ids="title-1" names="title"> |
| 613 |
<paragraph> |
| 614 |
Paragraph. |
| 615 |
"""], |
| 616 |
["""\ |
| 617 |
Duplicate implicit/directive targets. |
| 618 |
|
| 619 |
Title |
| 620 |
===== |
| 621 |
|
| 622 |
.. note:: remember remember |
| 623 |
:name: title |
| 624 |
""", |
| 625 |
"""\ |
| 626 |
<document source="test data"> |
| 627 |
<paragraph> |
| 628 |
Duplicate implicit/directive targets. |
| 629 |
<section dupnames="title" ids="title"> |
| 630 |
<title> |
| 631 |
Title |
| 632 |
<note ids="title-1" names="title"> |
| 633 |
<system_message backrefs="title-1" level="1" line="7" source="test data" type="INFO"> |
| 634 |
<paragraph> |
| 635 |
Target name overrides implicit target name "title". |
| 636 |
<paragraph> |
| 637 |
remember remember |
| 638 |
"""], |
| 639 |
["""\ |
| 640 |
Duplicate explicit targets. |
| 641 |
|
| 642 |
.. _title: |
| 643 |
|
| 644 |
First. |
| 645 |
|
| 646 |
.. _title: |
| 647 |
|
| 648 |
Second. |
| 649 |
|
| 650 |
.. _title: |
| 651 |
|
| 652 |
Third. |
| 653 |
""", |
| 654 |
"""\ |
| 655 |
<document source="test data"> |
| 656 |
<paragraph> |
| 657 |
Duplicate explicit targets. |
| 658 |
<target dupnames="title" ids="title"> |
| 659 |
<paragraph> |
| 660 |
First. |
| 661 |
<system_message level="2" line="7" source="test data" type="WARNING"> |
| 662 |
<paragraph> |
| 663 |
Duplicate explicit target name: "title". |
| 664 |
<target dupnames="title" ids="title-1"> |
| 665 |
<paragraph> |
| 666 |
Second. |
| 667 |
<system_message level="2" line="11" source="test data" type="WARNING"> |
| 668 |
<paragraph> |
| 669 |
Duplicate explicit target name: "title". |
| 670 |
<target dupnames="title" ids="title-2"> |
| 671 |
<paragraph> |
| 672 |
Third. |
| 673 |
"""], |
| 674 |
["""\ |
| 675 |
Duplicate targets: |
| 676 |
|
| 677 |
Target |
| 678 |
====== |
| 679 |
|
| 680 |
Implicit section header target. |
| 681 |
|
| 682 |
.. [TARGET] Citation target. |
| 683 |
|
| 684 |
.. [#target] Autonumber-labeled footnote target. |
| 685 |
|
| 686 |
.. _target: |
| 687 |
|
| 688 |
Explicit internal target. |
| 689 |
|
| 690 |
.. _target: Explicit_external_target |
| 691 |
|
| 692 |
| Do not insert <system_message> element for duplicate |
| 693 |
| _`target`, if this results in an invalid doctree. |
| 694 |
|
| 695 |
.. rubric:: directive with target |
| 696 |
:name: Target |
| 697 |
|
| 698 |
:field list: with |
| 699 |
:_`target`: in a field name |
| 700 |
""", |
| 701 |
"""\ |
| 702 |
<document source="test data"> |
| 703 |
<paragraph> |
| 704 |
Duplicate targets: |
| 705 |
<section dupnames="target" ids="target"> |
| 706 |
<title> |
| 707 |
Target |
| 708 |
<paragraph> |
| 709 |
Implicit section header target. |
| 710 |
<citation dupnames="target" ids="target-1"> |
| 711 |
<label> |
| 712 |
TARGET |
| 713 |
<system_message backrefs="target-1" level="1" line="8" source="test data" type="INFO"> |
| 714 |
<paragraph> |
| 715 |
Target name overrides implicit target name "target". |
| 716 |
<paragraph> |
| 717 |
Citation target. |
| 718 |
<footnote auto="1" dupnames="target" ids="target-2"> |
| 719 |
<system_message backrefs="target-2" level="2" line="10" source="test data" type="WARNING"> |
| 720 |
<paragraph> |
| 721 |
Duplicate explicit target name: "target". |
| 722 |
<paragraph> |
| 723 |
Autonumber-labeled footnote target. |
| 724 |
<system_message level="2" line="12" source="test data" type="WARNING"> |
| 725 |
<paragraph> |
| 726 |
Duplicate explicit target name: "target". |
| 727 |
<target dupnames="target" ids="target-3"> |
| 728 |
<paragraph> |
| 729 |
Explicit internal target. |
| 730 |
<system_message level="2" line="16" source="test data" type="WARNING"> |
| 731 |
<paragraph> |
| 732 |
Duplicate explicit target name: "target". |
| 733 |
<target dupnames="target" ids="target-4" refuri="Explicit_external_target"> |
| 734 |
<line_block> |
| 735 |
<line> |
| 736 |
Do not insert <system_message> element for duplicate |
| 737 |
<line> |
| 738 |
<target dupnames="target" ids="target-5"> |
| 739 |
target |
| 740 |
, if this results in an invalid doctree. |
| 741 |
<rubric dupnames="target" ids="target-6"> |
| 742 |
directive with target |
| 743 |
<field_list> |
| 744 |
<field> |
| 745 |
<field_name> |
| 746 |
field list |
| 747 |
<field_body> |
| 748 |
<paragraph> |
| 749 |
with |
| 750 |
<field> |
| 751 |
<field_name> |
| 752 |
<target dupnames="target" ids="target-7"> |
| 753 |
target |
| 754 |
<field_body> |
| 755 |
<paragraph> |
| 756 |
in a field name |
| 757 |
"""], |
| 758 |
]) |
| 759 |
|
| 760 |
|
| 761 |
totest['anonymous_targets'] = ({}, [ |
| 762 |
["""\ |
| 763 |
Anonymous external hyperlink target: |
| 764 |
|
| 765 |
.. __: http://w3c.org/ |
| 766 |
""", |
| 767 |
"""\ |
| 768 |
<document source="test data"> |
| 769 |
<paragraph> |
| 770 |
Anonymous external hyperlink target: |
| 771 |
<target anonymous="1" ids="target-1" refuri="http://w3c.org/"> |
| 772 |
"""], |
| 773 |
["""\ |
| 774 |
Anonymous external hyperlink target: |
| 775 |
|
| 776 |
__ http://w3c.org/ |
| 777 |
""", |
| 778 |
"""\ |
| 779 |
<document source="test data"> |
| 780 |
<paragraph> |
| 781 |
Anonymous external hyperlink target: |
| 782 |
<target anonymous="1" ids="target-1" refuri="http://w3c.org/"> |
| 783 |
"""], |
| 784 |
["""\ |
| 785 |
Anonymous indirect hyperlink target: |
| 786 |
|
| 787 |
.. __: reference_ |
| 788 |
""", |
| 789 |
"""\ |
| 790 |
<document source="test data"> |
| 791 |
<paragraph> |
| 792 |
Anonymous indirect hyperlink target: |
| 793 |
<target anonymous="1" ids="target-1" refname="reference"> |
| 794 |
"""], |
| 795 |
["""\ |
| 796 |
Anonymous external hyperlink target, not indirect: |
| 797 |
|
| 798 |
__ uri\\_ |
| 799 |
|
| 800 |
__ this URI ends with an underscore_ |
| 801 |
""", |
| 802 |
"""\ |
| 803 |
<document source="test data"> |
| 804 |
<paragraph> |
| 805 |
Anonymous external hyperlink target, not indirect: |
| 806 |
<target anonymous="1" ids="target-1" refuri="uri_"> |
| 807 |
<target anonymous="1" ids="target-2" refuri="thisURIendswithanunderscore_"> |
| 808 |
"""], |
| 809 |
["""\ |
| 810 |
Anonymous indirect hyperlink targets: |
| 811 |
|
| 812 |
__ reference_ |
| 813 |
__ `a very long |
| 814 |
reference`_ |
| 815 |
""", |
| 816 |
"""\ |
| 817 |
<document source="test data"> |
| 818 |
<paragraph> |
| 819 |
Anonymous indirect hyperlink targets: |
| 820 |
<target anonymous="1" ids="target-1" refname="reference"> |
| 821 |
<target anonymous="1" ids="target-2" refname="a very long reference"> |
| 822 |
"""], |
| 823 |
["""\ |
| 824 |
Mixed anonymous & named indirect hyperlink targets: |
| 825 |
|
| 826 |
__ reference_ |
| 827 |
.. __: reference_ |
| 828 |
__ reference_ |
| 829 |
.. _target1: reference_ |
| 830 |
no blank line |
| 831 |
|
| 832 |
.. _target2: reference_ |
| 833 |
__ reference_ |
| 834 |
.. __: reference_ |
| 835 |
__ reference_ |
| 836 |
no blank line |
| 837 |
""", |
| 838 |
"""\ |
| 839 |
<document source="test data"> |
| 840 |
<paragraph> |
| 841 |
Mixed anonymous & named indirect hyperlink targets: |
| 842 |
<target anonymous="1" ids="target-1" refname="reference"> |
| 843 |
<target anonymous="1" ids="target-2" refname="reference"> |
| 844 |
<target anonymous="1" ids="target-3" refname="reference"> |
| 845 |
<target ids="target1" names="target1" refname="reference"> |
| 846 |
<system_message level="2" line="7" source="test data" type="WARNING"> |
| 847 |
<paragraph> |
| 848 |
Explicit markup ends without a blank line; unexpected unindent. |
| 849 |
<paragraph> |
| 850 |
no blank line |
| 851 |
<target ids="target2" names="target2" refname="reference"> |
| 852 |
<target anonymous="1" ids="target-4" refname="reference"> |
| 853 |
<target anonymous="1" ids="target-5" refname="reference"> |
| 854 |
<target anonymous="1" ids="target-6" refname="reference"> |
| 855 |
<system_message level="2" line="13" source="test data" type="WARNING"> |
| 856 |
<paragraph> |
| 857 |
Explicit markup ends without a blank line; unexpected unindent. |
| 858 |
<paragraph> |
| 859 |
no blank line |
| 860 |
"""], |
| 861 |
["""\ |
| 862 |
.. _ |
| 863 |
""", |
| 864 |
"""\ |
| 865 |
<document source="test data"> |
| 866 |
<comment xml:space="preserve"> |
| 867 |
_ |
| 868 |
"""], |
| 869 |
]) |
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
totest['legacy auto-id prefix'] = ({'auto_id_prefix': 'id', |
| 874 |
'legacy_ids': True}, [ |
| 875 |
["""\ |
| 876 |
Duplicate external targets (different URIs): |
| 877 |
|
| 878 |
.. _target: first |
| 879 |
|
| 880 |
.. _target: second |
| 881 |
""", |
| 882 |
"""\ |
| 883 |
<document source="test data"> |
| 884 |
<paragraph> |
| 885 |
Duplicate external targets (different URIs): |
| 886 |
<target dupnames="target" ids="target" refuri="first"> |
| 887 |
<system_message level="2" line="5" source="test data" type="WARNING"> |
| 888 |
<paragraph> |
| 889 |
Duplicate explicit target name: "target". |
| 890 |
<target dupnames="target" ids="id1" refuri="second"> |
| 891 |
"""], |
| 892 |
["""\ |
| 893 |
Duplicate external targets (same URIs): |
| 894 |
|
| 895 |
.. _target: first |
| 896 |
|
| 897 |
.. _target: first |
| 898 |
""", |
| 899 |
"""\ |
| 900 |
<document source="test data"> |
| 901 |
<paragraph> |
| 902 |
Duplicate external targets (same URIs): |
| 903 |
<target ids="target" names="target" refuri="first"> |
| 904 |
<system_message level="1" line="5" source="test data" type="INFO"> |
| 905 |
<paragraph> |
| 906 |
Duplicate name "target" for external target "first". |
| 907 |
<target dupnames="target" ids="id1" refuri="first"> |
| 908 |
"""], |
| 909 |
["""\ |
| 910 |
Duplicate external targets (embedded/explicit, same URIs): |
| 911 |
|
| 912 |
See the `example <example.rst>`_ |
| 913 |
|
| 914 |
See the example_ |
| 915 |
|
| 916 |
.. _example: example.rst |
| 917 |
""", |
| 918 |
"""\ |
| 919 |
<document source="test data"> |
| 920 |
<paragraph> |
| 921 |
Duplicate external targets (embedded/explicit, same URIs): |
| 922 |
<paragraph> |
| 923 |
See the \n\ |
| 924 |
<reference name="example" refuri="example.rst"> |
| 925 |
example |
| 926 |
<target ids="example" names="example" refuri="example.rst"> |
| 927 |
<paragraph> |
| 928 |
See the \n\ |
| 929 |
<reference name="example" refname="example"> |
| 930 |
example |
| 931 |
<system_message level="1" line="7" source="test data" type="INFO"> |
| 932 |
<paragraph> |
| 933 |
Duplicate name "example" for external target "example.rst". |
| 934 |
<target dupnames="example" ids="id1" refuri="example.rst"> |
| 935 |
"""], |
| 936 |
["""\ |
| 937 |
Duplicate indirect _`targets` (same refname): |
| 938 |
|
| 939 |
.. _link: targets_ |
| 940 |
|
| 941 |
.. _link: targets_ |
| 942 |
|
| 943 |
do not conflict. The reference name can be used in a link_. |
| 944 |
""", |
| 945 |
"""\ |
| 946 |
<document source="test data"> |
| 947 |
<paragraph> |
| 948 |
Duplicate indirect \n\ |
| 949 |
<target ids="targets" names="targets"> |
| 950 |
targets |
| 951 |
(same refname): |
| 952 |
<target ids="link" names="link" refname="targets"> |
| 953 |
<system_message level="1" line="5" source="test data" type="INFO"> |
| 954 |
<paragraph> |
| 955 |
Duplicate name "link" for external target "targets". |
| 956 |
<target dupnames="link" ids="id1" refname="targets"> |
| 957 |
<paragraph> |
| 958 |
do not conflict. The reference name can be used in a \n\ |
| 959 |
<reference name="link" refname="link"> |
| 960 |
link |
| 961 |
. |
| 962 |
"""], |
| 963 |
["""\ |
| 964 |
Duplicate implicit targets. |
| 965 |
|
| 966 |
Title |
| 967 |
===== |
| 968 |
|
| 969 |
Paragraph. |
| 970 |
|
| 971 |
Title |
| 972 |
===== |
| 973 |
|
| 974 |
Paragraph. |
| 975 |
""", |
| 976 |
"""\ |
| 977 |
<document source="test data"> |
| 978 |
<paragraph> |
| 979 |
Duplicate implicit targets. |
| 980 |
<section dupnames="title" ids="title"> |
| 981 |
<title> |
| 982 |
Title |
| 983 |
<paragraph> |
| 984 |
Paragraph. |
| 985 |
<section dupnames="title" ids="id1"> |
| 986 |
<title> |
| 987 |
Title |
| 988 |
<system_message backrefs="id1" level="1" line="9" source="test data" type="INFO"> |
| 989 |
<paragraph> |
| 990 |
Duplicate implicit target name: "title". |
| 991 |
<paragraph> |
| 992 |
Paragraph. |
| 993 |
"""], |
| 994 |
["""\ |
| 995 |
Duplicate implicit/explicit targets. |
| 996 |
|
| 997 |
Title |
| 998 |
===== |
| 999 |
|
| 1000 |
.. _title: |
| 1001 |
|
| 1002 |
Paragraph. |
| 1003 |
""", |
| 1004 |
"""\ |
| 1005 |
<document source="test data"> |
| 1006 |
<paragraph> |
| 1007 |
Duplicate implicit/explicit targets. |
| 1008 |
<section dupnames="title" ids="title"> |
| 1009 |
<title> |
| 1010 |
Title |
| 1011 |
<system_message level="1" line="6" source="test data" type="INFO"> |
| 1012 |
<paragraph> |
| 1013 |
Target name overrides implicit target name "title". |
| 1014 |
<target ids="id1" names="title"> |
| 1015 |
<paragraph> |
| 1016 |
Paragraph. |
| 1017 |
"""], |
| 1018 |
["""\ |
| 1019 |
Duplicate implicit/directive targets. |
| 1020 |
|
| 1021 |
Title |
| 1022 |
===== |
| 1023 |
|
| 1024 |
.. note:: remember remember |
| 1025 |
:name: title |
| 1026 |
""", |
| 1027 |
"""\ |
| 1028 |
<document source="test data"> |
| 1029 |
<paragraph> |
| 1030 |
Duplicate implicit/directive targets. |
| 1031 |
<section dupnames="title" ids="title"> |
| 1032 |
<title> |
| 1033 |
Title |
| 1034 |
<note ids="id1" names="title"> |
| 1035 |
<system_message backrefs="id1" level="1" line="7" source="test data" type="INFO"> |
| 1036 |
<paragraph> |
| 1037 |
Target name overrides implicit target name "title". |
| 1038 |
<paragraph> |
| 1039 |
remember remember |
| 1040 |
"""], |
| 1041 |
["""\ |
| 1042 |
Duplicate explicit targets. |
| 1043 |
|
| 1044 |
.. _title: |
| 1045 |
|
| 1046 |
First. |
| 1047 |
|
| 1048 |
.. _title: |
| 1049 |
|
| 1050 |
Second. |
| 1051 |
|
| 1052 |
.. _title: |
| 1053 |
|
| 1054 |
Third. |
| 1055 |
""", |
| 1056 |
"""\ |
| 1057 |
<document source="test data"> |
| 1058 |
<paragraph> |
| 1059 |
Duplicate explicit targets. |
| 1060 |
<target dupnames="title" ids="title"> |
| 1061 |
<paragraph> |
| 1062 |
First. |
| 1063 |
<system_message level="2" line="7" source="test data" type="WARNING"> |
| 1064 |
<paragraph> |
| 1065 |
Duplicate explicit target name: "title". |
| 1066 |
<target dupnames="title" ids="id1"> |
| 1067 |
<paragraph> |
| 1068 |
Second. |
| 1069 |
<system_message level="2" line="11" source="test data" type="WARNING"> |
| 1070 |
<paragraph> |
| 1071 |
Duplicate explicit target name: "title". |
| 1072 |
<target dupnames="title" ids="id2"> |
| 1073 |
<paragraph> |
| 1074 |
Third. |
| 1075 |
"""], |
| 1076 |
["""\ |
| 1077 |
Duplicate explicit/directive targets. |
| 1078 |
|
| 1079 |
.. _title: |
| 1080 |
|
| 1081 |
First. |
| 1082 |
|
| 1083 |
.. rubric:: this is a title too |
| 1084 |
:name: title |
| 1085 |
|
| 1086 |
The system message is left dangling |
| 1087 |
(to be handled by the "universal.Messages" transform). |
| 1088 |
""", |
| 1089 |
"""\ |
| 1090 |
<document source="test data"> |
| 1091 |
<paragraph> |
| 1092 |
Duplicate explicit/directive targets. |
| 1093 |
<target dupnames="title" ids="title"> |
| 1094 |
<paragraph> |
| 1095 |
First. |
| 1096 |
<rubric dupnames="title" ids="id1"> |
| 1097 |
this is a title too |
| 1098 |
<paragraph> |
| 1099 |
The system message is left dangling |
| 1100 |
(to be handled by the "universal.Messages" transform). |
| 1101 |
"""], |
| 1102 |
["""\ |
| 1103 |
Duplicate targets: |
| 1104 |
|
| 1105 |
Target |
| 1106 |
====== |
| 1107 |
|
| 1108 |
Implicit section header target. |
| 1109 |
|
| 1110 |
.. [TARGET] Citation target. |
| 1111 |
|
| 1112 |
.. [#target] Autonumber-labeled footnote target. |
| 1113 |
|
| 1114 |
.. _target: |
| 1115 |
|
| 1116 |
Explicit internal target. |
| 1117 |
|
| 1118 |
.. _target: Explicit_external_target |
| 1119 |
|
| 1120 |
| Do not insert <system_message> element for duplicate |
| 1121 |
| _`target`, if this results in an invalid doctree. |
| 1122 |
|
| 1123 |
.. rubric:: directive with target |
| 1124 |
:name: Target |
| 1125 |
|
| 1126 |
:field list: with |
| 1127 |
:_`target`: in a field name |
| 1128 |
""", |
| 1129 |
"""\ |
| 1130 |
<document source="test data"> |
| 1131 |
<paragraph> |
| 1132 |
Duplicate targets: |
| 1133 |
<section dupnames="target" ids="target"> |
| 1134 |
<title> |
| 1135 |
Target |
| 1136 |
<paragraph> |
| 1137 |
Implicit section header target. |
| 1138 |
<citation dupnames="target" ids="id1"> |
| 1139 |
<label> |
| 1140 |
TARGET |
| 1141 |
<system_message backrefs="id1" level="1" line="8" source="test data" type="INFO"> |
| 1142 |
<paragraph> |
| 1143 |
Target name overrides implicit target name "target". |
| 1144 |
<paragraph> |
| 1145 |
Citation target. |
| 1146 |
<footnote auto="1" dupnames="target" ids="id2"> |
| 1147 |
<system_message backrefs="id2" level="2" line="10" source="test data" type="WARNING"> |
| 1148 |
<paragraph> |
| 1149 |
Duplicate explicit target name: "target". |
| 1150 |
<paragraph> |
| 1151 |
Autonumber-labeled footnote target. |
| 1152 |
<system_message level="2" line="12" source="test data" type="WARNING"> |
| 1153 |
<paragraph> |
| 1154 |
Duplicate explicit target name: "target". |
| 1155 |
<target dupnames="target" ids="id3"> |
| 1156 |
<paragraph> |
| 1157 |
Explicit internal target. |
| 1158 |
<system_message level="2" line="16" source="test data" type="WARNING"> |
| 1159 |
<paragraph> |
| 1160 |
Duplicate explicit target name: "target". |
| 1161 |
<target dupnames="target" ids="id4" refuri="Explicit_external_target"> |
| 1162 |
<line_block> |
| 1163 |
<line> |
| 1164 |
Do not insert <system_message> element for duplicate |
| 1165 |
<line> |
| 1166 |
<target dupnames="target" ids="id5"> |
| 1167 |
target |
| 1168 |
, if this results in an invalid doctree. |
| 1169 |
<rubric dupnames="target" ids="id6"> |
| 1170 |
directive with target |
| 1171 |
<field_list> |
| 1172 |
<field> |
| 1173 |
<field_name> |
| 1174 |
field list |
| 1175 |
<field_body> |
| 1176 |
<paragraph> |
| 1177 |
with |
| 1178 |
<field> |
| 1179 |
<field_name> |
| 1180 |
<target dupnames="target" ids="id7"> |
| 1181 |
target |
| 1182 |
<field_body> |
| 1183 |
<paragraph> |
| 1184 |
in a field name |
| 1185 |
"""], |
| 1186 |
["""\ |
| 1187 |
Anonymous external hyperlink target: |
| 1188 |
|
| 1189 |
__ http://w3c.org/ |
| 1190 |
""", |
| 1191 |
"""\ |
| 1192 |
<document source="test data"> |
| 1193 |
<paragraph> |
| 1194 |
Anonymous external hyperlink target: |
| 1195 |
<target anonymous="1" ids="id1" refuri="http://w3c.org/"> |
| 1196 |
"""], |
| 1197 |
["""\ |
| 1198 |
Anonymous indirect hyperlink target: |
| 1199 |
|
| 1200 |
.. __: reference_ |
| 1201 |
""", |
| 1202 |
"""\ |
| 1203 |
<document source="test data"> |
| 1204 |
<paragraph> |
| 1205 |
Anonymous indirect hyperlink target: |
| 1206 |
<target anonymous="1" ids="id1" refname="reference"> |
| 1207 |
"""], |
| 1208 |
]) |
| 1209 |
|
| 1210 |
if __name__ == '__main__': |
| 1211 |
unittest.main() |