Update smartquotes:
[docutils.git] / test / test_transforms / test_smartquotes.py
blob4e5b4e53dffd09b2303f7d0fe6a24595d2a84a58
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-x-altquot
162 British "primary quotes" use single and
163 'secondary quotes' double quote signs.
165 .. class:: language-foo
167 "Quoting style" for unknown languages is 'ASCII'.
169 .. class:: language-de-x-altquot
171 Alternative German "smart quotes" and 'secondary smart quotes'.
172 """,
173 u"""\
174 <document source="test data">
175 <paragraph classes="language-de">
176 German „smart quotes“ and ‚secondary smart quotes‘.
177 <paragraph classes="language-en-uk-x-altquot">
178 British ‘primary quotes’ use single and
179 “secondary quotes” double quote signs.
180 <paragraph classes="language-foo">
181 "Quoting style" for unknown languages is 'ASCII'.
182 <paragraph classes="language-de-x-altquot">
183 Alternative German »smart quotes« and ›secondary smart quotes‹.
184 <system_message level="2" line="12" source="test data" type="WARNING">
185 <paragraph>
186 No smart quotes defined for language "foo".
187 """],
190 totest_de['transitions'] = ((SmartQuotes,), [
191 ["""\
192 German "smart quotes" and 'secondary smart quotes'.
194 .. class:: language-en
196 English "smart quotes" and 'secondary smart quotes'.
197 """,
198 u"""\
199 <document source="test data">
200 <paragraph>
201 German „smart quotes“ and ‚secondary smart quotes‘.
202 <paragraph classes="language-en">
203 English “smart quotes” and ‘secondary smart quotes’.
204 """],
207 totest_de_alt['transitions'] = ((SmartQuotes,), [
208 ["""\
209 Alternative German "smart quotes" and 'secondary smart quotes'.
211 In this case, the apostrophe isn't a closing secondary quote!
213 .. class:: language-en-UK
215 British "quotes" use single and 'secondary quotes' double quote signs
216 (there are no alternative quotes defined).
218 .. class:: language-ro
220 Romanian "smart quotes" and 'secondary' smart quotes.
221 """,
222 u"""\
223 <document source="test data">
224 <paragraph>
225 Alternative German »smart quotes« and ›secondary smart quotes‹.
226 <paragraph>
227 In this case, the apostrophe isn’t a closing secondary quote!
228 <paragraph classes="language-en-uk">
229 British ‘quotes’ use single and “secondary quotes” double quote signs
230 (there are no alternative quotes defined).
231 <paragraph classes="language-ro">
232 Romanian „smart quotes” and «secondary» smart quotes.
233 """],
236 if __name__ == '__main__':
237 import unittest
238 unittest.main(defaultTest='suite')