~ubuntu-branches/ubuntu/jaunty/python-docutils/jaunty

« back to all changes in this revision

Viewing changes to test/test_rst/test_inline_markup.py

  • Committer: Bazaar Package Importer
  • Author(s): martin f. krafft
  • Date: 2006-07-10 11:45:05 UTC
  • mfrom: (2.1.4 edgy)
  • Revision ID: james.westby@ubuntu.com-20060710114505-otkhqcslevewxmz5
Tags: 0.4-3
Added build dependency on python-central (closes: #377580).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/env python
2
 
 
3
 
"""
4
 
:Author: David Goodger
5
 
:Contact: goodger@users.sourceforge.net
6
 
:Revision: $Revision: 1.6 $
7
 
:Date: $Date: 2002/07/04 01:35:55 $
8
 
:Copyright: This module has been placed in the public domain.
9
 
 
10
 
Tests for states.py.
11
 
"""
12
 
 
13
 
from __init__ import DocutilsTestSupport
14
 
 
15
 
def suite():
16
 
    s = DocutilsTestSupport.ParserTestSuite()
17
 
    s.generateTests(totest)
18
 
    return s
19
 
 
20
 
totest = {}
21
 
 
22
 
totest['emphasis'] = [
23
 
["""\
24
 
*emphasis*
25
 
""",
26
 
"""\
27
 
<document>
28
 
    <paragraph>
29
 
        <emphasis>
30
 
            emphasis
31
 
"""],
32
 
["""\
33
 
*emphasized sentence
34
 
across lines*
35
 
""",
36
 
"""\
37
 
<document>
38
 
    <paragraph>
39
 
        <emphasis>
40
 
            emphasized sentence
41
 
            across lines
42
 
"""],
43
 
["""\
44
 
*emphasis without closing asterisk
45
 
""",
46
 
"""\
47
 
<document>
48
 
    <paragraph>
49
 
        <problematic id="id2" refid="id1">
50
 
            *
51
 
        emphasis without closing asterisk
52
 
    <system_message backrefs="id2" id="id1" level="2" type="WARNING">
53
 
        <paragraph>
54
 
            Inline emphasis start-string without end-string at line 1.
55
 
"""],
56
 
["""\
57
 
'*emphasis*' and 1/*emphasis*/2 and 3-*emphasis*-4 and 5:*emphasis*:6
58
 
but not '*' or '"*"' or  x*2* or 2*x* or \\*args or *
59
 
or *the\\* *stars\\\\\\* *inside*
60
 
 
61
 
(however, '*args' will trigger a warning and may be problematic)
62
 
 
63
 
what about *this**?
64
 
""",
65
 
"""\
66
 
<document>
67
 
    <paragraph>
68
 
        '
69
 
        <emphasis>
70
 
            emphasis
71
 
        ' and 1/
72
 
        <emphasis>
73
 
            emphasis
74
 
        /2 and 3-
75
 
        <emphasis>
76
 
            emphasis
77
 
        -4 and 5:
78
 
        <emphasis>
79
 
            emphasis
80
 
        :6
81
 
        but not '*' or '"*"' or  x*2* or 2*x* or *args or *
82
 
        or \n\
83
 
        <emphasis>
84
 
            the* *stars\* *inside
85
 
    <paragraph>
86
 
        (however, '
87
 
        <problematic id="id2" refid="id1">
88
 
            *
89
 
        args' will trigger a warning and may be problematic)
90
 
    <system_message backrefs="id2" id="id1" level="2" type="WARNING">
91
 
        <paragraph>
92
 
            Inline emphasis start-string without end-string at line 5.
93
 
    <paragraph>
94
 
        what about \n\
95
 
        <emphasis>
96
 
            this*
97
 
        ?
98
 
"""],
99
 
["""\
100
 
Emphasized asterisk: *\\**
101
 
 
102
 
Emphasized double asterisk: *\\***
103
 
""",
104
 
"""\
105
 
<document>
106
 
    <paragraph>
107
 
        Emphasized asterisk: \n\
108
 
        <emphasis>
109
 
            *
110
 
    <paragraph>
111
 
        Emphasized double asterisk: \n\
112
 
        <emphasis>
113
 
            **
114
 
"""],
115
 
]
116
 
 
117
 
totest['strong'] = [
118
 
["""\
119
 
**strong**
120
 
""",
121
 
"""\
122
 
<document>
123
 
    <paragraph>
124
 
        <strong>
125
 
            strong
126
 
"""],
127
 
["""\
128
 
(**strong**) but not (**) or '(** ' or x**2 or \\**kwargs or **
129
 
 
130
 
(however, '**kwargs' will trigger a warning and may be problematic)
131
 
""",
132
 
"""\
133
 
<document>
134
 
    <paragraph>
135
 
        (
136
 
        <strong>
137
 
            strong
138
 
        ) but not (**) or '(** ' or x**2 or **kwargs or **
139
 
    <paragraph>
140
 
        (however, '
141
 
        <problematic id="id2" refid="id1">
142
 
            **
143
 
        kwargs' will trigger a warning and may be problematic)
144
 
    <system_message backrefs="id2" id="id1" level="2" type="WARNING">
145
 
        <paragraph>
146
 
            Inline strong start-string without end-string at line 3.
147
 
"""],
148
 
["""\
149
 
Strong asterisk: *****
150
 
 
151
 
Strong double asterisk: ******
152
 
""",
153
 
"""\
154
 
<document>
155
 
    <paragraph>
156
 
        Strong asterisk: \n\
157
 
        <strong>
158
 
            *
159
 
    <paragraph>
160
 
        Strong double asterisk: \n\
161
 
        <strong>
162
 
            **
163
 
"""],
164
 
["""\
165
 
**strong without closing asterisks
166
 
""",
167
 
"""\
168
 
<document>
169
 
    <paragraph>
170
 
        <problematic id="id2" refid="id1">
171
 
            **
172
 
        strong without closing asterisks
173
 
    <system_message backrefs="id2" id="id1" level="2" type="WARNING">
174
 
        <paragraph>
175
 
            Inline strong start-string without end-string at line 1.
176
 
"""],
177
 
]
178
 
 
179
 
totest['literal'] = [
180
 
["""\
181
 
``literal``
182
 
""",
183
 
"""\
184
 
<document>
185
 
    <paragraph>
186
 
        <literal>
187
 
            literal
188
 
"""],
189
 
["""\
190
 
``\\literal``
191
 
""",
192
 
"""\
193
 
<document>
194
 
    <paragraph>
195
 
        <literal>
196
 
            \\literal
197
 
"""],
198
 
["""\
199
 
``lite\\ral``
200
 
""",
201
 
"""\
202
 
<document>
203
 
    <paragraph>
204
 
        <literal>
205
 
            lite\\ral
206
 
"""],
207
 
["""\
208
 
``literal\\``
209
 
""",
210
 
"""\
211
 
<document>
212
 
    <paragraph>
213
 
        <literal>
214
 
            literal\\
215
 
"""],
216
 
["""\
217
 
``literal ``TeX quotes'' & \\backslash`` but not "``" or ``
218
 
 
219
 
(however, ``standalone TeX quotes'' will trigger a warning
220
 
and may be problematic)
221
 
""",
222
 
"""\
223
 
<document>
224
 
    <paragraph>
225
 
        <literal>
226
 
            literal ``TeX quotes'' & \\backslash
227
 
         but not "``" or ``
228
 
    <paragraph>
229
 
        (however, \n\
230
 
        <problematic id="id2" refid="id1">
231
 
            ``
232
 
        standalone TeX quotes'' will trigger a warning
233
 
        and may be problematic)
234
 
    <system_message backrefs="id2" id="id1" level="2" type="WARNING">
235
 
        <paragraph>
236
 
            Inline literal start-string without end-string at line 3.
237
 
"""],
238
 
["""\
239
 
Find the ```interpreted text``` in this paragraph!
240
 
""",
241
 
"""\
242
 
<document>
243
 
    <paragraph>
244
 
        Find the \n\
245
 
        <literal>
246
 
            `interpreted text`
247
 
         in this paragraph!
248
 
"""],
249
 
["""\
250
 
``literal without closing backquotes
251
 
""",
252
 
"""\
253
 
<document>
254
 
    <paragraph>
255
 
        <problematic id="id2" refid="id1">
256
 
            ``
257
 
        literal without closing backquotes
258
 
    <system_message backrefs="id2" id="id1" level="2" type="WARNING">
259
 
        <paragraph>
260
 
            Inline literal start-string without end-string at line 1.
261
 
"""],
262
 
]
263
 
 
264
 
totest['interpreted'] = [
265
 
["""\
266
 
`interpreted`
267
 
""",
268
 
"""\
269
 
<document>
270
 
    <paragraph>
271
 
        <interpreted>
272
 
            interpreted
273
 
"""],
274
 
["""\
275
 
:role:`interpreted`
276
 
""",
277
 
"""\
278
 
<document>
279
 
    <paragraph>
280
 
        <interpreted position="prefix" role="role">
281
 
            interpreted
282
 
"""],
283
 
["""\
284
 
`interpreted`:role:
285
 
""",
286
 
"""\
287
 
<document>
288
 
    <paragraph>
289
 
        <interpreted position="suffix" role="role">
290
 
            interpreted
291
 
"""],
292
 
["""\
293
 
:role:`interpreted`:role:
294
 
""",
295
 
"""\
296
 
<document>
297
 
    <paragraph>
298
 
        <problematic id="id2" refid="id1">
299
 
            :role:`interpreted`:role:
300
 
    <system_message backrefs="id2" id="id1" level="2" type="WARNING">
301
 
        <paragraph>
302
 
            Multiple roles in interpreted text at line 1 (both prefix and suffix present; only one allowed).
303
 
"""],
304
 
["""\
305
 
:role:`:not-role: interpreted`
306
 
""",
307
 
"""\
308
 
<document>
309
 
    <paragraph>
310
 
        <interpreted position="prefix" role="role">
311
 
            :not-role: interpreted
312
 
"""],
313
 
["""\
314
 
:very.long-role_name:`interpreted`
315
 
""",
316
 
"""\
317
 
<document>
318
 
    <paragraph>
319
 
        <interpreted position="prefix" role="very.long-role_name">
320
 
            interpreted
321
 
"""],
322
 
["""\
323
 
`interpreted` but not \\`interpreted` [`] or ({[`] or [`]}) or `
324
 
""",
325
 
"""\
326
 
<document>
327
 
    <paragraph>
328
 
        <interpreted>
329
 
            interpreted
330
 
         but not `interpreted` [`] or ({[`] or [`]}) or `
331
 
"""],
332
 
["""\
333
 
`interpreted`-text `interpreted`: text `interpreted`:text `text`'s interpreted
334
 
""",
335
 
"""\
336
 
<document>
337
 
    <paragraph>
338
 
        <interpreted>
339
 
            interpreted
340
 
        -text \n\
341
 
        <interpreted>
342
 
            interpreted
343
 
        : text \n\
344
 
        <interpreted>
345
 
            interpreted
346
 
        :text \n\
347
 
        <interpreted>
348
 
            text
349
 
        's interpreted
350
 
"""],
351
 
["""\
352
 
`interpreted without closing backquote
353
 
""",
354
 
"""\
355
 
<document>
356
 
    <paragraph>
357
 
        <problematic id="id2" refid="id1">
358
 
            `
359
 
        interpreted without closing backquote
360
 
    <system_message backrefs="id2" id="id1" level="2" type="WARNING">
361
 
        <paragraph>
362
 
            Inline interpreted text or phrase reference start-string without end-string at line 1.
363
 
"""],
364
 
]
365
 
 
366
 
totest['references'] = [
367
 
["""\
368
 
ref_
369
 
""",
370
 
"""\
371
 
<document>
372
 
    <paragraph>
373
 
        <reference refname="ref">
374
 
            ref
375
 
"""],
376
 
["""\
377
 
ref__
378
 
""",
379
 
"""\
380
 
<document>
381
 
    <paragraph>
382
 
        <reference anonymous="1">
383
 
            ref
384
 
"""],
385
 
["""\
386
 
ref_, r_, r_e-f_, -ref_, and anonymousref__, but not _ref_
387
 
""",
388
 
"""\
389
 
<document>
390
 
    <paragraph>
391
 
        <reference refname="ref">
392
 
            ref
393
 
        , \n\
394
 
        <reference refname="r">
395
 
            r
396
 
        , \n\
397
 
        <reference refname="r_e-f">
398
 
            r_e-f
399
 
        , -
400
 
        <reference refname="ref">
401
 
            ref
402
 
        , and \n\
403
 
        <reference anonymous="1">
404
 
            anonymousref
405
 
        , but not _ref_
406
 
"""],
407
 
]
408
 
 
409
 
totest['phrase_references'] = [
410
 
["""\
411
 
`phrase reference`_
412
 
""",
413
 
"""\
414
 
<document>
415
 
    <paragraph>
416
 
        <reference refname="phrase reference">
417
 
            phrase reference
418
 
"""],
419
 
["""\
420
 
`anonymous reference`__
421
 
""",
422
 
"""\
423
 
<document>
424
 
    <paragraph>
425
 
        <reference anonymous="1">
426
 
            anonymous reference
427
 
"""],
428
 
["""\
429
 
`phrase reference
430
 
across lines`_
431
 
""",
432
 
"""\
433
 
<document>
434
 
    <paragraph>
435
 
        <reference refname="phrase reference across lines">
436
 
            phrase reference
437
 
            across lines
438
 
"""],
439
 
["""\
440
 
`phrase\`_ reference`_
441
 
""",
442
 
"""\
443
 
<document>
444
 
    <paragraph>
445
 
        <reference refname="phrase`_ reference">
446
 
            phrase`_ reference
447
 
"""],
448
 
["""\
449
 
Invalid phrase reference:
450
 
 
451
 
:role:`phrase reference`_
452
 
""",
453
 
"""\
454
 
<document>
455
 
    <paragraph>
456
 
        Invalid phrase reference:
457
 
    <paragraph>
458
 
        <problematic id="id2" refid="id1">
459
 
            :role:`phrase reference`_
460
 
    <system_message backrefs="id2" id="id1" level="2" type="WARNING">
461
 
        <paragraph>
462
 
            Mismatch: both interpreted text role prefix and reference suffix at line 3.
463
 
"""],
464
 
["""\
465
 
Invalid phrase reference:
466
 
 
467
 
`phrase reference`:role:_
468
 
""",
469
 
"""\
470
 
<document>
471
 
    <paragraph>
472
 
        Invalid phrase reference:
473
 
    <paragraph>
474
 
        <problematic id="id2" refid="id1">
475
 
            `phrase reference`:role:_
476
 
    <system_message backrefs="id2" id="id1" level="2" type="WARNING">
477
 
        <paragraph>
478
 
            Mismatch: both interpreted text role suffix and reference suffix at line 3.
479
 
"""],
480
 
["""\
481
 
`phrase reference_ without closing backquote
482
 
""",
483
 
"""\
484
 
<document>
485
 
    <paragraph>
486
 
        <problematic id="id2" refid="id1">
487
 
            `
488
 
        phrase \n\
489
 
        <reference refname="reference">
490
 
            reference
491
 
         without closing backquote
492
 
    <system_message backrefs="id2" id="id1" level="2" type="WARNING">
493
 
        <paragraph>
494
 
            Inline interpreted text or phrase reference start-string without end-string at line 1.
495
 
"""],
496
 
["""\
497
 
`anonymous phrase reference__ without closing backquote
498
 
""",
499
 
"""\
500
 
<document>
501
 
    <paragraph>
502
 
        <problematic id="id2" refid="id1">
503
 
            `
504
 
        anonymous phrase \n\
505
 
        <reference anonymous="1">
506
 
            reference
507
 
         without closing backquote
508
 
    <system_message backrefs="id2" id="id1" level="2" type="WARNING">
509
 
        <paragraph>
510
 
            Inline interpreted text or phrase reference start-string without end-string at line 1.
511
 
"""],
512
 
]
513
 
 
514
 
totest['inline_targets'] = [
515
 
["""\
516
 
_`target`
517
 
 
518
 
Here is _`another target` in some text. And _`yet
519
 
another target`, spanning lines.
520
 
 
521
 
_`Here is  a    TaRgeT` with case and spacial difficulties.
522
 
""",
523
 
"""\
524
 
<document>
525
 
    <paragraph>
526
 
        <target id="target" name="target">
527
 
            target
528
 
    <paragraph>
529
 
        Here is \n\
530
 
        <target id="another-target" name="another target">
531
 
            another target
532
 
         in some text. And \n\
533
 
        <target id="yet-another-target" name="yet another target">
534
 
            yet
535
 
            another target
536
 
        , spanning lines.
537
 
    <paragraph>
538
 
        <target id="here-is-a-target" name="here is a target">
539
 
            Here is  a    TaRgeT
540
 
         with case and spacial difficulties.
541
 
"""],
542
 
["""\
543
 
But this isn't a _target; targets require backquotes.
544
 
 
545
 
And _`this`_ is just plain confusing.
546
 
""",
547
 
"""\
548
 
<document>
549
 
    <paragraph>
550
 
        But this isn't a _target; targets require backquotes.
551
 
    <paragraph>
552
 
        And \n\
553
 
        <problematic id="id2" refid="id1">
554
 
            _`
555
 
        this`_ is just plain confusing.
556
 
    <system_message backrefs="id2" id="id1" level="2" type="WARNING">
557
 
        <paragraph>
558
 
            Inline target start-string without end-string at line 3.
559
 
"""],
560
 
["""\
561
 
_`inline target without closing backquote
562
 
""",
563
 
"""\
564
 
<document>
565
 
    <paragraph>
566
 
        <problematic id="id2" refid="id1">
567
 
            _`
568
 
        inline target without closing backquote
569
 
    <system_message backrefs="id2" id="id1" level="2" type="WARNING">
570
 
        <paragraph>
571
 
            Inline target start-string without end-string at line 1.
572
 
"""],
573
 
]
574
 
 
575
 
totest['footnote_reference'] = [
576
 
["""\
577
 
[1]_
578
 
""",
579
 
"""\
580
 
<document>
581
 
    <paragraph>
582
 
        <footnote_reference id="id1" refname="1">
583
 
            1
584
 
"""],
585
 
["""\
586
 
[#]_
587
 
""",
588
 
"""\
589
 
<document>
590
 
    <paragraph>
591
 
        <footnote_reference auto="1" id="id1">
592
 
"""],
593
 
["""\
594
 
[#label]_
595
 
""",
596
 
"""\
597
 
<document>
598
 
    <paragraph>
599
 
        <footnote_reference auto="1" id="id1" refname="label">
600
 
"""],
601
 
["""\
602
 
[*]_
603
 
""",
604
 
"""\
605
 
<document>
606
 
    <paragraph>
607
 
        <footnote_reference auto="*" id="id1">
608
 
"""],
609
 
]
610
 
 
611
 
totest['citation_reference'] = [
612
 
["""\
613
 
[citation]_
614
 
""",
615
 
"""\
616
 
<document>
617
 
    <paragraph>
618
 
        <citation_reference id="id1" refname="citation">
619
 
            citation
620
 
"""],
621
 
["""\
622
 
[citation]_ and [cit-ation]_ and [cit.ation]_ and [CIT1]_ but not [CIT 1]_
623
 
""",
624
 
"""\
625
 
<document>
626
 
    <paragraph>
627
 
        <citation_reference id="id1" refname="citation">
628
 
            citation
629
 
         and \n\
630
 
        <citation_reference id="id2" refname="cit-ation">
631
 
            cit-ation
632
 
         and \n\
633
 
        <citation_reference id="id3" refname="cit.ation">
634
 
            cit.ation
635
 
         and \n\
636
 
        <citation_reference id="id4" refname="cit1">
637
 
            CIT1
638
 
         but not [CIT 1]_
639
 
"""],
640
 
]
641
 
 
642
 
totest['substitution_references'] = [
643
 
["""\
644
 
|subref|
645
 
""",
646
 
"""\
647
 
<document>
648
 
    <paragraph>
649
 
        <substitution_reference refname="subref">
650
 
            subref
651
 
"""],
652
 
["""\
653
 
|subref|_ and |subref|__
654
 
""",
655
 
"""\
656
 
<document>
657
 
    <paragraph>
658
 
        <reference refname="subref">
659
 
            <substitution_reference refname="subref">
660
 
                subref
661
 
         and \n\
662
 
        <reference anonymous="1">
663
 
            <substitution_reference refname="subref">
664
 
                subref
665
 
"""],
666
 
["""\
667
 
|substitution reference|
668
 
""",
669
 
"""\
670
 
<document>
671
 
    <paragraph>
672
 
        <substitution_reference refname="substitution reference">
673
 
            substitution reference
674
 
"""],
675
 
["""\
676
 
|substitution
677
 
reference|
678
 
""",
679
 
"""\
680
 
<document>
681
 
    <paragraph>
682
 
        <substitution_reference refname="substitution reference">
683
 
            substitution
684
 
            reference
685
 
"""],
686
 
["""\
687
 
|substitution reference without closing verbar
688
 
""",
689
 
"""\
690
 
<document>
691
 
    <paragraph>
692
 
        <problematic id="id2" refid="id1">
693
 
            |
694
 
        substitution reference without closing verbar
695
 
    <system_message backrefs="id2" id="id1" level="2" type="WARNING">
696
 
        <paragraph>
697
 
            Inline substitution_reference start-string without end-string at line 1.
698
 
"""],
699
 
]
700
 
 
701
 
totest['standalone_hyperlink'] = [
702
 
["""\
703
 
http://www.standalone.hyperlink.com
704
 
 
705
 
http:/one-slash-only.absolute.path
706
 
 
707
 
http://[1080:0:0:0:8:800:200C:417A]/IPv6address.html
708
 
 
709
 
http://[3ffe:2a00:100:7031::1]
710
 
 
711
 
mailto:someone@somewhere.com
712
 
 
713
 
news:comp.lang.python
714
 
 
715
 
An email address in a sentence: someone@somewhere.com.
716
 
 
717
 
ftp://ends.with.a.period.
718
 
 
719
 
(a.question.mark@end?)
720
 
""",
721
 
"""\
722
 
<document>
723
 
    <paragraph>
724
 
        <reference refuri="http://www.standalone.hyperlink.com">
725
 
            http://www.standalone.hyperlink.com
726
 
    <paragraph>
727
 
        <reference refuri="http:/one-slash-only.absolute.path">
728
 
            http:/one-slash-only.absolute.path
729
 
    <paragraph>
730
 
        <reference refuri="http://[1080:0:0:0:8:800:200C:417A]/IPv6address.html">
731
 
            http://[1080:0:0:0:8:800:200C:417A]/IPv6address.html
732
 
    <paragraph>
733
 
        <reference refuri="http://[3ffe:2a00:100:7031::1]">
734
 
            http://[3ffe:2a00:100:7031::1]
735
 
    <paragraph>
736
 
        <reference refuri="mailto:someone@somewhere.com">
737
 
            mailto:someone@somewhere.com
738
 
    <paragraph>
739
 
        <reference refuri="news:comp.lang.python">
740
 
            news:comp.lang.python
741
 
    <paragraph>
742
 
        An email address in a sentence: \n\
743
 
        <reference refuri="mailto:someone@somewhere.com">
744
 
            someone@somewhere.com
745
 
        .
746
 
    <paragraph>
747
 
        <reference refuri="ftp://ends.with.a.period">
748
 
            ftp://ends.with.a.period
749
 
        .
750
 
    <paragraph>
751
 
        (
752
 
        <reference refuri="mailto:a.question.mark@end">
753
 
            a.question.mark@end
754
 
        ?)
755
 
"""],
756
 
["""\
757
 
None of these are standalone hyperlinks (their "schemes"
758
 
are not recognized): signal:noise, a:b.
759
 
""",
760
 
"""\
761
 
<document>
762
 
    <paragraph>
763
 
        None of these are standalone hyperlinks (their "schemes"
764
 
        are not recognized): signal:noise, a:b.
765
 
"""],
766
 
]
767
 
 
768
 
totest['miscellaneous'] = [
769
 
["""\
770
 
__This__ should be left alone.
771
 
""",
772
 
"""\
773
 
<document>
774
 
    <paragraph>
775
 
        __This__ should be left alone.
776
 
"""],
777
 
]
778
 
 
779
 
 
780
 
if __name__ == '__main__':
781
 
    import unittest
782
 
    unittest.main(defaultTest='suite')