~ubuntu-branches/ubuntu/saucy/python-docutils/saucy-proposed

« back to all changes in this revision

Viewing changes to test/test_parsers/test_rst/test_inline_markup.py

  • Committer: Package Import Robot
  • Author(s): Dmitry Shachnev
  • Date: 2012-10-19 18:23:15 UTC
  • mfrom: (1.2.1) (11.1.6 experimental)
  • Revision ID: package-import@ubuntu.com-20121019182315-ln3lvct1pqq7mzgm
Tags: 0.9.1+svn7532-0ubuntu1
* Resynchronize with Debian packaging SVN, remaining change:
  - Use dh_python2 instead of dh_pysupport.
* New snapshot from upstream SVN, fixes build with Python 3.3.
* Add XS-Testsuite header.
* debian/patches/move-data-to-usr-share.diff: unfuzz.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#! /usr/bin/env python
 
2
# -*- coding: utf8 -*-
2
3
 
3
 
# $Id: test_inline_markup.py 5642 2008-09-05 18:18:28Z goodger $
 
4
# $Id$
4
5
# Author: David Goodger <goodger@python.org>
5
6
# Copyright: This module has been placed in the public domain.
6
7
 
29
30
            emphasis
30
31
"""],
31
32
[u"""\
32
 
l'*emphasis* and l\u2019*emphasis* with apostrophe
 
33
l'*emphasis* with the *emphasis*' apostrophe.
 
34
l\u2019*emphasis* with the *emphasis*\u2019 apostrophe.
33
35
""",
34
36
u"""\
35
37
<document source="test data">
36
38
    <paragraph>
37
 
        l'
38
 
        <emphasis>
39
 
            emphasis
40
 
         and l\u2019
41
 
        <emphasis>
42
 
            emphasis
43
 
         with apostrophe
 
39
        l\'
 
40
        <emphasis>
 
41
            emphasis
 
42
         with the \n\
 
43
        <emphasis>
 
44
            emphasis
 
45
        \' apostrophe.
 
46
        l\u2019
 
47
        <emphasis>
 
48
            emphasis
 
49
         with the \n\
 
50
        <emphasis>
 
51
            emphasis
 
52
        \u2019 apostrophe.
44
53
"""],
45
54
["""\
46
55
*emphasized sentence
66
75
        <paragraph>
67
76
            Inline emphasis start-string without end-string.
68
77
"""],
69
 
["""\
70
 
'*emphasis*' and 1/*emphasis*/2 and 3-*emphasis*-4 and 5:*emphasis*:6
71
 
but not '*' or '"*"' or  x*2* or 2*x* or \\*args or *
72
 
or *the\\* *stars\\\\\\* *inside*
73
 
 
74
 
(however, '*args' will trigger a warning and may be problematic)
 
