blob: d631406a005ecaad35c0c26e902c214c18c2fa32 [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:
55 unicode(s, 'unicode-escape', 'strict')
56except UnicodeError:
57 pass
58else:
59 raise AssertionError, "failed to raise an exception when presented " \
60 "with a UCN > k_cchMaxUnicodeName"
61try:
62 unicode("\N{blah}", 'unicode-escape', 'strict')
63except UnicodeError:
64 pass
65else:
66 raise AssertionError, "failed to raise an exception when given a bogus character name"
67
68try:
69 unicode("\N{SPACE", 'unicode-escape', 'strict')
70except UnicodeError:
71 pass
72else:
73 raise AssertionError, "failed to raise an exception for a missing closing brace."
74
75try:
76 unicode("\NSPACE", 'unicode-escape', 'strict')
77except UnicodeError:
78 pass
79else:
80 raise AssertionError, "failed to raise an exception for a missing opening brace."
81print "done."
82