Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 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. |
| 3 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 4 | import unittest |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 5 | from test import support |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 6 | |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 7 | from stringprep import * |
| 8 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 9 | class StringprepTests(unittest.TestCase): |
| 10 | def test(self): |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 11 | self.assertTrue(in_table_a1("\u0221")) |
| 12 | self.assertFalse(in_table_a1("\u0222")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 13 | |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 14 | self.assertTrue(in_table_b1("\u00ad")) |
| 15 | self.assertFalse(in_table_b1("\u00ae")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 16 | |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 17 | self.assertTrue(map_table_b2("\u0041"), "\u0061") |
| 18 | self.assertTrue(map_table_b2("\u0061"), "\u0061") |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 19 | |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 20 | self.assertTrue(map_table_b3("\u0041"), "\u0061") |
| 21 | self.assertTrue(map_table_b3("\u0061"), "\u0061") |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 22 | |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 23 | self.assertTrue(in_table_c11("\u0020")) |
| 24 | self.assertFalse(in_table_c11("\u0021")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 25 | |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 26 | self.assertTrue(in_table_c12("\u00a0")) |
| 27 | self.assertFalse(in_table_c12("\u00a1")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 28 | |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 29 | self.assertTrue(in_table_c12("\u00a0")) |
| 30 | self.assertFalse(in_table_c12("\u00a1")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 31 | |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 32 | self.assertTrue(in_table_c11_c12("\u00a0")) |
| 33 | self.assertFalse(in_table_c11_c12("\u00a1")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 34 | |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 35 | self.assertTrue(in_table_c21("\u001f")) |
| 36 | self.assertFalse(in_table_c21("\u0020")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 37 | |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 38 | self.assertTrue(in_table_c22("\u009f")) |
| 39 | self.assertFalse(in_table_c22("\u00a0")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 40 | |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 41 | self.assertTrue(in_table_c21_c22("\u009f")) |
| 42 | self.assertFalse(in_table_c21_c22("\u00a0")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 43 | |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 44 | self.assertTrue(in_table_c3("\ue000")) |
| 45 | self.assertFalse(in_table_c3("\uf900")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 46 | |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 47 | self.assertTrue(in_table_c4("\uffff")) |
| 48 | self.assertFalse(in_table_c4("\u0000")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 49 | |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 50 | self.assertTrue(in_table_c5("\ud800")) |
| 51 | self.assertFalse(in_table_c5("\ud7ff")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 52 | |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 53 | self.assertTrue(in_table_c6("\ufff9")) |
| 54 | self.assertFalse(in_table_c6("\ufffe")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 55 | |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 56 | self.assertTrue(in_table_c7("\u2ff0")) |
| 57 | self.assertFalse(in_table_c7("\u2ffc")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 58 | |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 59 | self.assertTrue(in_table_c8("\u0340")) |
| 60 | self.assertFalse(in_table_c8("\u0342")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 61 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 62 | # C.9 is not in the bmp |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 63 | # self.assertTrue(in_table_c9(u"\U000E0001")) |
| 64 | # self.assertFalse(in_table_c8(u"\U000E0002")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 65 | |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 66 | self.assertTrue(in_table_d1("\u05be")) |
| 67 | self.assertFalse(in_table_d1("\u05bf")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 68 | |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 69 | self.assertTrue(in_table_d2("\u0041")) |
| 70 | self.assertFalse(in_table_d2("\u0040")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 71 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 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. |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 76 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 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() |
| 91 | |
| 92 | def test_main(): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 93 | support.run_unittest(StringprepTests) |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 94 | |
| 95 | if __name__ == '__main__': |
| 96 | test_main() |