blob: f680140f153ef7fc31f2dde2e9530ff7b608ae20 [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)
Fredrik Lundh2acb54a2001-01-19 11:13:46 +000040print "done."
Fredrik Lundhee865c62001-01-19 11:00:42 +000041
42import ucnhash
43
Fredrik Lundh2acb54a2001-01-19 11:13:46 +000044print "Testing name to code mapping....",
Fredrik Lundhee865c62001-01-19 11:00:42 +000045for char in "SPAM":
46 name = "LATIN SMALL LETTER %s" % char
47 code = ucnhash.getcode(name)
48 verify(ucnhash.getname(code) == name)
Fredrik Lundh2acb54a2001-01-19 11:13:46 +000049print "done."
Fredrik Lundhee865c62001-01-19 11:00:42 +000050
Fredrik Lundh2acb54a2001-01-19 11:13:46 +000051print "Testing code to name mapping for all characters....",
52count = 0
Fredrik Lundhee865c62001-01-19 11:00:42 +000053for code in range(65536):
54 try:
55 name = ucnhash.getname(code)
56 verify(ucnhash.getcode(name) == code)
Fredrik Lundh2acb54a2001-01-19 11:13:46 +000057 count += 1
Fredrik Lundhee865c62001-01-19 11:00:42 +000058 except ValueError:
59 pass
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000060print "done."
61
Fredrik Lundh2acb54a2001-01-19 11:13:46 +000062print "Found", count, "characters in the unicode name database"
63
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000064# misc. symbol testing
65print "Testing misc. symbols for unicode character name expansion....",
Marc-André Lemburg36619082001-01-17 19:11:13 +000066verify(u"\N{PILCROW SIGN}" == u"\u00b6")
67verify(u"\N{REPLACEMENT CHARACTER}" == u"\uFFFD")
68verify(u"\N{HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK}" == u"\uFF9F")
69verify(u"\N{FULLWIDTH LATIN SMALL LETTER A}" == u"\uFF41")
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000070print "done."
71
72
73# strict error testing:
74print "Testing unicode character name expansion strict error handling....",
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000075try:
Fred Drake004d5e62000-10-23 17:22:08 +000076 unicode("\N{blah}", '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 when given a bogus character name"
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000081
82try:
Fredrik Lundh0fdb90c2001-01-19 09:45:02 +000083 unicode("\N{" + "x" * 100000 + "}", 'unicode-escape', 'strict')
84except UnicodeError:
85 pass
86else:
87 raise AssertionError, "failed to raise an exception when given a very " \
88 "long bogus character name"
89
90try:
Fred Drake004d5e62000-10-23 17:22:08 +000091 unicode("\N{SPACE", 'unicode-escape', 'strict')
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000092except UnicodeError:
Fred Drake004d5e62000-10-23 17:22:08 +000093 pass
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000094else:
Fred Drake004d5e62000-10-23 17:22:08 +000095 raise AssertionError, "failed to raise an exception for a missing closing brace."
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000096
97try:
Fred Drake004d5e62000-10-23 17:22:08 +000098 unicode("\NSPACE", 'unicode-escape', 'strict')
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +000099except UnicodeError:
Fred Drake004d5e62000-10-23 17:22:08 +0000100 pass
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +0000101else:
Fred Drake004d5e62000-10-23 17:22:08 +0000102 raise AssertionError, "failed to raise an exception for a missing opening brace."
Marc-André Lemburg6cdec2e2000-06-30 09:45:20 +0000103print "done."