1 | n/a | # To fully test this module, we would need a copy of the stringprep tables. |
---|
2 | n/a | # Since we don't have them, this test checks only a few code points. |
---|
3 | n/a | |
---|
4 | n/a | import unittest |
---|
5 | n/a | |
---|
6 | n/a | from stringprep import * |
---|
7 | n/a | |
---|
8 | n/a | class StringprepTests(unittest.TestCase): |
---|
9 | n/a | def test(self): |
---|
10 | n/a | self.assertTrue(in_table_a1("\u0221")) |
---|
11 | n/a | self.assertFalse(in_table_a1("\u0222")) |
---|
12 | n/a | |
---|
13 | n/a | self.assertTrue(in_table_b1("\u00ad")) |
---|
14 | n/a | self.assertFalse(in_table_b1("\u00ae")) |
---|
15 | n/a | |
---|
16 | n/a | self.assertTrue(map_table_b2("\u0041"), "\u0061") |
---|
17 | n/a | self.assertTrue(map_table_b2("\u0061"), "\u0061") |
---|
18 | n/a | |
---|
19 | n/a | self.assertTrue(map_table_b3("\u0041"), "\u0061") |
---|
20 | n/a | self.assertTrue(map_table_b3("\u0061"), "\u0061") |
---|
21 | n/a | |
---|
22 | n/a | self.assertTrue(in_table_c11("\u0020")) |
---|
23 | n/a | self.assertFalse(in_table_c11("\u0021")) |
---|
24 | n/a | |
---|
25 | n/a | self.assertTrue(in_table_c12("\u00a0")) |
---|
26 | n/a | self.assertFalse(in_table_c12("\u00a1")) |
---|
27 | n/a | |
---|
28 | n/a | self.assertTrue(in_table_c12("\u00a0")) |
---|
29 | n/a | self.assertFalse(in_table_c12("\u00a1")) |
---|
30 | n/a | |
---|
31 | n/a | self.assertTrue(in_table_c11_c12("\u00a0")) |
---|
32 | n/a | self.assertFalse(in_table_c11_c12("\u00a1")) |
---|
33 | n/a | |
---|
34 | n/a | self.assertTrue(in_table_c21("\u001f")) |
---|
35 | n/a | self.assertFalse(in_table_c21("\u0020")) |
---|
36 | n/a | |
---|
37 | n/a | self.assertTrue(in_table_c22("\u009f")) |
---|
38 | n/a | self.assertFalse(in_table_c22("\u00a0")) |
---|
39 | n/a | |
---|
40 | n/a | self.assertTrue(in_table_c21_c22("\u009f")) |
---|
41 | n/a | self.assertFalse(in_table_c21_c22("\u00a0")) |
---|
42 | n/a | |
---|
43 | n/a | self.assertTrue(in_table_c3("\ue000")) |
---|
44 | n/a | self.assertFalse(in_table_c3("\uf900")) |
---|
45 | n/a | |
---|
46 | n/a | self.assertTrue(in_table_c4("\uffff")) |
---|
47 | n/a | self.assertFalse(in_table_c4("\u0000")) |
---|
48 | n/a | |
---|
49 | n/a | self.assertTrue(in_table_c5("\ud800")) |
---|
50 | n/a | self.assertFalse(in_table_c5("\ud7ff")) |
---|
51 | n/a | |
---|
52 | n/a | self.assertTrue(in_table_c6("\ufff9")) |
---|
53 | n/a | self.assertFalse(in_table_c6("\ufffe")) |
---|
54 | n/a | |
---|
55 | n/a | self.assertTrue(in_table_c7("\u2ff0")) |
---|
56 | n/a | self.assertFalse(in_table_c7("\u2ffc")) |
---|
57 | n/a | |
---|
58 | n/a | self.assertTrue(in_table_c8("\u0340")) |
---|
59 | n/a | self.assertFalse(in_table_c8("\u0342")) |
---|
60 | n/a | |
---|
61 | n/a | # C.9 is not in the bmp |
---|
62 | n/a | # self.assertTrue(in_table_c9(u"\U000E0001")) |
---|
63 | n/a | # self.assertFalse(in_table_c8(u"\U000E0002")) |
---|
64 | n/a | |
---|
65 | n/a | self.assertTrue(in_table_d1("\u05be")) |
---|
66 | n/a | self.assertFalse(in_table_d1("\u05bf")) |
---|
67 | n/a | |
---|
68 | n/a | self.assertTrue(in_table_d2("\u0041")) |
---|
69 | n/a | self.assertFalse(in_table_d2("\u0040")) |
---|
70 | n/a | |
---|
71 | n/a | # This would generate a hash of all predicates. However, running |
---|
72 | n/a | # it is quite expensive, and only serves to detect changes in the |
---|
73 | n/a | # unicode database. Instead, stringprep.py asserts the version of |
---|
74 | n/a | # the database. |
---|
75 | n/a | |
---|
76 | n/a | # import hashlib |
---|
77 | n/a | # predicates = [k for k in dir(stringprep) if k.startswith("in_table")] |
---|
78 | n/a | # predicates.sort() |
---|
79 | n/a | # for p in predicates: |
---|
80 | n/a | # f = getattr(stringprep, p) |
---|
81 | n/a | # # Collect all BMP code points |
---|
82 | n/a | # data = ["0"] * 0x10000 |
---|
83 | n/a | # for i in range(0x10000): |
---|
84 | n/a | # if f(unichr(i)): |
---|
85 | n/a | # data[i] = "1" |
---|
86 | n/a | # data = "".join(data) |
---|
87 | n/a | # h = hashlib.sha1() |
---|
88 | n/a | # h.update(data) |
---|
89 | n/a | # print p, h.hexdigest() |
---|
90 | n/a | |
---|
91 | n/a | if __name__ == '__main__': |
---|
92 | n/a | unittest.main() |
---|