Spelling fixes
[docutils.git] / test / test_parsers / test_rst / test_directives / test_unicode.py
blobd6205ca675e57b9fe417b41c17ada53fccc7c42a
1 #! /usr/bin/env python
3 # $Id$
4 # Author: David Goodger <goodger@python.org>
5 # Copyright: This module has been placed in the public domain.
7 """
8 Tests for misc.py "unicode" directive.
9 """
11 from __init__ import DocutilsTestSupport
14 def suite():
15 s = DocutilsTestSupport.ParserTestSuite()
16 s.generateTests(totest)
17 return s
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
23 else:
24 unichr_exception_string = str(unichr_exception)
26 totest = {}
28 totest['unicode'] = [
29 ["""
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:: &#x000A0;
36 .. |bne| unicode:: U0003D U020E5
37 .. |Omega| unicode:: U+003A9
38 """,
39 u"""\
40 <document source="test data">
41 <paragraph>
42 Insert an em-dash (
43 <substitution_reference refname="mdash">
44 mdash
45 ), a copyright symbol (
46 <substitution_reference refname="copy">
47 copy
48 ), a non-breaking
49 space (
50 <substitution_reference refname="nbsp">
51 nbsp
52 ), a backwards-not-equals (
53 <substitution_reference refname="bne">
54 bne
55 ), and a capital omega (
56 <substitution_reference refname="Omega">
57 Omega
59 <substitution_definition names="mdash">
60 \u2014
61 <substitution_definition names="copy">
62 \u00A9
63 <substitution_definition names="nbsp">
64 \u00A0
65 <substitution_definition names="bne">
67 \u20e5
68 <substitution_definition names="Omega">
69 \u03a9
70 """],
71 ["""
72 Bad input:
74 .. |empty| unicode::
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
79 """,
80 """\
81 <document source="test data">
82 <paragraph>
83 Bad input:
84 <system_message level="3" line="4" source="test data" type="ERROR">
85 <paragraph>
86 Error in "unicode" directive:
87 1 argument(s) required, 0 supplied.
88 <literal_block xml:space="preserve">
89 unicode::
90 <system_message level="2" line="4" source="test data" type="WARNING">
91 <paragraph>
92 Substitution definition "empty" empty or invalid.
93 <literal_block xml:space="preserve">
94 .. |empty| unicode::
95 <system_message level="2" line="5" source="test data" type="WARNING">
96 <paragraph>
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">
101 0xHEX
102 <substitution_definition names="not\ all\ hex">
103 UABCX
104 <system_message level="3" line="8" source="test data" type="ERROR">
105 <paragraph>
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
109 """],
110 ["""
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
118 """,
119 u"""\
120 <document source="test data">
121 <paragraph>
122 Testing comments and extra text.
123 <paragraph>
124 Copyright
125 <substitution_reference refname="copy">
126 copy
127 2003,
128 <substitution_reference refname="BogusMegaCorp (TM)">
129 BogusMegaCorp (TM)
131 <substitution_definition names="copy">
132 \u00A9
133 <substitution_definition names="BogusMegaCorp\ (TM)">
134 BogusMegaCorp
135 \u2122
136 """],
137 ["""
138 .. |too big for int| unicode:: 0x111111111111111111
139 .. |too big for unicode| unicode:: 0x11111111
140 """,
141 """\
142 <document source="test data">
143 <system_message level="3" line="2" source="test data" type="ERROR">
144 <paragraph>
145 Invalid character code: 0x111111111111111111
146 ValueError: %s
147 <literal_block xml:space="preserve">
148 unicode:: 0x111111111111111111
149 <system_message level="2" line="2" source="test data" type="WARNING">
150 <paragraph>
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">
155 <paragraph>
156 Invalid character code: 0x11111111
158 <literal_block xml:space="preserve">
159 unicode:: 0x11111111
160 <system_message level="2" line="3" source="test data" type="WARNING">
161 <paragraph>
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__':
171 import unittest
172 unittest.main(defaultTest='suite')