78
[r"""some punctuation is allowed around inline markup, e.g.
 
79
/*emphasis*/, -*emphasis*-, and :*emphasis*: (delimiters),
 
80
(*emphasis*), [*emphasis*], <*emphasis*>, {*emphasis*} (open/close pairs)
 
81
 
 
82
but not
 
83
)*emphasis*(, ]*emphasis*[, >*emphasis*>, }*emphasis*{ (close/open pairs)
 
84
(*), [*], '*' or '"*"' ("quoted" start-string),
 
85
x*2* or 2*x* (alphanumeric char before),
 
86
\*args or * (escaped, whitespace behind start-string)
 
87
or *the\* *stars\* *inside* (escaped, whitespace before end-string).
 
88
 
 
89
However, '*args' will trigger a warning and may be problematic.
75
90
 
76
91
what about *this**?
77
92
""",
78
93
"""\
79
94
<document source="test data">
80
95
    <paragraph>
81
 
        '
82
 
        <emphasis>
83
 
            emphasis
84
 
        ' and 1/
85
 
        <emphasis>
86
 
            emphasis
87
 
        /2 and 3-
88
 
        <emphasis>
89
 
            emphasis
90
 
        -4 and 5:
91
 
        <emphasis>
92
 
            emphasis
93
 
        :6
94
 
        but not '*' or '"*"' or  x*2* or 2*x* or *args or *
 
96
        some punctuation is allowed around inline markup, e.g.
 
97
        /
 
98
        <emphasis>
 
99
            emphasis
 
100
        /, -
 
101
        <emphasis>
 
102
            emphasis
 
103
        -, and :
 
104
        <emphasis>
 
105
            emphasis
 
106
        : (delimiters),
 
107
        (
 
108
        <emphasis>
 
109
            emphasis
 
110
        ), [
 
111
        <emphasis>
 
112
            emphasis
 
113
        ], <
 
114
        <emphasis>
 
115
            emphasis
 
116
        >, {
 
117
        <emphasis>
 
118
            emphasis
 
119
        } (open/close pairs)
 
120
    <paragraph>
 
121
        but not
 
122
        )*emphasis*(, ]*emphasis*[, >*emphasis*>, }*emphasis*{ (close/open pairs)
 
123
        (*), [*], '*' or '"*"' ("quoted" start-string),
 
124
        x*2* or 2*x* (alphanumeric char before),
 
125
        *args or * (escaped, whitespace behind start-string)
95
126
        or \n\
96
127
        <emphasis>
97
 
            the* *stars\* *inside
 
128
            the* *stars* *inside
 
129
         (escaped, whitespace before end-string).
98
130
    <paragraph>
99
 
        (however, '
 
131
        However, '
100
132
        <problematic ids="id2" refid="id1">
101
133
            *
102
 
        args' will trigger a warning and may be problematic)
103
 
    <system_message backrefs="id2" ids="id1" level="2" line="5" source="test data" type="WARNING">
 
134
        args' will trigger a warning and may be problematic.
 
135
    <system_message backrefs="id2" ids="id1" level="2" line="12" source="test data" type="WARNING">
104
136
        <paragraph>
105
137
            Inline emphasis start-string without end-string.
106
138
    <paragraph>
109
141
            this*
110
142
        ?
111
143
"""],
112
 
