4 # Author: David Goodger <goodger@python.org>
5 # Copyright: This module has been placed in the public domain.
8 Tests for misc.py "unicode" directive.
11 from __init__
import DocutilsTestSupport
15 s
= DocutilsTestSupport
.ParserTestSuite()
16 s
.generateTests(totest
)
19 unichr_exception
= DocutilsTestSupport
.exception_data(
20 unichr, int("111111111111111111", 16))[0]
21 if isinstance(unichr_exception
, OverflowError):
22 unichr_exception_string
= 'code too large (%s)' % unichr_exception
24 unichr_exception_string
= str(unichr_exception
)
30 Insert an em-dash (|mdash|), a copyright symbol (|copy|), a non-breaking
31 space (|nbsp|), a backwards-not-equals (|bne|), and a capital omega (|Omega|).
33 .. |mdash| unicode:: 0x02014
34 .. |copy| unicode:: \\u00A9
35 .. |nbsp| unicode::  
36 .. |bne| unicode:: U0003D U020E5
37 .. |Omega| unicode:: U+003A9
40 <document source="test data">
43 <substitution_reference refname="mdash">
45 ), a copyright symbol (
46 <substitution_reference refname="copy">
50 <substitution_reference refname="nbsp">
52 ), a backwards-not-equals (
53 <substitution_reference refname="bne">
55 ), and a capital omega (
56 <substitution_reference refname="Omega">
59 <substitution_definition names="mdash">
61 <substitution_definition names="copy">
63 <substitution_definition names="nbsp">
65 <substitution_definition names="bne">
68 <substitution_definition names="Omega">
75 .. |empty too| unicode:: .. comment doesn't count as content
76 .. |not hex| unicode:: 0xHEX
77 .. |not all hex| unicode:: UABCX
78 .. unicode:: not in a substitution definition
81 <document source="test data">
84 <system_message level="3" line="4" source="test data" type="ERROR">
86 Error in "unicode" directive:
87 1 argument(s) required, 0 supplied.
88 <literal_block xml:space="preserve">
90 <system_message level="2" line="4" source="test data" type="WARNING">
92 Substitution definition "empty" empty or invalid.
93 <literal_block xml:space="preserve">
95 <system_message level="2" line="5" source="test data" type="WARNING">
97 Substitution definition "empty too" empty or invalid.
98 <literal_block xml:space="preserve">
99 .. |empty too| unicode:: .. comment doesn't count as content
100 <substitution_definition names="not\ hex">
102 <substitution_definition names="not\ all\ hex">
104 <system_message level="3" line="8" source="test data" type="ERROR">
106 Invalid context: the "unicode" directive can only be used within a substitution definition.
107 <literal_block xml:space="preserve">
108 .. unicode:: not in a substitution definition
111 Testing comments and extra text.
113 Copyright |copy| 2003, |BogusMegaCorp (TM)|.
115 .. |copy| unicode:: 0xA9 .. copyright sign
116 .. |BogusMegaCorp (TM)| unicode:: BogusMegaCorp U+2122
117 .. with trademark sign
120 <document source="test data">
122 Testing comments and extra text.
125 <substitution_reference refname="copy">
128 <substitution_reference refname="BogusMegaCorp (TM)">
131 <substitution_definition names="copy">
133 <substitution_definition names="BogusMegaCorp\ (TM)">
138 .. |too big for int| unicode:: 0x111111111111111111
139 .. |too big for unicode| unicode:: 0x11111111
142 <document source="test data">
143 <system_message level="3" line="2" source="test data" type="ERROR">
145 Invalid character code: 0x111111111111111111
147 <literal_block xml:space="preserve">
148 unicode:: 0x111111111111111111
149 <system_message level="2" line="2" source="test data" type="WARNING">
151 Substitution definition "too big for int" empty or invalid.
152 <literal_block xml:space="preserve">
153 .. |too big for int| unicode:: 0x111111111111111111
154 <system_message level="3" line="3" source="test data" type="ERROR">
156 Invalid character code: 0x11111111
158 <literal_block xml:space="preserve">
160 <system_message level="2" line="3" source="test data" type="WARNING">
162 Substitution definition "too big for unicode" empty or invalid.
163 <literal_block xml:space="preserve">
164 .. |too big for unicode| unicode:: 0x11111111
165 """ % (unichr_exception_string
,
166 DocutilsTestSupport
.exception_data(unichr, int("11111111", 16))[2])]
170 if __name__
== '__main__':
172 unittest
.main(defaultTest
='suite')