blob: 92155be86951fd1959422e3ee131cc392934b375 [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"""#"
Marc-André Lemburg36619082001-01-17 19:11:13 +00008from test_support import verify, verbose
9
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000010print 'Testing General Unicode Character Name, and case insensitivity...',
11
12# General and case insensitivity test:
13s = u"\N{LATIN CAPITAL LETTER T}" \
14 u"\N{LATIN SMALL LETTER H}" \
15 u"\N{LATIN SMALL LETTER E}" \
16 u"\N{SPACE}" \
17 u"\N{LATIN SMALL LETTER R}" \
18 u"\N{LATIN CAPITAL LETTER E}" \
19 u"\N{LATIN SMALL LETTER D}" \
20 u"\N{SPACE}" \
21 u"\N{LATIN SMALL LETTER f}" \
22 u"\N{LATIN CAPITAL LeTtEr o}" \
23 u"\N{LATIN SMaLl LETTER x}" \
24 u"\N{SPACE}" \
25 u"\N{LATIN SMALL LETTER A}" \
26 u"\N{LATIN SMALL LETTER T}" \
27 u"\N{LATIN SMALL LETTER E}" \
28 u"\N{SPACE}" \
29 u"\N{LATIN SMALL LETTER T}" \
30 u"\N{LATIN SMALL LETTER H}" \
31 u"\N{LATIN SMALL LETTER E}" \
32 u"\N{SpAcE}" \
33 u"\N{LATIN SMALL LETTER S}" \
34 u"\N{LATIN SMALL LETTER H}" \
35 u"\N{LATIN SMALL LETTER E}" \
36 u"\N{LATIN SMALL LETTER E}" \
37 u"\N{LATIN SMALL LETTER P}" \
38 u"\N{FULL STOP}"
Marc-André Lemburg36619082001-01-17 19:11:13 +000039verify(s == u"The rEd fOx ate the sheep.", s)
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000040print "done."
41
42# misc. symbol testing
43print "Testing misc. symbols for unicode character name expansion....",
Marc-André Lemburg36619082001-01-17 19:11:13 +000044verify(u"\N{PILCROW SIGN}" == u"\u00b6")
45verify(u"\N{REPLACEMENT CHARACTER}" == u"\uFFFD")
46verify(u"\N{HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK}" == u"\uFF9F")
47verify(u"\N{FULLWIDTH LATIN SMALL LETTER A}" == u"\uFF41")
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000048print "done."
49
50
51# strict error testing:
52print "Testing unicode character name expansion strict error handling....",
53k_cchMaxUnicodeName = 83
54
55s = "\N{" + "1" * (k_cchMaxUnicodeName + 2) + "}"
56try:
Fred Drake004d5e62000-10-23 17:22:08 +000057 unicode(s, 'unicode-escape', 'strict')
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000058except UnicodeError:
Fred Drake004d5e62000-10-23 17:22:08 +000059 pass
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000060else:
Fred Drake004d5e62000-10-23 17:22:08 +000061 raise AssertionError, "failed to raise an exception when presented " \
62 "with a UCN > k_cchMaxUnicodeName"
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000063try:
Fred Drake004d5e62000-10-23 17:22:08 +000064 unicode("\N{blah}", 'unicode-escape', 'strict')
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000065except UnicodeError:
Fred Drake004d5e62000-10-23 17:22:08 +000066 pass
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000067else:
Fred Drake004d5e62000-10-23 17:22:08 +000068 raise AssertionError, "failed to raise an exception when given a bogus character name"
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000069
70try:
Fred Drake004d5e62000-10-23 17:22:08 +000071 unicode("\N{SPACE", 'unicode-escape', 'strict')
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000072except UnicodeError:
Fred Drake004d5e62000-10-23 17:22:08 +000073 pass
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000074else:
Fred Drake004d5e62000-10-23 17:22:08 +000075 raise AssertionError, "failed to raise an exception for a missing closing brace."
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000076
77try:
Fred Drake004d5e62000-10-23 17:22:08 +000078 unicode("\NSPACE", 'unicode-escape', 'strict')
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000079except UnicodeError:
Fred Drake004d5e62000-10-23 17:22:08 +000080 pass
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000081else:
Fred Drake004d5e62000-10-23 17:22:08 +000082 raise AssertionError, "failed to raise an exception for a missing opening brace."
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000083print "done."