blob: f1a62299c868da2e769bb8bb40657b4894f10cf0 [file] [log] [blame]
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +00001""" Test script for the Unicode implementation.
2
3Written by Bill Tutt.
4
5(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
6
7"""#"
8print 'Testing General Unicode Character Name, and case insensitivity...',
9
10# General and case insensitivity test:
11s = 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}"
37assert s == u"The rEd fOx ate the sheep.", s
38print "done."
39
40# misc. symbol testing
41print "Testing misc. symbols for unicode character name expansion....",
42assert u"\N{PILCROW SIGN}" == u"\u00b6"
43assert u"\N{REPLACEMENT CHARACTER}" == u"\uFFFD"
44assert u"\N{HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK}" == u"\uFF9F"
45assert u"\N{FULLWIDTH LATIN SMALL LETTER A}" == u"\uFF41"
46print "done."
47
48
49# strict error testing:
50print "Testing unicode character name expansion strict error handling....",
51k_cchMaxUnicodeName = 83
52
53s = "\N{" + "1" * (k_cchMaxUnicodeName + 2) + "}"
54try:
Fred Drake004d5e62000-10-23 17:22:08 +000055 unicode(s, 'unicode-escape', 'strict')
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000056except UnicodeError:
Fred Drake004d5e62000-10-23 17:22:08 +000057 pass
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000058else:
Fred Drake004d5e62000-10-23 17:22:08 +000059 raise AssertionError, "failed to raise an exception when presented " \
60 "with a UCN > k_cchMaxUnicodeName"
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000061try:
Fred Drake004d5e62000-10-23 17:22:08 +000062 unicode("\N{blah}", 'unicode-escape', 'strict')
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000063except UnicodeError:
Fred Drake004d5e62000-10-23 17:22:08 +000064 pass
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000065else:
Fred Drake004d5e62000-10-23 17:22:08 +000066 raise AssertionError, "failed to raise an exception when given a bogus character name"
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000067
68try:
Fred Drake004d5e62000-10-23 17:22:08 +000069 unicode("\N{SPACE", 'unicode-escape', 'strict')
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000070except UnicodeError:
Fred Drake004d5e62000-10-23 17:22:08 +000071 pass
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000072else:
Fred Drake004d5e62000-10-23 17:22:08 +000073 raise AssertionError, "failed to raise an exception for a missing closing brace."
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000074
75try:
Fred Drake004d5e62000-10-23 17:22:08 +000076 unicode("\NSPACE", 'unicode-escape', 'strict')
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000077except UnicodeError:
Fred Drake004d5e62000-10-23 17:22:08 +000078 pass
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000079else:
Fred Drake004d5e62000-10-23 17:22:08 +000080 raise AssertionError, "failed to raise an exception for a missing opening brace."
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000081print "done."