#!/usr/bin/env python # -*- coding: utf-8 -*- # $Id: test_smartquotes.py 8068 2017-05-08 22:10:39Z milde $ # # :Copyright: © 2011 Günter Milde. # :Maintainer: docutils-develop@lists.sourceforge.net # :License: Released under the terms of the `2-Clause BSD license`_, in short: # # Copying and distribution of this file, with or without modification, # are permitted in any medium without royalty provided the copyright # notice and this notice are preserved. # This file is offered as-is, without any warranty. # # .. _2-Clause BSD license: http://www.spdx.org/licenses/BSD-2-Clause """ Test module for universal.SmartQuotes transform. """ from __init__ import DocutilsTestSupport # must be imported before docutils from docutils.transforms.universal import SmartQuotes from docutils.parsers.rst import Parser def suite(): parser = Parser() settings = {'smart_quotes': True} s = DocutilsTestSupport.TransformTestSuite( parser, suite_settings=settings) s.generateTests(totest) settings['language_code'] = 'de' s.generateTests(totest_de) settings['smart_quotes'] = 'alternative' s.generateTests(totest_de_alt) settings['smart_quotes'] = True settings['smartquotes_locales'] = [('de', u'«»()'), ('nl', u'„”’’')] s.generateTests(totest_locales) return s totest = {} totest_de = {} totest_de_alt = {} totest_locales = {} totest['transitions'] = ((SmartQuotes,), [ ["""\ Test "smart quotes", 'secondary smart quotes', "'nested' smart" quotes -- and ---also long--- dashes. """, u"""\ Test “smart quotes”, ‘secondary smart quotes’, “‘nested’ smart” quotes – and —also long— dashes. """], [r"""Escaped \\"smart quotes\\", \\'secondary smart quotes\\', \\"\\'nested\\' smart\\" quotes \\-- and -\\--also long-\\-- dashes. """, u"""\ Escaped "smart quotes", 'secondary smart quotes', "'nested' smart" quotes -- and ---also long--- dashes. """], ["""\ Do not "educate" quotes ``inside "literal" text`` and :: "literal" blocks. Keep quotes straight in code and math: :code:`print "hello"` :math:`1' 12"`. .. code:: print "hello" .. math:: f'(x) = df(x)/dx """, u"""\ Do not “educate” quotes inside "literal" text and "literal" blocks. Keep quotes straight in code and math: print "hello" 1' 12" . print "hello" f'(x) = df(x)/dx """], ["""\ Quotes and inline-elements: * Around "_`targets`", "*emphasized*" or "``literal``" text and links to "targets_". * Inside *"emphasized"* or other `inline "roles"` Do not drop characters from intra-word inline markup like *re*\ ``Structured``\ *Text*. """, u"""\ Quotes and inline-elements: Around “ targets ”, “ emphasized ” or “ literal ” text and links to “ targets ”. Inside \n\ “emphasized” or other \n\ inline “roles” Do not drop characters from intra-word inline markup like re Structured Text .\ """], ["""\ Do not convert context-character at inline-tag boundaries (in French, smart quotes expand to two characters). .. class:: language-fr-ch-x-altquot Around "_`targets`", "*emphasized*" or "``literal``" text and links to "targets_". Inside *"emphasized"* or other `inline "roles"`: (``"string"``), (``'string'``), *\\"betont\\"*, \\"*betont*". Do not drop characters from intra-word inline markup like *re*\ ``Structured``\ *Text*. """, u"""\ Do not convert context-character at inline-tag boundaries (in French, smart quotes expand to two characters). Around «\u202f targets \u202f», «\u202f emphasized \u202f» or «\u202f literal \u202f» text and links to «\u202f targets \u202f». Inside \n\ «\u202femphasized\u202f» or other \n\ inline «\u202froles\u202f» : ( "string" ), ( 'string' ), «\u202fbetont\u202f» , «\u202f betont \u202f». Do not drop characters from intra-word inline markup like re Structured Text . """], ["""\ .. class:: language-de German "smart quotes" and 'secondary smart quotes'. .. class:: language-en-UK-x-altquot British "primary quotes" use single and 'secondary quotes' double quote signs. .. class:: language-foo "Quoting style" for unknown languages is 'ASCII'. .. class:: language-de-x-altquot Alternative German "smart quotes" and 'secondary smart quotes'. """, u"""\ German „smart quotes“ and ‚secondary smart quotes‘. British ‘primary quotes’ use single and “secondary quotes” double quote signs. "Quoting style" for unknown languages is 'ASCII'. Alternative German »smart quotes« and ›secondary smart quotes‹. No smart quotes defined for language "foo". """], ]) totest_de['transitions'] = ((SmartQuotes,), [ ["""\ German "smart quotes" and 'secondary smart quotes'. .. class:: language-en English "smart quotes" and 'secondary smart quotes'. """, u"""\ German „smart quotes“ and ‚secondary smart quotes‘. English “smart quotes” and ‘secondary smart quotes’. """], ]) totest_de_alt['transitions'] = ((SmartQuotes,), [ ["""\ Alternative German "smart quotes" and 'secondary smart quotes'. In this case, the apostrophe isn't a closing secondary quote! .. class:: language-en-UK British "quotes" use single and 'secondary quotes' double quote signs (there are no alternative quotes defined). .. class:: language-ro Romanian "smart quotes" and 'secondary' smart quotes. """, u"""\ Alternative German »smart quotes« and ›secondary smart quotes‹. In this case, the apostrophe isn’t a closing secondary quote! British ‘quotes’ use single and “secondary quotes” double quote signs (there are no alternative quotes defined). Romanian „smart quotes” and «secondary» smart quotes. """], ]) totest_locales['transitions'] = ((SmartQuotes,), [ ["""\ German "smart quotes" and 'secondary smart quotes'. .. class:: language-nl Dutch "smart quotes" and 's Gravenhage (leading apostrophe). """, u"""\ German «smart quotes» and (secondary smart quotes). Dutch „smart quotes” and ’s Gravenhage (leading apostrophe). """], ]) if __name__ == '__main__': import unittest unittest.main(defaultTest='suite')