move sections
[python/dscho.git] / Lib / test / test_stringprep.py
blob15bdf87652999120df4c021648f34db5775e7d5a
1 # 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.
4 import unittest
5 from test import test_support
7 from stringprep import *
9 class StringprepTests(unittest.TestCase):
10 def test(self):
11 self.assertTrue(in_table_a1(u"\u0221"))
12 self.assertFalse(in_table_a1(u"\u0222"))
14 self.assertTrue(in_table_b1(u"\u00ad"))
15 self.assertFalse(in_table_b1(u"\u00ae"))
17 self.assertTrue(map_table_b2(u"\u0041"), u"\u0061")
18 self.assertTrue(map_table_b2(u"\u0061"), u"\u0061")
20 self.assertTrue(map_table_b3(u"\u0041"), u"\u0061")
21 self.assertTrue(map_table_b3(u"\u0061"), u"\u0061")
23 self.assertTrue(in_table_c11(u"\u0020"))
24 self.assertFalse(in_table_c11(u"\u0021"))
26 self.assertTrue(in_table_c12(u"\u00a0"))
27 self.assertFalse(in_table_c12(u"\u00a1"))
29 self.assertTrue(in_table_c12(u"\u00a0"))
30 self.assertFalse(in_table_c12(u"\u00a1"))
32 self.assertTrue(in_table_c11_c12(u"\u00a0"))
33 self.assertFalse(in_table_c11_c12(u"\u00a1"))
35 self.assertTrue(in_table_c21(u"\u001f"))
36 self.assertFalse(in_table_c21(u"\u0020"))
38 self.assertTrue(in_table_c22(u"\u009f"))
39 self.assertFalse(in_table_c22(u"\u00a0"))
41 self.assertTrue(in_table_c21_c22(u"\u009f"))
42 self.assertFalse(in_table_c21_c22(u"\u00a0"))
44 self.assertTrue(in_table_c3(u"\ue000"))
45 self.assertFalse(in_table_c3(u"\uf900"))
47 self.assertTrue(in_table_c4(u"\uffff"))
48 self.assertFalse(in_table_c4(u"\u0000"))
50 self.assertTrue(in_table_c5(u"\ud800"))
51 self.assertFalse(in_table_c5(u"\ud7ff"))
53 self.assertTrue(in_table_c6(u"\ufff9"))
54 self.assertFalse(in_table_c6(u"\ufffe"))
56 self.assertTrue(in_table_c7(u"\u2ff0"))
57 self.assertFalse(in_table_c7(u"\u2ffc"))
59 self.assertTrue(in_table_c8(u"\u0340"))
60 self.assertFalse(in_table_c8(u"\u0342"))
62 # C.9 is not in the bmp
63 # self.assertTrue(in_table_c9(u"\U000E0001"))
64 # self.assertFalse(in_table_c8(u"\U000E0002"))
66 self.assertTrue(in_table_d1(u"\u05be"))
67 self.assertFalse(in_table_d1(u"\u05bf"))
69 self.assertTrue(in_table_d2(u"\u0041"))
70 self.assertFalse(in_table_d2(u"\u0040"))
72 # This would generate a hash of all predicates. However, running
73 # it is quite expensive, and only serves to detect changes in the
74 # unicode database. Instead, stringprep.py asserts the version of
75 # the database.
77 # import hashlib
78 # predicates = [k for k in dir(stringprep) if k.startswith("in_table")]
79 # predicates.sort()
80 # for p in predicates:
81 # f = getattr(stringprep, p)
82 # # Collect all BMP code points
83 # data = ["0"] * 0x10000
84 # for i in range(0x10000):
85 # if f(unichr(i)):
86 # data[i] = "1"
87 # data = "".join(data)
88 # h = hashlib.sha1()
89 # h.update(data)
90 # print p, h.hexdigest()
92 def test_main():
93 test_support.run_unittest(StringprepTests)
95 if __name__ == '__main__':
96 test_main()