4 # Author: David Goodger <goodger@python.org>
5 # Copyright: This module has been placed in the public domain.
8 Tests for inline markup in docutils/parsers/rst/states.py.
9 Interpreted text tests are in a separate module, test_interpreted.py.
12 from __init__
import DocutilsTestSupport
15 s
= DocutilsTestSupport
.ParserTestSuite()
16 s
.generateTests(totest
)
21 totest
['emphasis'] = [
26 <document source="test data">
36 <document source="test data">
43 *emphasis without closing asterisk
46 <document source="test data">
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">
53 Inline emphasis start-string without end-string.
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)
65 <document source="test data">
80 but not '*' or '"*"' or x*2* or 2*x* or *args or *
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">
91 Inline emphasis start-string without end-string.
99 Emphasized asterisk: *\\**
101 Emphasized double asterisk: *\\***
104 <document source="test data">
106 Emphasized asterisk: \n\
110 Emphasized double asterisk: \n\
121 <document source="test data">
127 (**strong**) but not (**) or '(** ' or x**2 or \\**kwargs or **
129 (however, '**kwargs' will trigger a warning and may be problematic)
132 <document source="test data">
137 ) but not (**) or '(** ' or x**2 or **kwargs or **
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">
145 Inline strong start-string without end-string.
148 Strong asterisk: *****
150 Strong double asterisk: ******
153 <document source="test data">
159 Strong double asterisk: \n\
164 **strong without closing asterisks
167 <document source="test data">
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">
174 Inline strong start-string without end-string.
178 totest
['literal'] = [
183 <document source="test data">
192 <document source="test data">
201 <document source="test data">
210 <document source="test data">
216 ``literal ``TeX quotes'' & \\backslash`` but not "``" or ``
218 (however, ``standalone TeX quotes'' will trigger a warning
219 and may be problematic)
222 <document source="test data">
225 literal ``TeX quotes'' & \\backslash
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">
235 Inline literal start-string without end-string.
238 Find the ```interpreted text``` in this paragraph!
241 <document source="test data">
249 ``literal without closing backquotes
252 <document source="test data">
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">
259 Inline literal start-string without end-string.
262 Python ``list``\\s use square bracket syntax.
265 <document source="test data">
270 s use square bracket syntax.
274 totest
['references'] = [
279 <document source="test data">
281 <reference name="ref" refname="ref">
288 <document source="test data">
290 <reference anonymous="1" name="ref">
294 ref_, r_, r_e-f_, -ref_, and anonymousref__,
295 but not _ref_ or __attr__ or object.__attr__
298 <document source="test data">
300 <reference name="ref" refname="ref">
303 <reference name="r" refname="r">
306 <reference name="r_e-f" refname="r_e-f">
309 <reference name="ref" refname="ref">
312 <reference anonymous="1" name="anonymousref">
315 but not _ref_ or __attr__ or object.__attr__
319 totest
['phrase_references'] = [
324 <document source="test data">
326 <reference name="phrase reference" refname="phrase reference">
330 `anonymous reference`__
333 <document source="test data">
335 <reference anonymous="1" name="anonymous reference">
343 <document source="test data">
345 <reference name="phrase reference across lines" refname="phrase reference across lines">
350 `phrase\`_ reference`_
353 <document source="test data">
355 <reference name="phrase`_ reference" refname="phrase`_ reference">
359 Invalid phrase reference:
361 :role:`phrase reference`_
364 <document source="test data">
366 Invalid phrase reference:
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">
372 Mismatch: both interpreted text role prefix and reference suffix.
375 Invalid phrase reference:
377 `phrase reference`:role:_
380 <document source="test data">
382 Invalid phrase reference:
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">
388 Mismatch: both interpreted text role suffix and reference suffix.
391 `phrase reference_ without closing backquote
394 <document source="test data">
396 <problematic ids="id2" refid="id1">
399 <reference name="reference" refname="reference">
401 without closing backquote
402 <system_message backrefs="id2" ids="id1" level="2" line="1" source="test data" type="WARNING">
404 Inline interpreted text or phrase reference start-string without end-string.
407 `anonymous phrase reference__ without closing backquote
410 <document source="test data">
412 <problematic ids="id2" refid="id1">
415 <reference anonymous="1" name="reference">
417 without closing backquote
418 <system_message backrefs="id2" ids="id1" level="2" line="1" source="test data" type="WARNING">
420 Inline interpreted text or phrase reference start-string without end-string.
424 totest
['embedded_URIs'] = [
426 `phrase reference <http://example.com>`_
429 <document source="test data">
431 <reference name="phrase reference" refuri="http://example.com">
433 <target ids="phrase-reference" names="phrase\ reference" refuri="http://example.com">
436 `anonymous reference <http://example.com>`__
439 <document source="test data">
441 <reference name="anonymous reference" refuri="http://example.com">
445 `embedded URI on next line
446 <http://example.com>`__
449 <document source="test data">
451 <reference name="embedded URI on next line" refuri="http://example.com">
452 embedded URI on next line
455 `embedded URI across lines <http://example.com/
459 <document source="test data">
461 <reference name="embedded URI across lines" refuri="http://example.com/long/path">
462 embedded URI across lines
465 `embedded URI with whitespace <http://example.com/
466 long/path /and /whitespace>`__
469 <document source="test data">
471 <reference name="embedded URI with whitespace" refuri="http://example.com/long/path/and/whitespace">
472 embedded URI with whitespace
475 `embedded email address <jdoe@example.com>`__
477 `embedded email address broken across lines <jdoe
481 <document source="test data">
483 <reference name="embedded email address" refuri="mailto:jdoe@example.com">
484 embedded email address
486 <reference name="embedded email address broken across lines" refuri="mailto:jdoe@example.com">
487 embedded email address broken across lines
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>`_.
503 <document source="test data">
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 >
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 >
513 <reference anonymous="1" name="embedded URI with no preceding whitespace<http://example.com>">
514 embedded URI with no preceding whitespace<http://example.com>
516 <reference anonymous="1" name="escaped URI <http://example.com>">
517 escaped URI <http://example.com>
520 <reference name="HTML Anchors: <a>" refname="html anchors: <a>">
525 Relative URIs' reference text can be omitted:
532 <document source="test data">
534 Relative URIs' reference text can be omitted:
536 <reference name="reference" refuri="reference">
538 <target ids="reference" names="reference" refuri="reference">
540 <reference name="anonymous" refuri="anonymous">
545 totest
['inline_targets'] = [
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.
555 <document source="test data">
557 <target ids="target" names="target">
561 <target ids="another-target" names="another\ target">
563 in some text. And \n\
564 <target ids="yet-another-target" names="yet\ another\ target">
569 <target ids="here-is-a-target" names="here\ is\ a\ target">
571 with case and spacial difficulties.
574 But this isn't a _target; targets require backquotes.
576 And _`this`_ is just plain confusing.
579 <document source="test data">
581 But this isn't a _target; targets require backquotes.
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">
589 Inline target start-string without end-string.
592 _`inline target without closing backquote
595 <document source="test data">
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">
602 Inline target start-string without end-string.
606 totest
['footnote_reference'] = [
611 <document source="test data">
613 <footnote_reference ids="id1" refname="1">
620 <document source="test data">
622 <footnote_reference auto="1" ids="id1">
628 <document source="test data">
630 <footnote_reference auto="1" ids="id1" refname="label">
636 <document source="test data">
638 <footnote_reference auto="*" ids="id1">
642 totest
['citation_reference'] = [
647 <document source="test data">
649 <citation_reference ids="id1" refname="citation">
653 [citation]_ and [cit-ation]_ and [cit.ation]_ and [CIT1]_ but not [CIT 1]_
656 <document source="test data">
658 <citation_reference ids="id1" refname="citation">
661 <citation_reference ids="id2" refname="cit-ation">
664 <citation_reference ids="id3" refname="cit.ation">
667 <citation_reference ids="id4" refname="cit1">
673 totest
['substitution_references'] = [
678 <document source="test data">
680 <substitution_reference refname="subref">
684 |subref|_ and |subref|__
687 <document source="test data">
689 <reference refname="subref">
690 <substitution_reference refname="subref">
693 <reference anonymous="1">
694 <substitution_reference refname="subref">
698 |substitution reference|
701 <document source="test data">
703 <substitution_reference refname="substitution reference">
704 substitution reference
711 <document source="test data">
713 <substitution_reference refname="substitution reference">
718 |substitution reference without closing verbar
721 <document source="test data">
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">
728 Inline substitution_reference start-string without end-string.
731 first | then || and finally |||
734 <document source="test data">
736 first | then || and finally |||
740 totest
['standalone_hyperlink'] = [
742 http://www.standalone.hyperlink.com
744 http:/one-slash-only.absolute.path
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?)
769 <document source="test data">
771 <reference refuri="http://www.standalone.hyperlink.com">
772 http://www.standalone.hyperlink.com
774 <reference refuri="http:/one-slash-only.absolute.path">
775 http:/one-slash-only.absolute.path
778 <reference refuri="http://example.com">
783 <reference refuri="http://example.com">
788 <reference refuri="http://example.com">
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
795 <reference refuri="http://[3ffe:2a00:100:7031::1">
796 http://[3ffe:2a00:100:7031::1
797 ] (the final "]" is ambiguous in text)
799 <reference refuri="http://[3ffe:2a00:100:7031::1]/">
800 http://[3ffe:2a00:100:7031::1]/
802 <reference refuri="mailto:someone@somewhere.com">
803 mailto:someone@somewhere.com
805 <reference refuri="news:comp.lang.python">
806 news:comp.lang.python
808 An email address in a sentence: \n\
809 <reference refuri="mailto:someone@somewhere.com">
810 someone@somewhere.com
813 <reference refuri="ftp://ends.with.a.period">
814 ftp://ends.with.a.period
818 <reference refuri="mailto:a.question.mark@end">
823 Valid URLs with escaped markup characters:
825 http://example.com/\\*content\\*/whatever
827 http://example.com/\\*content*/whatever
830 <document source="test data">
832 Valid URLs with escaped markup characters:
834 <reference refuri="http://example.com/*content*/whatever">
835 http://example.com/*content*/whatever
837 <reference refuri="http://example.com/*content*/whatever">
838 http://example.com/*content*/whatever
841 Valid URLs may end with punctuation inside "<>":
843 <http://example.org/ends-with-dot.>
846 <document source="test data">
848 Valid URLs may end with punctuation inside "<>":
851 <reference refuri="http://example.org/ends-with-dot.">
852 http://example.org/ends-with-dot.
856 Valid URLs with interesting endings:
858 http://example.org/ends-with-pluses++
861 <document source="test data">
863 Valid URLs with interesting endings:
865 <reference refuri="http://example.org/ends-with-pluses++">
866 http://example.org/ends-with-pluses++
869 None of these are standalone hyperlinks (their "schemes"
870 are not recognized): signal:noise, a:b.
873 <document source="test data">
875 None of these are standalone hyperlinks (their "schemes"
876 are not recognized): signal:noise, a:b.
879 Escaped email addresses are not recognized: test\@example.org
882 <document source="test data">
884 Escaped email addresses are not recognized: test@example.org
888 totest
['miscellaneous'] = [
890 __This__ should be left alone.
893 <document source="test data">
895 __This__ should be left alone.
898 Character-level m\ *a*\ **r**\ ``k``\ `u`:title:\p
899 with backslash-escaped whitespace, including new\
903 <document source="test data">
915 with backslash-escaped whitespace, including newlines.
920 if __name__
== '__main__':
922 unittest
.main(defaultTest
='suite')