2 # -*- coding: utf-8 -*-
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
17 Test module for universal.SmartQuotes transform.
21 from __init__
import DocutilsTestSupport
# must be imported before docutils
22 from docutils
.transforms
.universal
import SmartQuotes
23 from docutils
.parsers
.rst
import 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
)
42 totest
['transitions'] = ((SmartQuotes
,), [
44 Test "smart quotes", 'secondary smart quotes',
45 "'nested' smart" quotes
46 -- and ---also long--- dashes.
49 <document source="test data">
51 Test “smart quotes”, ‘secondary smart quotes’,
52 “‘nested’ smart” quotes
53 – and —also long— dashes.
55 [r
"""Escaped \\"smart quotes\\", \\'secondary smart quotes\\',
56 \\"\\'nested\\' smart\\" quotes
57 \\-- and -\\--also long-\\-- dashes.
60 <document source="test data">
62 Escaped "smart quotes", 'secondary smart quotes',
63 "'nested' smart" quotes
64 -- and ---also long--- dashes.
67 Do not "educate" quotes ``inside "literal" text`` and ::
71 Keep quotes straight in code and math:
72 :code:`print "hello"` :math:`1' 12"`.
84 <document source="test data">
86 Do not “educate” quotes
90 <literal_block xml:space="preserve">
93 Keep quotes straight in code and math:
94 <literal classes="code">
100 <literal_block classes="code" xml:space="preserve">
102 <math_block xml:space="preserve">
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*.
117 <document source="test data">
119 Quotes and inline-elements:
120 <bullet_list bullet="*">
124 <target ids="targets" names="targets">
134 <reference name="targets" refname="targets">
146 Do not drop characters from intra-word inline markup like
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'.
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">
186 No smart quotes defined for language "foo".
190 totest_de
['transitions'] = ((SmartQuotes
,), [
192 German "smart quotes" and 'secondary smart quotes'.
194 .. class:: language-en
196 English "smart quotes" and 'secondary smart quotes'.
199 <document source="test data">
201 German „smart quotes“ and ‚secondary smart quotes‘.
202 <paragraph classes="language-en">
203 English “smart quotes” and ‘secondary smart quotes’.
207 totest_de_alt
['transitions'] = ((SmartQuotes
,), [
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.
223 <document source="test data">
225 Alternative German »smart quotes« and ›secondary smart quotes‹.
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.
236 if __name__
== '__main__':
238 unittest
.main(defaultTest
='suite')