["""\
113
 
Emphasized asterisk: *\\**
114
 
 
115
 
Emphasized double asterisk: *\\***
 
144
[u"""\
 
145
Quotes around inline markup:
 
146
 
 
147
'*emphasis*' "*emphasis*" Straight,
 
148
‘*emphasis*’ “*emphasis*” English, ...,
 
149
« *emphasis* » ‹ *emphasis* › « *emphasis* » ‹ *emphasis* ›
 
150
« *emphasis* » ‹ *emphasis* › French,
 
151
„*emphasis*“ ‚*emphasis*‘ »*emphasis*« ›*emphasis*‹ German, Czech, ...,
 
152
„*emphasis*” «*emphasis*» Romanian,
 
153
“*emphasis*„ ‘*emphasis*‚ Greek,
 
154
「*emphasis*」 『*emphasis*』traditional Chinese,
 
155
”*emphasis*” ’*emphasis*’ »*emphasis*» ›*emphasis*› Swedish, Finnish,
 
156
„*emphasis*” ‚*emphasis*’ Polish,
 
157
„*emphasis*” »*emphasis*« ’*emphasis*’ Hungarian,
 
158
""",
 
159
u"""\
 
160
<document source="test data">
 
161
    <paragraph>
 
162
        Quotes around inline markup:
 
163
    <paragraph>
 
164
        \'
 
165
        <emphasis>
 
166
            emphasis
 
167
        \' "
 
168
        <emphasis>
 
169
            emphasis
 
170
        " Straight,
 
171
        \u2018
 
172
        <emphasis>
 
173
            emphasis
 
174
        \u2019 \u201c
 
175
        <emphasis>
 
176
            emphasis
 
177
        \u201d English, ...,
 
178
        \xab\u202f
 
179
        <emphasis>
 
180
            emphasis
 
181
        \u202f\xbb \u2039\u202f
 
182
        <emphasis>
 
183
            emphasis
 
184
        \u202f\u203a \xab\xa0
 
185
        <emphasis>
 
186
            emphasis
 
187
        \xa0\xbb \u2039\xa0
 
188
        <emphasis>
 
189
            emphasis
 
190
        \xa0\u203a
 
191
        \xab\u2005
 
192
        <emphasis>
 
193
            emphasis
 
194
        \u2005\xbb \u2039\u2005
 
195
        <emphasis>
 
196
            emphasis
 
197
        \u2005\u203a French,
 
198
        \u201e
 
199
        <emphasis>
 
200
            emphasis
 
201
        \u201c \u201a
 
202
        <emphasis>
 
203
            emphasis
 
204
        \u2018 \xbb
 
205
        <emphasis>
 
206
            emphasis
 
207
        \xab \u203a
 
208
        <emphasis>
 
209
            emphasis
 
210
        \u2039 German, Czech, ...,
 
211
        \u201e
 
212
        <emphasis>
 
213
            emphasis
 
214
        \u201d \xab
 
215
        <emphasis>
 
216
            emphasis
 
217
        \xbb Romanian,
 
218
        \u201c
 
219
        <emphasis>
 
220
            emphasis
 
221
        \u201e \u2018
 
222
        <emphasis>
 
223
            emphasis
 
224
        \u201a Greek,
 
225
        \u300c
 
226
        <emphasis>
 
227
            emphasis
 
228
        \u300d \u300e
 
229
        <emphasis>
 
230
            emphasis
 
231
        \u300ftraditional Chinese,
 
232
        \u201d
 
233
        <emphasis>
 
234
            emphasis
 
235
        \u201d \u2019
 
236
        <emphasis>
 
237
            emphasis
 
238
        \u2019 \xbb
 
239
        <emphasis>
 
240
            emphasis
 
241
        \xbb \u203a
 
242
        <emphasis>
 
243
            emphasis
 
244
        \u203a Swedish, Finnish,
 
245
        \u201e
 
246
        <emphasis>
 
247
            emphasis
 
248
        \u201d \u201a
 
249
        <emphasis>
 
250
            emphasis
 
251
        \u2019 Polish,
 
252
        \u201e
 
253
        <emphasis>
 
254
            emphasis
 
255
        \u201d \xbb
 
256
        <emphasis>
 
257
            emphasis
 
258
        \xab \u2019
 
259
        <emphasis>
 
260
            emphasis
 
261
        \u2019 Hungarian,
 
262
"""],
 
263
[r"""
 
264
Emphasized asterisk: *\**
 
265
 
 
266
Emphasized double asterisk: *\***
116
267
""",
117
268
"""\
118
269
<document source="test data">
178
329
            strong
179
330
        \xbb
180
331
"""],
181
 
["""\
182
 
(**strong**) but not (**) or '(** ' or x**2 or \\**kwargs or **
 
332
[r"""
 
333
(**strong**) but not (**) or '(** ' or x**2 or \**kwargs or **
183
334
 
184
335
(however, '**kwargs' will trigger a warning and may be problematic)
185
336
""",
195
346
        <problematic ids="id2" refid="id1">
196
347
            **
197
348
        kwargs' will trigger a warning and may be problematic)
198
 
    <system_message backrefs="id2" ids="id1" level="2" line="3" source="test data" type="WARNING">
 
349
    <system_message backrefs="id2" ids="id1" level="2" line="4" source="test data" type="WARNING">
199
350
        <paragraph>
200
351
            Inline strong start-string without end-string.
201
352
"""],
240
391
        <literal>
241
392
            literal
242
393
"""],
243
 
["""\
244
 
``\\literal``
 
394
[r"""
 
395
``\literal``
245
396
""",
246
397
"""\
247
398
<document source="test data">
249
400
        <literal>
250
401
            \\literal
251
402
"""],
252
 
["""\
253
 
``lite\\ral``
 
403
[r"""
 
404
``lite\ral``
254
405
""",
255
406
"""\
256
407
<document source="test data">
258
409
        <literal>
259
410
            lite\\ral
260
411
"""],
261
 
["""\
262
 
``literal\\``
 
412
[r"""
 
413
``literal\``
263
414
""",
264
415
"""\
265
416
<document source="test data">
318
469
    <paragraph>
319
470
        <literal>
320
471
            'literal'
321
 
         with quotes, 
 
472
         with quotes, \n\
322
473
        <literal>
323
474
            "literal"
324
475
         with quotes,
325
476
        <literal>
326
477
            \u2018literal\u2019
327
 
         with quotes, 
 
478
         with quotes, \n\
328
479
        <literal>
329
480
            \u201cliteral\u201d
330
481
         with quotes,
332
483
            \xabliteral\xbb
333
484
         with quotes
334
485
"""],
335
 
["""\
336
 
``literal ``TeX quotes'' & \\backslash`` but not "``" or ``
 
486
[r"""
 
487
``literal ``TeX quotes'' & \backslash`` but not "``" or ``
337
488
 
338
489
(however, ``standalone TeX quotes'' will trigger a warning
339
490
and may be problematic)
350
501
            ``
351
502
        standalone TeX quotes'' will trigger a warning
352
503
        and may be problematic)
353
 
    <system_message backrefs="id2" ids="id1" level="2" line="3" source="test data" type="WARNING">
 
504
    <system_message backrefs="id2" ids="id1" level="2" line="4" source="test data" type="WARNING">
354
505
        <paragraph>
355
506
            Inline literal start-string without end-string.
356
507
"""],
378
529
        <paragraph>
379
530
            Inline literal start-string without end-string.
380
531
"""],
381
 
["""\
382
 
Python ``list``\\s use square bracket syntax.
 
532
[r"""
 
533
Python ``list``\s use square bracket syntax.
383
534
""",
384
535
"""\
385
536
<document source="test data">
590
741
    <paragraph>
591
742
        <reference name="'phrase reference'" refname="'phrase reference'">
592
743
            'phrase reference'
593
 
         with quotes, 
 
744
         with quotes, \n\
594
745
        <reference name=""phrase reference"" refname=""phrase reference"">
595
746
            "phrase reference"
596
747
         with quotes,
667
818
    <paragraph>
668
819
        <reference anonymous="1" name="'anonymous reference'">
669
820
            'anonymous reference'
670
 
         with quotes, 
 
821
         with quotes, \n\
671
822
        <reference anonymous="1" name=""anonymous reference"">
672
823
            "anonymous reference"
673
824
         with quotes,
832
983
        <reference name="embedded email address broken across lines" refuri="mailto:jdoe@example.com">
833
984
            embedded email address broken across lines
834
985
"""],
835
 
["""\
 
986
[r"""
836
987
`embedded URI with too much whitespace < http://example.com/
837
988
long/path /and  /whitespace >`__
838
989
 
841
992
 
842
993
`embedded URI with no preceding whitespace<http://example.com>`__
843
994
 
844
 
`escaped URI \\<http://example.com>`__
 
995
`escaped URI \<http://example.com>`__
845
996
 
846
 
See `HTML Anchors: \\<a>`_.
 
997
See `HTML Anchors: \<a>`_.
847
998
""",
848
999
"""\
849
1000
<document source="test data">
967
1118
    <paragraph>
968
1119
        <target ids="target1" names="'target1'">
969
1120
            'target1'
970
 
         with quotes, 
 
1121
         with quotes, \n\
971
1122
        <target ids="target2" names=""target2"">
972
1123
            "target2"
973
1124
         with quotes,
974
1125
        <target ids="target3" names="\u2018target3\u2019">
975
1126
            \u2018target3\u2019
976
 
         with quotes, 
 
1127
         with quotes, \n\
977
1128
        <target ids="target4" names="\u201ctarget4\u201d">
978
1129
            \u201ctarget4\u201d
979
1130
         with quotes,
1246
1397
            a.question.mark@end
1247
1398
        ?)
1248
1399
"""],
1249
 
["""\
 
1400
[r"""
1250
1401
Valid URLs with escaped markup characters:
1251
1402
 
1252
 
http://example.com/\\*content\\*/whatever
 
1403
http://example.com/\*content\*/whatever
1253
1404
 
1254
 
http://example.com/\\*content*/whatever
 
1405
http://example.com/\*content*/whatever
1255
1406
""",
1256
1407
"""\
1257
1408
<document source="test data">
1312
1463
"""],
1313
1464
]
1314
1465
 
1315
 
totest['miscellaneous'] = [
 
1466
totest['markup recognition rules'] = [
1316
1467
["""\
1317
1468
__This__ should be left alone.
1318
1469
""",
1342
1493
        with backslash-escaped whitespace, including newlines.
1343
1494
"""],
1344
1495
[u"""\
1345
 
quoted '*emphasis*', quoted "*emphasis*",
1346
 
quoted \u2018*emphasis*\u2019, quoted \u201c*emphasis*\u201d,
1347
 
quoted \xab*emphasis*\xbb
1348
 
""",
1349
 
u"""\
1350
 
<document source="test data">
1351
 
    <paragraph>
1352
 
        quoted '
1353
 
        <emphasis>
1354
 
            emphasis
1355
 
        ', quoted "
1356
 
        <emphasis>
1357
 
            emphasis
1358
 
        ",
1359
 
        quoted \u2018
1360
 
        <emphasis>
1361
 
            emphasis
1362
 
        \u2019, quoted \u201c
1363
 
        <emphasis>
1364
 
            emphasis
1365
 
        \u201d,
1366
 
        quoted \xab
1367
 
        <emphasis>
1368
 
            emphasis
1369
 
        \xbb
1370
 
"""],
1371
 
[u"""\
1372
1496
text-*separated*\u2010*by*\u2011*various*\u2012*dashes*\u2013*and*\u2014*hyphens*.
1373
 
\u00bf*punctuation*? \u00a1*examples*!\u00a0*too*.
 
1497
\u00bf*punctuation*? \u00a1*examples*!\u00a0*\u00a0no-break-space\u00a0*.
1374
1498
""",
1375
1499
u"""\
1376
1500
<document source="test data">
1402
1526
            examples
1403
1527
        !\xa0
1404
1528
        <emphasis>
1405
 
            too
1406
 
        .
1407
 
"""],
1408
 
[u"""\
1409
 
None of these should be markup (matched openers & closers):
1410
 
 
1411
 
\u2018*\u2019 \u201c*\u201d \xab*\xbb \u00bf*? \u00a1*!
1412
 
 
1413
 
But this should:
1414
 
 
1415
 
l\u2019*exception*.
1416
 
""",
1417
 
u"""\
1418
 
<document source="test data">
1419
 
    <paragraph>
1420
 
        None of these should be markup (matched openers & closers):
1421
 
    <paragraph>
1422
 
        \u2018*\u2019 \u201c*\u201d \xab*\xbb \xbf*? \xa1*!
1423
 
    <paragraph>
1424
 
        But this should:
1425
 
    <paragraph>
1426
 
        l\u2019
1427
 
        <emphasis>
1428
 
            exception
1429
 
        .
 
1529
            \u00a0no-break-space\u00a0
 
1530
        .
 
1531
"""],
 
1532
# Whitespace characters:
 
1533
#  \u180e*MONGOLIAN VOWEL SEPARATOR*\u180e,   fails in Python 2.4
 
1534
[u"""\
 
1535
text separated by
 
1536
*newline*
 
1537
or *space* or one of
 
1538
\xa0*NO-BREAK SPACE*\xa0,
 
1539
\u1680*OGHAM SPACE MARK*\u1680,
 
1540
\u2000*EN QUAD*\u2000,
 
1541
\u2001*EM QUAD*\u2001,
 
1542
\u2002*EN SPACE*\u2002,
 
1543
\u2003*EM SPACE*\u2003,
 
1544
\u2004*THREE-PER-EM SPACE*\u2004,
 
1545
\u2005*FOUR-PER-EM SPACE*\u2005,
 
1546
\u2006*SIX-PER-EM SPACE*\u2006,
 
1547
\u2007*FIGURE SPACE*\u2007,
 
1548
\u2008*PUNCTUATION SPACE*\u2008,
 
1549
\u2009*THIN SPACE*\u2009,
 
1550
\u200a*HAIR SPACE*\u200a,
 
1551
\u202f*NARROW NO-BREAK SPACE*\u202f,
 
1552
\u205f*MEDIUM MATHEMATICAL SPACE*\u205f,
 
1553
\u3000*IDEOGRAPHIC SPACE*\u3000,
 
1554
\u2028*LINE SEPARATOR*\u2028
 
1555
""",
 
1556
u"""\
 
1557
<document source="test data">
 
1558
    <paragraph>
 
1559
        text separated by
 
1560
        <emphasis>
 
1561
            newline
 
1562
        \n\
 
1563
        or \n\
 
1564
        <emphasis>
 
1565
            space
 
1566
         or one of
 
1567
        \xa0
 
1568
        <emphasis>
 
1569
            NO-BREAK SPACE
 
1570
        \xa0,
 
1571
        \u1680
 
1572
        <emphasis>
 
1573
            OGHAM SPACE MARK
 
1574
        \u1680,
 
1575
        \u2000
 
1576
        <emphasis>
 
1577
            EN QUAD
 
1578
        \u2000,
 
1579
        \u2001
 
1580
        <emphasis>
 
1581
            EM QUAD
 
1582
        \u2001,
 
1583
        \u2002
 
1584
        <emphasis>
 
1585
            EN SPACE
 
1586
        \u2002,
 
1587
        \u2003
 
1588
        <emphasis>
 
1589
            EM SPACE
 
1590
        \u2003,
 
1591
        \u2004
 
1592
        <emphasis>
 
1593
            THREE-PER-EM SPACE
 
1594
        \u2004,
 
1595
        \u2005
 
1596
        <emphasis>
 
1597
            FOUR-PER-EM SPACE
 
1598
        \u2005,
 
1599
        \u2006
 
1600
        <emphasis>
 
1601
            SIX-PER-EM SPACE
 
1602
        \u2006,
 
1603
        \u2007
 
1604
        <emphasis>
 
1605
            FIGURE SPACE
 
1606
        \u2007,
 
1607
        \u2008
 
1608
        <emphasis>
 
1609
            PUNCTUATION SPACE
 
1610
        \u2008,
 
1611
        \u2009
 
1612
        <emphasis>
 
1613
            THIN SPACE
 
1614
        \u2009,
 
1615
        \u200a
 
1616
        <emphasis>
 
1617
            HAIR SPACE
 
1618
        \u200a,
 
1619
        \u202f
 
1620
        <emphasis>
 
1621
            NARROW NO-BREAK SPACE
 
1622
        \u202f,
 
1623
        \u205f
 
1624
        <emphasis>
 
1625
            MEDIUM MATHEMATICAL SPACE
 
1626
        \u205f,
 
1627
        \u3000
 
1628
        <emphasis>
 
1629
            IDEOGRAPHIC SPACE
 
1630
        \u3000,
 
1631
    <paragraph>
 
1632
        <emphasis>
 
1633
            LINE SEPARATOR
 
1634
"""],
 
1635
# « * » ‹ * › « * » ‹ * › « * » ‹ * › French,
 
1636
[u"""\
 
1637
"Quoted" markup start-string (matched openers & closers) -> no markup:
 
1638
 
 
1639
'*' "*" (*) <*> [*] {*}
 
1640
⁅*⁆
 
1641
 
 
1642
Some international quoting styles:
 
1643
‘*’ “*” English, ...,
 
1644
„*“ ‚*‘ »*« ›*‹ German, Czech, ...,
 
1645
„*” «*» Romanian,
 
1646
“*„ ‘*‚ Greek,
 
1647
「*」 『*』traditional Chinese,
 
1648
”*” ’*’ »*» ›*› Swedish, Finnish,
 
1649
„*” ‚*’ Polish,
 
1650
„*” »*« ’*’ Hungarian,
 
1651
 
 
1652
But this is „*’ emphasized »*‹.
 
1653
""",
 
1654
u"""\
 
1655
<document source="test data">
 
1656
    <paragraph>
 
1657
        "Quoted" markup start-string (matched openers & closers) -> no markup:
 
1658
    <paragraph>
 
1659
        '*' "*" (*) <*> [*] {*}
 
1660
        ⁅*⁆
 
1661
    <paragraph>
 
1662
        Some international quoting styles:
 
1663
        ‘*’ “*” English, ...,
 
1664
        „*“ ‚*‘ »*« ›*‹ German, Czech, ...,
 
1665
        „*” «*» Romanian,
 
1666
        “*„ ‘*‚ Greek,
 
1667
        「*」 『*』traditional Chinese,
 
1668
        ”*” ’*’ »*» ›*› Swedish, Finnish,
 
1669
        „*” ‚*’ Polish,
 
1670
        „*” »*« ’*’ Hungarian,
 
1671
    <paragraph>
 
1672
        But this is „
 
1673
        <emphasis>
 
1674
            ’ emphasized »
 
1675
        ‹.
1430
1676
"""],
1431
1677
]
1432
1678