diff options
author | Marc-André Lemburg <mal@egenix.com> | 2000-06-28 16:41:23 (GMT) |
---|---|---|
committer | Marc-André Lemburg <mal@egenix.com> | 2000-06-28 16:41:23 (GMT) |
commit | a6f73d64c5eb8939731e9262a335f201c117574c (patch) | |
tree | d122b4c756ae518f16516d5708ca4df3446f8e63 /Lib | |
parent | 8cef4cf737878bd8eec648426eebe9b9019b18be (diff) | |
download | cpython-a6f73d64c5eb8939731e9262a335f201c117574c.zip cpython-a6f73d64c5eb8939731e9262a335f201c117574c.tar.gz cpython-a6f73d64c5eb8939731e9262a335f201c117574c.tar.bz2 |
Marc-Andre Lemburg <mal@lemburg.com>:
Added tests for the new Unicode character name support in the
standard unicode-escape codec.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_unicode.py | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 7c41534..304e672 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -408,3 +408,78 @@ assert (u"abc" "def") == u"abcdef" assert (u"abc" u"def" "ghi") == u"abcdefghi" assert ("abc" "def" u"ghi") == u"abcdefghi" print 'done.' + +print 'Testing General Unicode Character Name, and case insensitivity...', +# General and case insensitivity test: +s = u"\N{LATIN CAPITAL LETTER T}" \ + u"\N{LATIN SMALL LETTER H}" \ + u"\N{LATIN SMALL LETTER E}" \ + u"\N{SPACE}" \ + u"\N{LATIN SMALL LETTER R}" \ + u"\N{LATIN CAPITAL LETTER E}" \ + u"\N{LATIN SMALL LETTER D}" \ + u"\N{SPACE}" \ + u"\N{LATIN SMALL LETTER f}" \ + u"\N{LATIN CAPITAL LeTtEr o}" \ + u"\N{LATIN SMaLl LETTER x}" \ + u"\N{SPACE}" \ + u"\N{LATIN SMALL LETTER A}" \ + u"\N{LATIN SMALL LETTER T}" \ + u"\N{LATIN SMALL LETTER E}" \ + u"\N{SPACE}" \ + u"\N{LATIN SMALL LETTER T}" \ + u"\N{LATIN SMALL LETTER H}" \ + u"\N{LATIN SMALL LETTER E}" \ + u"\N{SpAcE}" \ + u"\N{LATIN SMALL LETTER S}" \ + u"\N{LATIN SMALL LETTER H}" \ + u"\N{LATIN SMALL LETTER E}" \ + u"\N{LATIN SMALL LETTER E}" \ + u"\N{LATIN SMALL LETTER P}" \ + u"\N{FULL STOP}" +assert s == u"The rEd fOx ate the sheep.", s +print "done." + +# misc. symbol testing +print "Testing misc. symbols for unicode character name expansion....", +assert u"\N{PILCROW SIGN}" == u"\u00b6" +assert u"\N{REPLACEMENT CHARACTER}" == u"\uFFFD" +assert u"\N{HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK}" == u"\uFF9F" +assert u"\N{FULLWIDTH LATIN SMALL LETTER A}" == u"\uFF41" +print "done." + + +# strict error testing: +print "Testing unicode character name expansion strict error handling....", +k_cchMaxUnicodeName = 83 + +s = "\N{" + "1" * (k_cchMaxUnicodeName + 2) + "}" +try: + unicode(s, 'unicode-escape', 'strict') +except UnicodeError: + pass +else: + raise AssertionError, "failed to raise an exception when presented " \ + "with a UCN > k_cchMaxUnicodeName" +try: + unicode("\N{blah}", 'unicode-escape', 'strict') +except UnicodeError: + pass +else: + raise AssertionError, "failed to raise an exception when given a bogus character name" + +try: + unicode("\N{SPACE", 'unicode-escape', 'strict') +except UnicodeError: + pass +else: + raise AssertionError, "failed to raise an exception for a missing closing brace." + +try: + unicode("\NSPACE", 'unicode-escape', 'strict') +except UnicodeError: + pass +else: + raise AssertionError, "failed to raise an exception for a missing opening brace." +print "done." + |