Consistently use "utf-8" (not "utf8") in magic comment giving source encoding.
[docutils.git] / test / test_transforms / test_smartquotes.py
blob26388e92976fdfcddb0c3808e620f8f758f92674
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # $Id$
5 # :Copyright: © 2011 Günter Milde.
6 # :Maintainer: docutils-develop@lists.sourceforge.net
7 # :License: Released under the terms of the `2-Clause BSD license`_, in short:
9 # Copying and distribution of this file, with or without modification,
10 # are permitted in any medium without royalty provided the copyright
11 # notice and this notice are preserved.
12 # This file is offered as-is, without any warranty.
14 # .. _2-Clause BSD license: http://www.spdx.org/licenses/BSD-2-Clause
16 """
17 Test module for universal.SmartQuotes transform.
18 """
21 from __init__ import DocutilsTestSupport # must be imported before docutils
22 from docutils.transforms.universal import SmartQuotes
23 from docutils.parsers.rst import Parser
25 def suite():
26 parser = Parser()
27 settings = {'smart_quotes': True}
28 s = DocutilsTestSupport.TransformTestSuite(
29 parser, suite_settings=settings)
30 s.generateTests(totest)
31 settings['language_code'] = 'de'
32 s.generateTests(totest_de)
33 settings['smart_quotes'] = 'alternative'
34 s.generateTests(totest_de_alt)
35 return s
38 totest = {}
39 totest_de = {}
40 totest_de_alt = {}
42 totest['transitions'] = ((SmartQuotes,), [
43 ["""\
44 Test "smart quotes", 'single smart quotes',
45 "'nested' smart" quotes
46 -- and ---also long--- dashes.
47 """,
48 u"""\
49 <document source="test data">
50 <paragraph>
51 Test “smart quotes”, ‘single smart quotes’,
52 “‘nested’ smart” quotes
53 – and —also long— dashes.
54 """],
55 ["""\
56 Do not "educate" quotes ``inside "literal" text`` and ::
58 "literal" blocks.
60 Keep quotes straight in code and math:
61 :code:`print "hello"` :math:`1' 12"`.
63 .. code::
65 print "hello"
67 .. math::
69 f'(x) = df(x)/dx
71 """,
72 u"""\
73 <document source="test data">
74 <paragraph>
75 Do not “educate” quotes
76 <literal>
77 inside "literal" text
78 and
79 <literal_block xml:space="preserve">
80 "literal" blocks.
81 <paragraph>
82 Keep quotes straight in code and math:
83 <literal classes="code">
84 print "hello"
86 <math>
87 1' 12"
89 <literal_block classes="code" xml:space="preserve">
90 print "hello"
91 <math_block xml:space="preserve">
92 f'(x) = df(x)/dx
93 """],
94 ["""\
95 Quotes and inline-elements:
97 * Around "_`targets`", "*emphasized*" or "``literal``" text
98 and links to "targets_".
100 * Inside *"emphasized"* or other `inline "roles"`
102 Do not drop characters from intra-word inline markup like
103 *re*\ ``Structured``\ *Text*.
104 """,
105 u"""\
106 <document source="test data">
107 <paragraph>
108 Quotes and inline-elements:
109 <bullet_list bullet="*">
110 <list_item>
111 <paragraph>
112 Around “
113 <target ids="targets" names="targets">
114 targets
115 ”, “
116 <emphasis>
117 emphasized
118 ” or “
119 <literal>
120 literal
121 ” text
122 and links to “
123 <reference name="targets" refname="targets">
124 targets
125 ”.
126 <list_item>
127 <paragraph>
128 Inside \n\
129 <emphasis>
130 “emphasized”
131 or other \n\
132 <title_reference>
133 inline “roles”
134 <paragraph>
135 Do not drop characters from intra-word inline markup like
136 <emphasis>
138 <literal>
139 Structured
140 <emphasis>
141 Text
143 """],
144 ["""\
145 .. class:: language-de
147 German "smart quotes" and 'single smart quotes'.
149 .. class:: language-foo
151 "Quoting style" for unknown languages is 'ASCII'.
153 .. class:: language-de-x-altquot
155 Alternative German "smart quotes" and 'single smart quotes'.
156 """,
157 u"""\
158 <document source="test data">
159 <paragraph classes="language-de">
160 German „smart quotes“ and ‚single smart quotes‘.
161 <paragraph classes="language-foo">
162 "Quoting style" for unknown languages is 'ASCII'.
163 <paragraph classes="language-de-x-altquot">
164 Alternative German »smart quotes« and ›single smart quotes‹.
165 <system_message level="2" line="7" source="test data" type="WARNING">
166 <paragraph>
167 No smart quotes defined for language "foo".
168 """],
171 totest_de['transitions'] = ((SmartQuotes,), [
172 ["""\
173 German "smart quotes" and 'single smart quotes'.
175 .. class:: language-en-UK
177 English "smart quotes" and 'single smart quotes'.
178 """,
179 u"""\
180 <document source="test data">
181 <paragraph>
182 German „smart quotes“ and ‚single smart quotes‘.
183 <paragraph classes="language-en-uk">
184 English “smart quotes” and ‘single smart quotes’.
185 """],
188 totest_de_alt['transitions'] = ((SmartQuotes,), [
189 ["""\
190 Alternative German "smart quotes" and 'single smart quotes'.
192 .. class:: language-en-UK
194 English "smart quotes" and 'single smart quotes' have no alternative.
196 .. class:: language-ro
198 Alternative Romanian "smart quotes" and 'single' smart quotes.
199 """,
200 u"""\
201 <document source="test data">
202 <paragraph>
203 Alternative German »smart quotes« and ›single smart quotes‹.
204 <paragraph classes="language-en-uk">
205 English “smart quotes” and ‘single smart quotes’ have no alternative.
206 <paragraph classes="language-ro">
207 Alternative Romanian «smart quotes» and „single” smart quotes.
208 """],
211 if __name__ == '__main__':
212 import unittest
213 unittest.main(defaultTest='suite')