Spelling fixes
[docutils.git] / test / test_parsers / test_rst / test_targets.py
blob56358357b016c086e958cd8fba118b78b16f886b
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 states.py.
9 """
11 from __init__ import DocutilsTestSupport
13 def suite():
14 s = DocutilsTestSupport.ParserTestSuite()
15 s.generateTests(totest)
16 return s
18 totest = {}
20 totest['targets'] = [
21 ["""\
22 .. _target:
24 (Internal hyperlink target.)
25 """,
26 """\
27 <document source="test data">
28 <target ids="target" names="target">
29 <paragraph>
30 (Internal hyperlink target.)
31 """],
32 ["""\
33 .. _optional space before colon :
34 """,
35 """\
36 <document source="test data">
37 <target ids="optional-space-before-colon" names="optional\ space\ before\ colon">
38 """],
39 ["""\
40 External hyperlink targets:
42 .. _one-liner: http://structuredtext.sourceforge.net
44 .. _starts-on-this-line: http://
45 structuredtext.
46 sourceforge.net
48 .. _entirely-below:
49 http://structuredtext.
50 sourceforge.net
52 .. _not-indirect: uri\\_
53 """,
54 """\
55 <document source="test data">
56 <paragraph>
57 External hyperlink targets:
58 <target ids="one-liner" names="one-liner" refuri="http://structuredtext.sourceforge.net">
59 <target ids="starts-on-this-line" names="starts-on-this-line" refuri="http://structuredtext.sourceforge.net">
60 <target ids="entirely-below" names="entirely-below" refuri="http://structuredtext.sourceforge.net">
61 <target ids="not-indirect" names="not-indirect" refuri="uri_">
62 """],
63 ["""\
64 Indirect hyperlink targets:
66 .. _target1: reference_
68 .. _target2: `phrase-link reference`_
69 """,
70 """\
71 <document source="test data">
72 <paragraph>
73 Indirect hyperlink targets:
74 <target ids="target1" names="target1" refname="reference">
75 <target ids="target2" names="target2" refname="phrase-link reference">
76 """],
77 ["""\
78 .. _a long target name:
80 .. _`a target name: including a colon (quoted)`:
82 .. _a target name\: including a colon (escaped):
83 """,
84 """\
85 <document source="test data">
86 <target ids="a-long-target-name" names="a\ long\ target\ name">
87 <target ids="a-target-name-including-a-colon-quoted" names="a\ target\ name:\ including\ a\ colon\ (quoted)">
88 <target ids="a-target-name-including-a-colon-escaped" names="a\ target\ name:\ including\ a\ colon\ (escaped)">
89 """],
90 ["""\
91 .. _`target: No matching backquote.
92 .. _`: No matching backquote either.
93 """,
94 """\
95 <document source="test data">
96 <comment xml:space="preserve">
97 _`target: No matching backquote.
98 <system_message level="2" line="1" source="test data" type="WARNING">
99 <paragraph>
100 malformed hyperlink target.
101 <comment xml:space="preserve">
102 _`: No matching backquote either.
103 <system_message level="2" line="2" source="test data" type="WARNING">
104 <paragraph>
105 malformed hyperlink target.
106 """],
107 ["""\
108 .. _a very long target name,
109 split across lines:
110 .. _`and another,
111 with backquotes`:
112 """,
113 """\
114 <document source="test data">
115 <target ids="a-very-long-target-name-split-across-lines" names="a\ very\ long\ target\ name,\ split\ across\ lines">
116 <target ids="and-another-with-backquotes" names="and\ another,\ with\ backquotes">
117 """],
118 ["""\
119 External hyperlink:
121 .. _target: http://www.python.org/
122 """,
123 """\
124 <document source="test data">
125 <paragraph>
126 External hyperlink:
127 <target ids="target" names="target" refuri="http://www.python.org/">
128 """],
129 ["""\
130 .. _email: jdoe@example.com
132 .. _multi-line email: jdoe
133 @example.com
134 """,
135 """\
136 <document source="test data">
137 <target ids="email" names="email" refuri="mailto:jdoe@example.com">
138 <target ids="multi-line-email" names="multi-line\ email" refuri="mailto:jdoe@example.com">
139 """],
140 ["""\
141 Malformed target:
143 .. __malformed: no good
145 Target beginning with an underscore:
147 .. _`_target`: OK
148 """,
149 """\
150 <document source="test data">
151 <paragraph>
152 Malformed target:
153 <comment xml:space="preserve">
154 __malformed: no good
155 <system_message level="2" line="3" source="test data" type="WARNING">
156 <paragraph>
157 malformed hyperlink target.
158 <paragraph>
159 Target beginning with an underscore:
160 <target ids="target" names="_target" refuri="OK">
161 """],
162 ["""\
163 Duplicate external targets (different URIs):
165 .. _target: first
167 .. _target: second
168 """,
169 """\
170 <document source="test data">
171 <paragraph>
172 Duplicate external targets (different URIs):
173 <target dupnames="target" ids="target" refuri="first">
174 <system_message backrefs="id1" level="2" line="5" source="test data" type="WARNING">
175 <paragraph>
176 Duplicate explicit target name: "target".
177 <target dupnames="target" ids="id1" refuri="second">
178 """],
179 ["""\
180 Duplicate external targets (same URIs):
182 .. _target: first
184 .. _target: first
185 """,
186 """\
187 <document source="test data">
188 <paragraph>
189 Duplicate external targets (same URIs):
190 <target ids="target" names="target" refuri="first">
191 <system_message backrefs="id1" level="1" line="5" source="test data" type="INFO">
192 <paragraph>
193 Duplicate explicit target name: "target".
194 <target dupnames="target" ids="id1" refuri="first">
195 """],
196 ["""\
197 Duplicate implicit targets.
199 Title
200 =====
202 Paragraph.
204 Title
205 =====
207 Paragraph.
208 """,
209 """\
210 <document source="test data">
211 <paragraph>
212 Duplicate implicit targets.
213 <section dupnames="title" ids="title">
214 <title>
215 Title
216 <paragraph>
217 Paragraph.
218 <section dupnames="title" ids="id1">
219 <title>
220 Title
221 <system_message backrefs="id1" level="1" line="9" source="test data" type="INFO">
222 <paragraph>
223 Duplicate implicit target name: "title".
224 <paragraph>
225 Paragraph.
226 """],
227 ["""\
228 Duplicate implicit/explicit targets.
230 Title
231 =====
233 .. _title:
235 Paragraph.
236 """,
237 """\
238 <document source="test data">
239 <paragraph>
240 Duplicate implicit/explicit targets.
241 <section dupnames="title" ids="title">
242 <title>
243 Title
244 <system_message backrefs="id1" level="1" line="6" source="test data" type="INFO">
245 <paragraph>
246 Duplicate implicit target name: "title".
247 <target ids="id1" names="title">
248 <paragraph>
249 Paragraph.
250 """],
251 ["""\
252 Duplicate implicit/directive targets.
254 Title
255 =====
257 .. target-notes::
258 :name: title
259 """,
260 """\
261 <document source="test data">
262 <paragraph>
263 Duplicate implicit/directive targets.
264 <section dupnames="title" ids="title">
265 <title>
266 Title
267 <pending ids="id1" names="title">
268 <system_message backrefs="id1" level="1" line="4" source="test data" type="INFO">
269 <paragraph>
270 Duplicate implicit target name: "title".
271 .. internal attributes:
272 .transform: docutils.transforms.references.TargetNotes
273 .details:
274 """],
275 ["""\
276 Duplicate explicit targets.
278 .. _title:
280 First.
282 .. _title:
284 Second.
286 .. _title:
288 Third.
289 """,
290 """\
291 <document source="test data">
292 <paragraph>
293 Duplicate explicit targets.
294 <target dupnames="title" ids="title">
295 <paragraph>
296 First.
297 <system_message backrefs="id1" level="2" line="7" source="test data" type="WARNING">
298 <paragraph>
299 Duplicate explicit target name: "title".
300 <target dupnames="title" ids="id1">
301 <paragraph>
302 Second.
303 <system_message backrefs="id2" level="2" line="11" source="test data" type="WARNING">
304 <paragraph>
305 Duplicate explicit target name: "title".
306 <target dupnames="title" ids="id2">
307 <paragraph>
308 Third.
309 """],
310 ["""\
311 Duplicate explicit/directive targets.
313 .. _title:
315 First.
317 .. rubric:: this is a title too
318 :name: title
320 """,
321 """\
322 <document source="test data">
323 <paragraph>
324 Duplicate explicit/directive targets.
325 <target dupnames="title" ids="title">
326 <paragraph>
327 First.
328 <rubric dupnames="title" ids="id1">
329 this is a title too
330 <system_message backrefs="id1" level="2" line="9" source="test data" type="WARNING">
331 <paragraph>
332 Duplicate explicit target name: "title".
333 """],
334 ["""\
335 Duplicate targets:
337 Target
338 ======
340 Implicit section header target.
342 .. [TARGET] Citation target.
344 .. [#target] Autonumber-labeled footnote target.
346 .. _target:
348 Explicit internal target.
350 .. _target: Explicit_external_target
352 .. rubric:: directive with target
353 :name: Target
354 """,
355 """\
356 <document source="test data">
357 <paragraph>
358 Duplicate targets:
359 <section dupnames="target" ids="target">
360 <title>
361 Target
362 <paragraph>
363 Implicit section header target.
364 <citation dupnames="target" ids="id1">
365 <label>
366 TARGET
367 <system_message backrefs="id1" level="1" line="8" source="test data" type="INFO">
368 <paragraph>
369 Duplicate implicit target name: "target".
370 <paragraph>
371 Citation target.
372 <footnote auto="1" dupnames="target" ids="id2">
373 <system_message backrefs="id2" level="2" line="10" source="test data" type="WARNING">
374 <paragraph>
375 Duplicate explicit target name: "target".
376 <paragraph>
377 Autonumber-labeled footnote target.
378 <system_message backrefs="id3" level="2" line="12" source="test data" type="WARNING">
379 <paragraph>
380 Duplicate explicit target name: "target".
381 <target dupnames="target" ids="id3">
382 <paragraph>
383 Explicit internal target.
384 <system_message backrefs="id4" level="2" line="16" source="test data" type="WARNING">
385 <paragraph>
386 Duplicate explicit target name: "target".
387 <target dupnames="target" ids="id4" refuri="Explicit_external_target">
388 <rubric dupnames="target" ids="id5">
389 directive with target
390 <system_message backrefs="id5" level="2" line="4" source="test data" type="WARNING">
391 <paragraph>
392 Duplicate explicit target name: "target".
393 """],
394 ["""\
395 .. _unescaped colon at end:: no good
397 .. _:: no good either
399 .. _escaped colon\:: OK
401 .. _`unescaped colon, quoted:`: OK
402 """,
403 """\
404 <document source="test data">
405 <comment xml:space="preserve">
406 _unescaped colon at end:: no good
407 <system_message level="2" line="1" source="test data" type="WARNING">
408 <paragraph>
409 malformed hyperlink target.
410 <comment xml:space="preserve">
411 _:: no good either
412 <system_message level="2" line="3" source="test data" type="WARNING">
413 <paragraph>
414 malformed hyperlink target.
415 <target ids="escaped-colon" names="escaped\ colon:" refuri="OK">
416 <target ids="unescaped-colon-quoted" names="unescaped\ colon,\ quoted:" refuri="OK">
417 """],
420 totest['anonymous_targets'] = [
421 ["""\
422 Anonymous external hyperlink target:
424 .. __: http://w3c.org/
425 """,
426 """\
427 <document source="test data">
428 <paragraph>
429 Anonymous external hyperlink target:
430 <target anonymous="1" ids="id1" refuri="http://w3c.org/">
431 """],
432 ["""\
433 Anonymous external hyperlink target:
435 __ http://w3c.org/
436 """,
437 """\
438 <document source="test data">
439 <paragraph>
440 Anonymous external hyperlink target:
441 <target anonymous="1" ids="id1" refuri="http://w3c.org/">
442 """],
443 ["""\
444 Anonymous indirect hyperlink target:
446 .. __: reference_
447 """,
448 """\
449 <document source="test data">
450 <paragraph>
451 Anonymous indirect hyperlink target:
452 <target anonymous="1" ids="id1" refname="reference">
453 """],
454 ["""\
455 Anonymous external hyperlink target, not indirect:
457 __ uri\\_
459 __ this URI ends with an underscore_
460 """,
461 """\
462 <document source="test data">
463 <paragraph>
464 Anonymous external hyperlink target, not indirect:
465 <target anonymous="1" ids="id1" refuri="uri_">
466 <target anonymous="1" ids="id2" refuri="thisURIendswithanunderscore_">
467 """],
468 ["""\
469 Anonymous indirect hyperlink targets:
471 __ reference_
472 __ `a very long
473 reference`_
474 """,
475 """\
476 <document source="test data">
477 <paragraph>
478 Anonymous indirect hyperlink targets:
479 <target anonymous="1" ids="id1" refname="reference">
480 <target anonymous="1" ids="id2" refname="a very long reference">
481 """],
482 ["""\
483 Mixed anonymous & named indirect hyperlink targets:
485 __ reference_
486 .. __: reference_
487 __ reference_
488 .. _target1: reference_
489 no blank line
491 .. _target2: reference_
492 __ reference_
493 .. __: reference_
494 __ reference_
495 no blank line
496 """,
497 """\
498 <document source="test data">
499 <paragraph>
500 Mixed anonymous & named indirect hyperlink targets:
501 <target anonymous="1" ids="id1" refname="reference">
502 <target anonymous="1" ids="id2" refname="reference">
503 <target anonymous="1" ids="id3" refname="reference">
504 <target ids="target1" names="target1" refname="reference">
505 <system_message level="2" line="7" source="test data" type="WARNING">
506 <paragraph>
507 Explicit markup ends without a blank line; unexpected unindent.
508 <paragraph>
509 no blank line
510 <target ids="target2" names="target2" refname="reference">
511 <target anonymous="1" ids="id4" refname="reference">
512 <target anonymous="1" ids="id5" refname="reference">
513 <target anonymous="1" ids="id6" refname="reference">
514 <system_message level="2" line="13" source="test data" type="WARNING">
515 <paragraph>
516 Explicit markup ends without a blank line; unexpected unindent.
517 <paragraph>
518 no blank line
519 """],
520 ["""\
521 .. _
522 """,
523 """\
524 <document source="test data">
525 <comment xml:space="preserve">
527 """],
531 if __name__ == '__main__':
532 import unittest
533 unittest.main(defaultTest='suite')