Fix [ 313 ] differentiate apostrophe from single quote (if possible).
[docutils.git] / docutils / test / test_transforms / test_smartquotes.py
blob309a6a9876b4a2066545c131a7d239c15a7bf089
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", 'secondary 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”, ‘secondary smart quotes’,
52 “‘nested’ smart” quotes
53 – and —also long— dashes.
54 """],
55 [r"""Escaped \\"smart quotes\\", \\'secondary smart quotes\\',
56 \\"\\'nested\\' smart\\" quotes
57 \\-- and -\\--also long-\\-- dashes.
58 """,
59 u"""\
60 <document source="test data">
61 <paragraph>
62 Escaped "smart quotes", 'secondary smart quotes',
63 "'nested' smart" quotes
64 -- and ---also long--- dashes.
65 """],
66 ["""\
67 Do not "educate" quotes ``inside "literal" text`` and ::
69 "literal" blocks.
71 Keep quotes straight in code and math:
72 :code:`print "hello"` :math:`1' 12"`.
74 .. code::
76 print "hello"
78 .. math::
80 f'(x) = df(x)/dx
82 """,
83 u"""\
84 <document source="test data">
85 <paragraph>
86 Do not “educate” quotes
87 <literal>
88 inside "literal" text
89 and
90 <literal_block xml:space="preserve">
91 "literal" blocks.
92 <paragraph>
93 Keep quotes straight in code and math:
94 <literal classes="code">
95 print "hello"
97 <math>
98 1' 12"
100 <literal_block classes="code" xml:space="preserve">
101 print "hello"
102 <math_block xml:space="preserve">
103 f'(x) = df(x)/dx
104 """],
105 ["""\
106 Quotes and inline-elements:
108 * Around "_`targets`", "*emphasized*" or "``literal``" text
109 and links to "targets_".
111 * Inside *"emphasized"* or other `inline "roles"`
113 Do not drop characters from intra-word inline markup like
114 *re*\ ``Structured``\ *Text*.
115 """,
116 u"""\
117 <document source="test data">
118 <paragraph>
119 Quotes and inline-elements:
120 <bullet_list bullet="*">
121 <list_item>
122 <paragraph>
123 Around “
124 <target ids="targets" names="targets">
125 targets
126 ”, “
127 <emphasis>
128 emphasized
129 ” or “
130 <literal>
131 literal
132 ” text
133 and links to “
134 <reference name="targets" refname="targets">
135 targets
136 ”.
137 <list_item>
138 <paragraph>
139 Inside \n\
140 <emphasis>
141 “emphasized”
142 or other \n\
143 <title_reference>
144 inline “roles”
145 <paragraph>
146 Do not drop characters from intra-word inline markup like
147 <emphasis>
149 <literal>
150 Structured
151 <emphasis>
152 Text
154 """],
155 ["""\
156 .. class:: language-de
158 German "smart quotes" and 'secondary smart quotes'.
160 .. class:: language-en-UK
162 British "quotes" use single and 'secondary quotes' double quote signs.
164 .. class:: language-foo
166 "Quoting style" for unknown languages is 'ASCII'.
168 .. class:: language-de-x-altquot
170 Alternative German "smart quotes" and 'secondary smart quotes'.
171 """,
172 u"""\
173 <document source="test data">
174 <paragraph classes="language-de">
175 German „smart quotes“ and ‚secondary smart quotes‘.
176 <paragraph classes="language-en-uk">
177 British ‘quotes’ use single and “secondary quotes” double quote signs.
178 <paragraph classes="language-foo">
179 "Quoting style" for unknown languages is 'ASCII'.
180 <paragraph classes="language-de-x-altquot">
181 Alternative German »smart quotes« and ›secondary smart quotes‹.
182 <system_message level="2" line="11" source="test data" type="WARNING">
183 <paragraph>
184 No smart quotes defined for language "foo".
185 """],
188 totest_de['transitions'] = ((SmartQuotes,), [
189 ["""\
190 German "smart quotes" and 'secondary smart quotes'.
192 .. class:: language-en
194 English "smart quotes" and 'secondary smart quotes'.
195 """,
196 u"""\
197 <document source="test data">
198 <paragraph>
199 German „smart quotes“ and ‚secondary smart quotes‘.
200 <paragraph classes="language-en">
201 English “smart quotes” and ‘secondary smart quotes’.
202 """],
205 totest_de_alt['transitions'] = ((SmartQuotes,), [
206 ["""\
207 Alternative German "smart quotes" and 'secondary smart quotes'.
209 In this case, the apostrophe isn't a closing secondary quote!
211 .. class:: language-en-UK
213 British "quotes" use single and 'secondary quotes' double quote signs
214 (there are no alternative quotes defined).
216 .. class:: language-ro
218 Romanian "smart quotes" and 'secondary' smart quotes.
219 """,
220 u"""\
221 <document source="test data">
222 <paragraph>
223 Alternative German »smart quotes« and ›secondary smart quotes‹.
224 <paragraph>
225 In this case, the apostrophe isn’t a closing secondary quote!
226 <paragraph classes="language-en-uk">
227 British ‘quotes’ use single and “secondary quotes” double quote signs
228 (there are no alternative quotes defined).
229 <paragraph classes="language-ro">
230 Romanian „smart quotes” and «secondary» smart quotes.
231 """],
234 if __name__ == '__main__':
235 import unittest
236 unittest.main(defaultTest='suite')