#! /usr/bin/env python # $Id: test_unicode.py 5889 2009-04-01 20:00:21Z gbrandl $ # Author: David Goodger # Copyright: This module has been placed in the public domain. """ Tests for misc.py "unicode" directive. """ from .__init__ import DocutilsTestSupport def suite(): s = DocutilsTestSupport.ParserTestSuite() s.generateTests(totest) return s unichr_exception = DocutilsTestSupport.exception_data( chr, int("111111111111111111", 16))[0] if isinstance(unichr_exception, OverflowError): unichr_exception_string = 'code too large (%s)' % unichr_exception else: unichr_exception_string = str(unichr_exception) totest = {} totest['unicode'] = [ [""" Insert an em-dash (|mdash|), a copyright symbol (|copy|), a non-breaking space (|nbsp|), a backwards-not-equals (|bne|), and a captial omega (|Omega|). .. |mdash| unicode:: 0x02014 .. |copy| unicode:: \\u00A9 .. |nbsp| unicode::   .. |bne| unicode:: U0003D U020E5 .. |Omega| unicode:: U+003A9 """, """\ Insert an em-dash ( mdash ), a copyright symbol ( copy ), a non-breaking space ( nbsp ), a backwards-not-equals ( bne ), and a captial omega ( Omega ). \u2014 \u00A9 \u00A0 = \u20e5 \u03a9 """], [""" Bad input: .. |empty| unicode:: .. |empty too| unicode:: .. comment doesn't count as content .. |not hex| unicode:: 0xHEX .. |not all hex| unicode:: UABCX .. unicode:: not in a substitution definition """, """\ Bad input: Error in "unicode" directive: 1 argument(s) required, 0 supplied. unicode:: Substitution definition "empty" empty or invalid. .. |empty| unicode:: Substitution definition "empty too" empty or invalid. .. |empty too| unicode:: .. comment doesn't count as content 0xHEX UABCX Invalid context: the "unicode" directive can only be used within a substitution definition. .. unicode:: not in a substitution definition """], [""" Testing comments and extra text. Copyright |copy| 2003, |BogusMegaCorp (TM)|. .. |copy| unicode:: 0xA9 .. copyright sign .. |BogusMegaCorp (TM)| unicode:: BogusMegaCorp U+2122 .. with trademark sign """, """\ Testing comments and extra text. Copyright copy 2003, BogusMegaCorp (TM) . \u00A9 BogusMegaCorp \u2122 """], [""" .. |too big for int| unicode:: 0x111111111111111111 .. |too big for unicode| unicode:: 0x11111111 """, """\ Invalid character code: 0x111111111111111111 ValueError: %s unicode:: 0x111111111111111111 Substitution definition "too big for int" empty or invalid. .. |too big for int| unicode:: 0x111111111111111111 Invalid character code: 0x11111111 %s unicode:: 0x11111111 Substitution definition "too big for unicode" empty or invalid. .. |too big for unicode| unicode:: 0x11111111 """ % (unichr_exception_string, DocutilsTestSupport.exception_data(chr, int("11111111", 16))[2])] ] if __name__ == '__main__': import unittest unittest.main(defaultTest='suite')