blob: 2baf4a5f2cac1e3306d38c3e60dfdeecaebc60dc [file] [log] [blame]
Martin v. Löwisb4cb6642003-04-19 12:57:57 +00001# To fully test this module, we would need a copy of the stringprep tables.
2# Since we don't have them, this test checks only a few codepoints.
3
4from test.test_support import verify, vereq
Martin v. Löwisb4cb6642003-04-19 12:57:57 +00005
6import stringprep
7from stringprep import *
8
9verify(in_table_a1(u"\u0221"))
10verify(not in_table_a1(u"\u0222"))
11
12verify(in_table_b1(u"\u00ad"))
13verify(not in_table_b1(u"\u00ae"))
14
15verify(map_table_b2(u"\u0041"), u"\u0061")
16verify(map_table_b2(u"\u0061"), u"\u0061")
17
18verify(map_table_b3(u"\u0041"), u"\u0061")
19verify(map_table_b3(u"\u0061"), u"\u0061")
20
21verify(in_table_c11(u"\u0020"))
22verify(not in_table_c11(u"\u0021"))
23
24verify(in_table_c12(u"\u00a0"))
25verify(not in_table_c12(u"\u00a1"))
26
27verify(in_table_c12(u"\u00a0"))
28verify(not in_table_c12(u"\u00a1"))
29
30verify(in_table_c11_c12(u"\u00a0"))
31verify(not in_table_c11_c12(u"\u00a1"))
32
33verify(in_table_c21(u"\u001f"))
34verify(not in_table_c21(u"\u0020"))
35
36verify(in_table_c22(u"\u009f"))
37verify(not in_table_c22(u"\u00a0"))
38
39verify(in_table_c21_c22(u"\u009f"))
40verify(not in_table_c21_c22(u"\u00a0"))
41
42verify(in_table_c3(u"\ue000"))
43verify(not in_table_c3(u"\uf900"))
44
45verify(in_table_c4(u"\uffff"))
46verify(not in_table_c4(u"\u0000"))
47
48verify(in_table_c5(u"\ud800"))
49verify(not in_table_c5(u"\ud7ff"))
50
51verify(in_table_c6(u"\ufff9"))
52verify(not in_table_c6(u"\ufffe"))
53
54verify(in_table_c7(u"\u2ff0"))
55verify(not in_table_c7(u"\u2ffc"))
56
57verify(in_table_c8(u"\u0340"))
58verify(not in_table_c8(u"\u0342"))
59
60# C.9 is not in the bmp
61# verify(in_table_c9(u"\U000E0001"))
62# verify(not in_table_c8(u"\U000E0002"))
63
64verify(in_table_d1(u"\u05be"))
65verify(not in_table_d1(u"\u05bf"))
66
67verify(in_table_d2(u"\u0041"))
68verify(not in_table_d2(u"\u0040"))
69
70# This would generate a hash of all predicates. However, running
71# it is quite expensive, and only serves to detect changes in the
72# unicode database. Instead, stringprep.py asserts the version of
Walter Dörwaldf0dfc7a2003-10-20 14:01:56 +000073# the database.
Martin v. Löwisb4cb6642003-04-19 12:57:57 +000074
Thomas Wouters477c8d52006-05-27 19:21:47 +000075# import hashlib
Martin v. Löwisb4cb6642003-04-19 12:57:57 +000076# predicates = [k for k in dir(stringprep) if k.startswith("in_table")]
77# predicates.sort()
78# for p in predicates:
79# f = getattr(stringprep, p)
80# # Collect all BMP code points
81# data = ["0"] * 0x10000
82# for i in range(0x10000):
83# if f(unichr(i)):
84# data[i] = "1"
85# data = "".join(data)
Thomas Wouters477c8d52006-05-27 19:21:47 +000086# h = hashlib.sha1()
Martin v. Löwisb4cb6642003-04-19 12:57:57 +000087# h.update(data)
Thomas Wouters477c8d52006-05-27 19:21:47 +000088# print p, h.hexdigest()