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.
10 from __future__
import absolute_import
14 from . import DocutilsTestSupport
17 if sys
.version_info
>= (3, 0):
22 s
= DocutilsTestSupport
.ParserTestSuite()
23 s
.generateTests(totest
)
26 unichr_exception
= DocutilsTestSupport
.exception_data(
27 unichr, int("111111111111111111", 16))[0]
28 if isinstance(unichr_exception
, OverflowError):
29 unichr_exception_string
= 'code too large (%s)' % unichr_exception
31 unichr_exception_string
= str(unichr_exception
)
37 Insert an em-dash (|mdash|), a copyright symbol (|copy|), a non-breaking
38 space (|nbsp|), a backwards-not-equals (|bne|), and a captial omega (|Omega|).
40 .. |mdash| unicode:: 0x02014
41 .. |copy| unicode:: \\u00A9
42 .. |nbsp| unicode::  
43 .. |bne| unicode:: U0003D U020E5
44 .. |Omega| unicode:: U+003A9
47 <document source="test data">
50 <substitution_reference refname="mdash">
52 ), a copyright symbol (
53 <substitution_reference refname="copy">
57 <substitution_reference refname="nbsp">
59 ), a backwards-not-equals (
60 <substitution_reference refname="bne">
62 ), and a captial omega (
63 <substitution_reference refname="Omega">
66 <substitution_definition names="mdash">
68 <substitution_definition names="copy">
70 <substitution_definition names="nbsp">
72 <substitution_definition names="bne">
75 <substitution_definition names="Omega">
82 .. |empty too| unicode:: .. comment doesn't count as content
83 .. |not hex| unicode:: 0xHEX
84 .. |not all hex| unicode:: UABCX
85 .. unicode:: not in a substitution definition
88 <document source="test data">
91 <system_message level="3" line="4" source="test data" type="ERROR">
93 Error in "unicode" directive:
94 1 argument(s) required, 0 supplied.
95 <literal_block xml:space="preserve">
97 <system_message level="2" line="4" source="test data" type="WARNING">
99 Substitution definition "empty" empty or invalid.
100 <literal_block xml:space="preserve">
102 <system_message level="2" line="5" source="test data" type="WARNING">
104 Substitution definition "empty too" empty or invalid.
105 <literal_block xml:space="preserve">
106 .. |empty too| unicode:: .. comment doesn't count as content
107 <substitution_definition names="not\\ hex">
109 <substitution_definition names="not\\ all\\ hex">
111 <system_message level="3" line="8" source="test data" type="ERROR">
113 Invalid context: the "unicode" directive can only be used within a substitution definition.
114 <literal_block xml:space="preserve">
115 .. unicode:: not in a substitution definition
118 Testing comments and extra text.
120 Copyright |copy| 2003, |BogusMegaCorp (TM)|.
122 .. |copy| unicode:: 0xA9 .. copyright sign
123 .. |BogusMegaCorp (TM)| unicode:: BogusMegaCorp U+2122
124 .. with trademark sign
127 <document source="test data">
129 Testing comments and extra text.
132 <substitution_reference refname="copy">
135 <substitution_reference refname="BogusMegaCorp (TM)">
138 <substitution_definition names="copy">
140 <substitution_definition names="BogusMegaCorp\\ (TM)">
145 .. |too big for int| unicode:: 0x111111111111111111
146 .. |too big for unicode| unicode:: 0x11111111
149 <document source="test data">
150 <system_message level="3" line="2" source="test data" type="ERROR">
152 Invalid character code: 0x111111111111111111
154 <literal_block xml:space="preserve">
155 unicode:: 0x111111111111111111
156 <system_message level="2" line="2" source="test data" type="WARNING">
158 Substitution definition "too big for int" empty or invalid.
159 <literal_block xml:space="preserve">
160 .. |too big for int| unicode:: 0x111111111111111111
161 <system_message level="3" line="3" source="test data" type="ERROR">
163 Invalid character code: 0x11111111
165 <literal_block xml:space="preserve">
167 <system_message level="2" line="3" source="test data" type="WARNING">
169 Substitution definition "too big for unicode" empty or invalid.
170 <literal_block xml:space="preserve">
171 .. |too big for unicode| unicode:: 0x11111111
172 """ % (unichr_exception_string
,
173 DocutilsTestSupport
.exception_data(unichr, int("11111111", 16))[2])]
177 if __name__
== '__main__':
179 unittest
.main(defaultTest
='suite')