Release 0.5: added empty "Changes Since 0.5" section
[docutils.git] / test / test_parsers / test_rst / test_inline_markup.py
blobfe1c1aff2397ae8e368b4774b52790909b0bb8ec
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 inline markup in docutils/parsers/rst/states.py.
9 Interpreted text tests are in a separate module, test_interpreted.py.
10 """
12 from __init__ import DocutilsTestSupport
14 def suite():
15 s = DocutilsTestSupport.ParserTestSuite()
16 s.generateTests(totest)
17 return s
19 totest = {}
21 totest['emphasis'] = [
22 ["""\
23 *emphasis*
24 """,
25 """\
26 <document source="test data">
27 <paragraph>
28 <emphasis>
29 emphasis
30 """],
31 ["""\
32 *emphasized sentence
33 across lines*
34 """,
35 """\
36 <document source="test data">
37 <paragraph>
38 <emphasis>
39 emphasized sentence
40 across lines
41 """],
42 ["""\
43 *emphasis without closing asterisk
44 """,
45 """\
46 <document source="test data">
47 <paragraph>
48 <problematic ids="id2" refid="id1">
50 emphasis without closing asterisk
51 <system_message backrefs="id2" ids="id1" level="2" line="1" source="test data" type="WARNING">
52 <paragraph>
53 Inline emphasis start-string without end-string.
54 """],
55 ["""\
56 '*emphasis*' and 1/*emphasis*/2 and 3-*emphasis*-4 and 5:*emphasis*:6
57 but not '*' or '"*"' or x*2* or 2*x* or \\*args or *
58 or *the\\* *stars\\\\\\* *inside*
60 (however, '*args' will trigger a warning and may be problematic)
62 what about *this**?
63 """,
64 """\
65 <document source="test data">
66 <paragraph>
68 <emphasis>
69 emphasis
70 ' and 1/
71 <emphasis>
72 emphasis
73 /2 and 3-
74 <emphasis>
75 emphasis
76 -4 and 5:
77 <emphasis>
78 emphasis
80 but not '*' or '"*"' or x*2* or 2*x* or *args or *
81 or \n\
82 <emphasis>
83 the* *stars\* *inside
84 <paragraph>
85 (however, '
86 <problematic ids="id2" refid="id1">
88 args' will trigger a warning and may be problematic)
89 <system_message backrefs="id2" ids="id1" level="2" line="5" source="test data" type="WARNING">
90 <paragraph>
91 Inline emphasis start-string without end-string.
92 <paragraph>
93 what about \n\
94 <emphasis>
95 this*
97 """],
98 ["""\
99 Emphasized asterisk: *\\**
101 Emphasized double asterisk: *\\***
102 """,
103 """\
104 <document source="test data">
105 <paragraph>
106 Emphasized asterisk: \n\
107 <emphasis>
109 <paragraph>
110 Emphasized double asterisk: \n\
111 <emphasis>
113 """],
116 totest['strong'] = [
117 ["""\
118 **strong**
119 """,
120 """\
121 <document source="test data">
122 <paragraph>
123 <strong>
124 strong
125 """],
126 ["""\
127 (**strong**) but not (**) or '(** ' or x**2 or \\**kwargs or **
129 (however, '**kwargs' will trigger a warning and may be problematic)
130 """,
131 """\
132 <document source="test data">
133 <paragraph>
135 <strong>
136 strong
137 ) but not (**) or '(** ' or x**2 or **kwargs or **
138 <paragraph>
139 (however, '
140 <problematic ids="id2" refid="id1">
142 kwargs' will trigger a warning and may be problematic)
143 <system_message backrefs="id2" ids="id1" level="2" line="3" source="test data" type="WARNING">
144 <paragraph>
145 Inline strong start-string without end-string.
146 """],
147 ["""\
148 Strong asterisk: *****
150 Strong double asterisk: ******
151 """,
152 """\
153 <document source="test data">
154 <paragraph>
155 Strong asterisk: \n\
156 <strong>
158 <paragraph>
159 Strong double asterisk: \n\
160 <strong>
162 """],
163 ["""\
164 **strong without closing asterisks
165 """,
166 """\
167 <document source="test data">
168 <paragraph>
169 <problematic ids="id2" refid="id1">
171 strong without closing asterisks
172 <system_message backrefs="id2" ids="id1" level="2" line="1" source="test data" type="WARNING">
173 <paragraph>
174 Inline strong start-string without end-string.
175 """],
178 totest['literal'] = [
179 ["""\
180 ``literal``
181 """,
182 """\
183 <document source="test data">
184 <paragraph>
185 <literal>
186 literal
187 """],
188 ["""\
189 ``\\literal``
190 """,
191 """\
192 <document source="test data">
193 <paragraph>
194 <literal>
195 \\literal
196 """],
197 ["""\
198 ``lite\\ral``
199 """,
200 """\
201 <document source="test data">
202 <paragraph>
203 <literal>
204 lite\\ral
205 """],
206 ["""\
207 ``literal\\``
208 """,
209 """\
210 <document source="test data">
211 <paragraph>
212 <literal>
213 literal\\
214 """],
215 ["""\
216 ``literal ``TeX quotes'' & \\backslash`` but not "``" or ``
218 (however, ``standalone TeX quotes'' will trigger a warning
219 and may be problematic)
220 """,
221 """\
222 <document source="test data">
223 <paragraph>
224 <literal>
225 literal ``TeX quotes'' & \\backslash
226 but not "``" or ``
227 <paragraph>
228 (however, \n\
229 <problematic ids="id2" refid="id1">
231 standalone TeX quotes'' will trigger a warning
232 and may be problematic)
233 <system_message backrefs="id2" ids="id1" level="2" line="3" source="test data" type="WARNING">
234 <paragraph>
235 Inline literal start-string without end-string.
236 """],
237 ["""\
238 Find the ```interpreted text``` in this paragraph!
239 """,
240 """\
241 <document source="test data">
242 <paragraph>
243 Find the \n\
244 <literal>
245 `interpreted text`
246 in this paragraph!
247 """],
248 ["""\
249 ``literal without closing backquotes
250 """,
251 """\
252 <document source="test data">
253 <paragraph>
254 <problematic ids="id2" refid="id1">
256 literal without closing backquotes
257 <system_message backrefs="id2" ids="id1" level="2" line="1" source="test data" type="WARNING">
258 <paragraph>
259 Inline literal start-string without end-string.
260 """],
261 ["""\
262 Python ``list``\\s use square bracket syntax.
263 """,
264 """\
265 <document source="test data">
266 <paragraph>
267 Python \n\
268 <literal>
269 list
270 s use square bracket syntax.
271 """],
274 totest['references'] = [
275 ["""\
276 ref_
277 """,
278 """\
279 <document source="test data">
280 <paragraph>
281 <reference name="ref" refname="ref">
283 """],
284 ["""\
285 ref__
286 """,
287 """\
288 <document source="test data">
289 <paragraph>
290 <reference anonymous="1" name="ref">
292 """],
293 ["""\
294 ref_, r_, r_e-f_, -ref_, and anonymousref__,
295 but not _ref_ or __attr__ or object.__attr__
296 """,
297 """\
298 <document source="test data">
299 <paragraph>
300 <reference name="ref" refname="ref">
302 , \n\
303 <reference name="r" refname="r">
305 , \n\
306 <reference name="r_e-f" refname="r_e-f">
307 r_e-f
309 <reference name="ref" refname="ref">
311 , and \n\
312 <reference anonymous="1" name="anonymousref">
313 anonymousref
315 but not _ref_ or __attr__ or object.__attr__
316 """],
319 totest['phrase_references'] = [
320 ["""\
321 `phrase reference`_
322 """,
323 """\
324 <document source="test data">
325 <paragraph>
326 <reference name="phrase reference" refname="phrase reference">
327 phrase reference
328 """],
329 ["""\
330 `anonymous reference`__
331 """,
332 """\
333 <document source="test data">
334 <paragraph>
335 <reference anonymous="1" name="anonymous reference">
336 anonymous reference
337 """],
338 ["""\
339 `phrase reference
340 across lines`_
341 """,
342 """\
343 <document source="test data">
344 <paragraph>
345 <reference name="phrase reference across lines" refname="phrase reference across lines">
346 phrase reference
347 across lines
348 """],
349 ["""\
350 `phrase\`_ reference`_
351 """,
352 """\
353 <document source="test data">
354 <paragraph>
355 <reference name="phrase`_ reference" refname="phrase`_ reference">
356 phrase`_ reference
357 """],
358 ["""\
359 Invalid phrase reference:
361 :role:`phrase reference`_
362 """,
363 """\
364 <document source="test data">
365 <paragraph>
366 Invalid phrase reference:
367 <paragraph>
368 <problematic ids="id2" refid="id1">
369 :role:`phrase reference`_
370 <system_message backrefs="id2" ids="id1" level="2" line="3" source="test data" type="WARNING">
371 <paragraph>
372 Mismatch: both interpreted text role prefix and reference suffix.
373 """],
374 ["""\
375 Invalid phrase reference:
377 `phrase reference`:role:_
378 """,
379 """\
380 <document source="test data">
381 <paragraph>
382 Invalid phrase reference:
383 <paragraph>
384 <problematic ids="id2" refid="id1">
385 `phrase reference`:role:_
386 <system_message backrefs="id2" ids="id1" level="2" line="3" source="test data" type="WARNING">
387 <paragraph>
388 Mismatch: both interpreted text role suffix and reference suffix.
389 """],
390 ["""\
391 `phrase reference_ without closing backquote
392 """,
393 """\
394 <document source="test data">
395 <paragraph>
396 <problematic ids="id2" refid="id1">
398 phrase \n\
399 <reference name="reference" refname="reference">
400 reference
401 without closing backquote
402 <system_message backrefs="id2" ids="id1" level="2" line="1" source="test data" type="WARNING">
403 <paragraph>
404 Inline interpreted text or phrase reference start-string without end-string.
405 """],
406 ["""\
407 `anonymous phrase reference__ without closing backquote
408 """,
409 """\
410 <document source="test data">
411 <paragraph>
412 <problematic ids="id2" refid="id1">
414 anonymous phrase \n\
415 <reference anonymous="1" name="reference">
416 reference
417 without closing backquote
418 <system_message backrefs="id2" ids="id1" level="2" line="1" source="test data" type="WARNING">
419 <paragraph>
420 Inline interpreted text or phrase reference start-string without end-string.
421 """],
424 totest['embedded_URIs'] = [
425 ["""\
426 `phrase reference <http://example.com>`_
427 """,
428 """\
429 <document source="test data">
430 <paragraph>
431 <reference name="phrase reference" refuri="http://example.com">
432 phrase reference
433 <target ids="phrase-reference" names="phrase\ reference" refuri="http://example.com">
434 """],
435 ["""\
436 `anonymous reference <http://example.com>`__
437 """,
438 """\
439 <document source="test data">
440 <paragraph>
441 <reference name="anonymous reference" refuri="http://example.com">
442 anonymous reference
443 """],
444 ["""\
445 `embedded URI on next line
446 <http://example.com>`__
447 """,
448 """\
449 <document source="test data">
450 <paragraph>
451 <reference name="embedded URI on next line" refuri="http://example.com">
452 embedded URI on next line
453 """],
454 ["""\
455 `embedded URI across lines <http://example.com/
456 long/path>`__
457 """,
458 """\
459 <document source="test data">
460 <paragraph>
461 <reference name="embedded URI across lines" refuri="http://example.com/long/path">
462 embedded URI across lines
463 """],
464 ["""\
465 `embedded URI with whitespace <http://example.com/
466 long/path /and /whitespace>`__
467 """,
468 """\
469 <document source="test data">
470 <paragraph>
471 <reference name="embedded URI with whitespace" refuri="http://example.com/long/path/and/whitespace">
472 embedded URI with whitespace
473 """],
474 ["""\
475 `embedded email address <jdoe@example.com>`__
477 `embedded email address broken across lines <jdoe
478 @example.com>`__
479 """,
480 """\
481 <document source="test data">
482 <paragraph>
483 <reference name="embedded email address" refuri="mailto:jdoe@example.com">
484 embedded email address
485 <paragraph>
486 <reference name="embedded email address broken across lines" refuri="mailto:jdoe@example.com">
487 embedded email address broken across lines
488 """],
489 ["""\
490 `embedded URI with too much whitespace < http://example.com/
491 long/path /and /whitespace >`__
493 `embedded URI with too much whitespace at end <http://example.com/
494 long/path /and /whitespace >`__
496 `embedded URI with no preceding whitespace<http://example.com>`__
498 `escaped URI \\<http://example.com>`__
500 See `HTML Anchors: \\<a>`_.
501 """,
502 """\
503 <document source="test data">
504 <paragraph>
505 <reference anonymous="1" name="embedded URI with too much whitespace < http://example.com/ long/path /and /whitespace >">
506 embedded URI with too much whitespace < http://example.com/
507 long/path /and /whitespace >
508 <paragraph>
509 <reference anonymous="1" name="embedded URI with too much whitespace at end <http://example.com/ long/path /and /whitespace >">
510 embedded URI with too much whitespace at end <http://example.com/
511 long/path /and /whitespace >
512 <paragraph>
513 <reference anonymous="1" name="embedded URI with no preceding whitespace<http://example.com>">
514 embedded URI with no preceding whitespace<http://example.com>
515 <paragraph>
516 <reference anonymous="1" name="escaped URI <http://example.com>">
517 escaped URI <http://example.com>
518 <paragraph>
519 See \n\
520 <reference name="HTML Anchors: <a>" refname="html anchors: <a>">
521 HTML Anchors: <a>
523 """],
524 ["""\
525 Relative URIs' reference text can be omitted:
527 `<reference>`_
529 `<anonymous>`__
530 """,
531 """\
532 <document source="test data">
533 <paragraph>
534 Relative URIs' reference text can be omitted:
535 <paragraph>
536 <reference name="reference" refuri="reference">
537 reference
538 <target ids="reference" names="reference" refuri="reference">
539 <paragraph>
540 <reference name="anonymous" refuri="anonymous">
541 anonymous
542 """],
545 totest['inline_targets'] = [
546 ["""\
547 _`target`
549 Here is _`another target` in some text. And _`yet
550 another target`, spanning lines.
552 _`Here is a TaRgeT` with case and spacial difficulties.
553 """,
554 """\
555 <document source="test data">
556 <paragraph>
557 <target ids="target" names="target">
558 target
559 <paragraph>
560 Here is \n\
561 <target ids="another-target" names="another\ target">
562 another target
563 in some text. And \n\
564 <target ids="yet-another-target" names="yet\ another\ target">
566 another target
567 , spanning lines.
568 <paragraph>
569 <target ids="here-is-a-target" names="here\ is\ a\ target">
570 Here is a TaRgeT
571 with case and spacial difficulties.
572 """],
573 ["""\
574 But this isn't a _target; targets require backquotes.
576 And _`this`_ is just plain confusing.
577 """,
578 """\
579 <document source="test data">
580 <paragraph>
581 But this isn't a _target; targets require backquotes.
582 <paragraph>
583 And \n\
584 <problematic ids="id2" refid="id1">
586 this`_ is just plain confusing.
587 <system_message backrefs="id2" ids="id1" level="2" line="3" source="test data" type="WARNING">
588 <paragraph>
589 Inline target start-string without end-string.
590 """],
591 ["""\
592 _`inline target without closing backquote
593 """,
594 """\
595 <document source="test data">
596 <paragraph>
597 <problematic ids="id2" refid="id1">
599 inline target without closing backquote
600 <system_message backrefs="id2" ids="id1" level="2" line="1" source="test data" type="WARNING">
601 <paragraph>
602 Inline target start-string without end-string.
603 """],
606 totest['footnote_reference'] = [
607 ["""\
608 [1]_
609 """,
610 """\
611 <document source="test data">
612 <paragraph>
613 <footnote_reference ids="id1" refname="1">
615 """],
616 ["""\
617 [#]_
618 """,
619 """\
620 <document source="test data">
621 <paragraph>
622 <footnote_reference auto="1" ids="id1">
623 """],
624 ["""\
625 [#label]_
626 """,
627 """\
628 <document source="test data">
629 <paragraph>
630 <footnote_reference auto="1" ids="id1" refname="label">
631 """],
632 ["""\
633 [*]_
634 """,
635 """\
636 <document source="test data">
637 <paragraph>
638 <footnote_reference auto="*" ids="id1">
639 """],
642 totest['citation_reference'] = [
643 ["""\
644 [citation]_
645 """,
646 """\
647 <document source="test data">
648 <paragraph>
649 <citation_reference ids="id1" refname="citation">
650 citation
651 """],
652 ["""\
653 [citation]_ and [cit-ation]_ and [cit.ation]_ and [CIT1]_ but not [CIT 1]_
654 """,
655 """\
656 <document source="test data">
657 <paragraph>
658 <citation_reference ids="id1" refname="citation">
659 citation
660 and \n\
661 <citation_reference ids="id2" refname="cit-ation">
662 cit-ation
663 and \n\
664 <citation_reference ids="id3" refname="cit.ation">
665 cit.ation
666 and \n\
667 <citation_reference ids="id4" refname="cit1">
668 CIT1
669 but not [CIT 1]_
670 """],
673 totest['substitution_references'] = [
674 ["""\
675 |subref|
676 """,
677 """\
678 <document source="test data">
679 <paragraph>
680 <substitution_reference refname="subref">
681 subref
682 """],
683 ["""\
684 |subref|_ and |subref|__
685 """,
686 """\
687 <document source="test data">
688 <paragraph>
689 <reference refname="subref">
690 <substitution_reference refname="subref">
691 subref
692 and \n\
693 <reference anonymous="1">
694 <substitution_reference refname="subref">
695 subref
696 """],
697 ["""\
698 |substitution reference|
699 """,
700 """\
701 <document source="test data">
702 <paragraph>
703 <substitution_reference refname="substitution reference">
704 substitution reference
705 """],
706 ["""\
707 |substitution
708 reference|
709 """,
710 """\
711 <document source="test data">
712 <paragraph>
713 <substitution_reference refname="substitution reference">
714 substitution
715 reference
716 """],
717 ["""\
718 |substitution reference without closing verbar
719 """,
720 """\
721 <document source="test data">
722 <paragraph>
723 <problematic ids="id2" refid="id1">
725 substitution reference without closing verbar
726 <system_message backrefs="id2" ids="id1" level="2" line="1" source="test data" type="WARNING">
727 <paragraph>
728 Inline substitution_reference start-string without end-string.
729 """],
730 ["""\
731 first | then || and finally |||
732 """,
733 """\
734 <document source="test data">
735 <paragraph>
736 first | then || and finally |||
737 """],
740 totest['standalone_hyperlink'] = [
741 ["""\
742 http://www.standalone.hyperlink.com
744 http:/one-slash-only.absolute.path
746 [http://example.com]
748 (http://example.com)
750 <http://example.com>
752 http://[1080:0:0:0:8:800:200C:417A]/IPv6address.html
754 http://[3ffe:2a00:100:7031::1] (the final "]" is ambiguous in text)
756 http://[3ffe:2a00:100:7031::1]/
758 mailto:someone@somewhere.com
760 news:comp.lang.python
762 An email address in a sentence: someone@somewhere.com.
764 ftp://ends.with.a.period.
766 (a.question.mark@end?)
767 """,
768 """\
769 <document source="test data">
770 <paragraph>
771 <reference refuri="http://www.standalone.hyperlink.com">
772 http://www.standalone.hyperlink.com
773 <paragraph>
774 <reference refuri="http:/one-slash-only.absolute.path">
775 http:/one-slash-only.absolute.path
776 <paragraph>
778 <reference refuri="http://example.com">
779 http://example.com
781 <paragraph>
783 <reference refuri="http://example.com">
784 http://example.com
786 <paragraph>
788 <reference refuri="http://example.com">
789 http://example.com
791 <paragraph>
792 <reference refuri="http://[1080:0:0:0:8:800:200C:417A]/IPv6address.html">
793 http://[1080:0:0:0:8:800:200C:417A]/IPv6address.html
794 <paragraph>
795 <reference refuri="http://[3ffe:2a00:100:7031::1">
796 http://[3ffe:2a00:100:7031::1
797 ] (the final "]" is ambiguous in text)
798 <paragraph>
799 <reference refuri="http://[3ffe:2a00:100:7031::1]/">
800 http://[3ffe:2a00:100:7031::1]/
801 <paragraph>
802 <reference refuri="mailto:someone@somewhere.com">
803 mailto:someone@somewhere.com
804 <paragraph>
805 <reference refuri="news:comp.lang.python">
806 news:comp.lang.python
807 <paragraph>
808 An email address in a sentence: \n\
809 <reference refuri="mailto:someone@somewhere.com">
810 someone@somewhere.com
812 <paragraph>
813 <reference refuri="ftp://ends.with.a.period">
814 ftp://ends.with.a.period
816 <paragraph>
818 <reference refuri="mailto:a.question.mark@end">
819 a.question.mark@end
821 """],
822 ["""\
823 Valid URLs with escaped markup characters:
825 http://example.com/\\*content\\*/whatever
827 http://example.com/\\*content*/whatever
828 """,
829 """\
830 <document source="test data">
831 <paragraph>
832 Valid URLs with escaped markup characters:
833 <paragraph>
834 <reference refuri="http://example.com/*content*/whatever">
835 http://example.com/*content*/whatever
836 <paragraph>
837 <reference refuri="http://example.com/*content*/whatever">
838 http://example.com/*content*/whatever
839 """],
840 ["""\
841 Valid URLs may end with punctuation inside "<>":
843 <http://example.org/ends-with-dot.>
844 """,
845 """\
846 <document source="test data">
847 <paragraph>
848 Valid URLs may end with punctuation inside "<>":
849 <paragraph>
851 <reference refuri="http://example.org/ends-with-dot.">
852 http://example.org/ends-with-dot.
854 """],
855 ["""\
856 Valid URLs with interesting endings:
858 http://example.org/ends-with-pluses++
859 """,
860 """\
861 <document source="test data">
862 <paragraph>
863 Valid URLs with interesting endings:
864 <paragraph>
865 <reference refuri="http://example.org/ends-with-pluses++">
866 http://example.org/ends-with-pluses++
867 """],
868 ["""\
869 None of these are standalone hyperlinks (their "schemes"
870 are not recognized): signal:noise, a:b.
871 """,
872 """\
873 <document source="test data">
874 <paragraph>
875 None of these are standalone hyperlinks (their "schemes"
876 are not recognized): signal:noise, a:b.
877 """],
878 ["""\
879 Escaped email addresses are not recognized: test\@example.org
880 """,
881 """\
882 <document source="test data">
883 <paragraph>
884 Escaped email addresses are not recognized: test@example.org
885 """],
888 totest['miscellaneous'] = [
889 ["""\
890 __This__ should be left alone.
891 """,
892 """\
893 <document source="test data">
894 <paragraph>
895 __This__ should be left alone.
896 """],
897 [r"""
898 Character-level m\ *a*\ **r**\ ``k``\ `u`:title:\p
899 with backslash-escaped whitespace, including new\
900 lines.
901 """,
902 """\
903 <document source="test data">
904 <paragraph>
905 Character-level m
906 <emphasis>
908 <strong>
910 <literal>
912 <title_reference>
915 with backslash-escaped whitespace, including newlines.
916 """],
920 if __name__ == '__main__':
921 import unittest
922 unittest.main(defaultTest='suite')