Marc-André Lemburg | 6cdec2e | 2000-06-30 09:45:20 +0000 | [diff] [blame] | 1 | """ Test script for the Unicode implementation. |
| 2 | |
| 3 | Written by Bill Tutt. |
| 4 | |
| 5 | (c) Copyright CNRI, All Rights Reserved. NO WARRANTY. |
| 6 | |
| 7 | """#" |
| 8 | print 'Testing General Unicode Character Name, and case insensitivity...', |
| 9 | |
| 10 | # General and case insensitivity test: |
| 11 | s = u"\N{LATIN CAPITAL LETTER T}" \ |
| 12 | u"\N{LATIN SMALL LETTER H}" \ |
| 13 | u"\N{LATIN SMALL LETTER E}" \ |
| 14 | u"\N{SPACE}" \ |
| 15 | u"\N{LATIN SMALL LETTER R}" \ |
| 16 | u"\N{LATIN CAPITAL LETTER E}" \ |
| 17 | u"\N{LATIN SMALL LETTER D}" \ |
| 18 | u"\N{SPACE}" \ |
| 19 | u"\N{LATIN SMALL LETTER f}" \ |
| 20 | u"\N{LATIN CAPITAL LeTtEr o}" \ |
| 21 | u"\N{LATIN SMaLl LETTER x}" \ |
| 22 | u"\N{SPACE}" \ |
| 23 | u"\N{LATIN SMALL LETTER A}" \ |
| 24 | u"\N{LATIN SMALL LETTER T}" \ |
| 25 | u"\N{LATIN SMALL LETTER E}" \ |
| 26 | u"\N{SPACE}" \ |
| 27 | u"\N{LATIN SMALL LETTER T}" \ |
| 28 | u"\N{LATIN SMALL LETTER H}" \ |
| 29 | u"\N{LATIN SMALL LETTER E}" \ |
| 30 | u"\N{SpAcE}" \ |
| 31 | u"\N{LATIN SMALL LETTER S}" \ |
| 32 | u"\N{LATIN SMALL LETTER H}" \ |
| 33 | u"\N{LATIN SMALL LETTER E}" \ |
| 34 | u"\N{LATIN SMALL LETTER E}" \ |
| 35 | u"\N{LATIN SMALL LETTER P}" \ |
| 36 | u"\N{FULL STOP}" |
| 37 | assert s == u"The rEd fOx ate the sheep.", s |
| 38 | print "done." |
| 39 | |
| 40 | # misc. symbol testing |
| 41 | print "Testing misc. symbols for unicode character name expansion....", |
| 42 | assert u"\N{PILCROW SIGN}" == u"\u00b6" |
| 43 | assert u"\N{REPLACEMENT CHARACTER}" == u"\uFFFD" |
| 44 | assert u"\N{HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK}" == u"\uFF9F" |
| 45 | assert u"\N{FULLWIDTH LATIN SMALL LETTER A}" == u"\uFF41" |
| 46 | print "done." |
| 47 | |
| 48 | |
| 49 | # strict error testing: |
| 50 | print "Testing unicode character name expansion strict error handling....", |
| 51 | k_cchMaxUnicodeName = 83 |
| 52 | |
| 53 | s = "\N{" + "1" * (k_cchMaxUnicodeName + 2) + "}" |
| 54 | try: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame^] | 55 | unicode(s, 'unicode-escape', 'strict') |
Marc-André Lemburg | 6cdec2e | 2000-06-30 09:45:20 +0000 | [diff] [blame] | 56 | except UnicodeError: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame^] | 57 | pass |
Marc-André Lemburg | 6cdec2e | 2000-06-30 09:45:20 +0000 | [diff] [blame] | 58 | else: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame^] | 59 | raise AssertionError, "failed to raise an exception when presented " \ |
| 60 | "with a UCN > k_cchMaxUnicodeName" |
Marc-André Lemburg | 6cdec2e | 2000-06-30 09:45:20 +0000 | [diff] [blame] | 61 | try: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame^] | 62 | unicode("\N{blah}", 'unicode-escape', 'strict') |
Marc-André Lemburg | 6cdec2e | 2000-06-30 09:45:20 +0000 | [diff] [blame] | 63 | except UnicodeError: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame^] | 64 | pass |
Marc-André Lemburg | 6cdec2e | 2000-06-30 09:45:20 +0000 | [diff] [blame] | 65 | else: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame^] | 66 | raise AssertionError, "failed to raise an exception when given a bogus character name" |
Marc-André Lemburg | 6cdec2e | 2000-06-30 09:45:20 +0000 | [diff] [blame] | 67 | |
| 68 | try: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame^] | 69 | unicode("\N{SPACE", 'unicode-escape', 'strict') |
Marc-André Lemburg | 6cdec2e | 2000-06-30 09:45:20 +0000 | [diff] [blame] | 70 | except UnicodeError: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame^] | 71 | pass |
Marc-André Lemburg | 6cdec2e | 2000-06-30 09:45:20 +0000 | [diff] [blame] | 72 | else: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame^] | 73 | raise AssertionError, "failed to raise an exception for a missing closing brace." |
Marc-André Lemburg | 6cdec2e | 2000-06-30 09:45:20 +0000 | [diff] [blame] | 74 | |
| 75 | try: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame^] | 76 | unicode("\NSPACE", 'unicode-escape', 'strict') |
Marc-André Lemburg | 6cdec2e | 2000-06-30 09:45:20 +0000 | [diff] [blame] | 77 | except UnicodeError: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame^] | 78 | pass |
Marc-André Lemburg | 6cdec2e | 2000-06-30 09:45:20 +0000 | [diff] [blame] | 79 | else: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame^] | 80 | raise AssertionError, "failed to raise an exception for a missing opening brace." |
Marc-André Lemburg | 6cdec2e | 2000-06-30 09:45:20 +0000 | [diff] [blame] | 81 | print "done." |