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 |
| 5 | from test import test_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): |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 11 | self.failUnless(in_table_a1("\u0221")) |
| 12 | self.failIf(in_table_a1("\u0222")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 13 | |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 14 | self.failUnless(in_table_b1("\u00ad")) |
| 15 | self.failIf(in_table_b1("\u00ae")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 16 | |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 17 | self.failUnless(map_table_b2("\u0041"), "\u0061") |
| 18 | self.failUnless(map_table_b2("\u0061"), "\u0061") |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 19 | |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 20 | self.failUnless(map_table_b3("\u0041"), "\u0061") |
| 21 | self.failUnless(map_table_b3("\u0061"), "\u0061") |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 22 | |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 23 | self.failUnless(in_table_c11("\u0020")) |
| 24 | self.failIf(in_table_c11("\u0021")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 25 | |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 26 | self.failUnless(in_table_c12("\u00a0")) |
| 27 | self.failIf(in_table_c12("\u00a1")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 28 | |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 29 | self.failUnless(in_table_c12("\u00a0")) |
| 30 | self.failIf(in_table_c12("\u00a1")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 31 | |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 32 | self.failUnless(in_table_c11_c12("\u00a0")) |
| 33 | self.failIf(in_table_c11_c12("\u00a1")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 34 | |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 35 | self.failUnless(in_table_c21("\u001f")) |
| 36 | self.failIf(in_table_c21("\u0020")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 37 | |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 38 | self.failUnless(in_table_c22("\u009f")) |
| 39 | self.failIf(in_table_c22("\u00a0")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 40 | |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 41 | self.failUnless(in_table_c21_c22("\u009f")) |
| 42 | self.failIf(in_table_c21_c22("\u00a0")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 43 | |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 44 | self.failUnless(in_table_c3("\ue000")) |
| 45 | self.failIf(in_table_c3("\uf900")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 46 | |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 47 | self.failUnless(in_table_c4("\uffff")) |
| 48 | self.failIf(in_table_c4("\u0000")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 49 | |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 50 | self.failUnless(in_table_c5("\ud800")) |
| 51 | self.failIf(in_table_c5("\ud7ff")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 52 | |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 53 | self.failUnless(in_table_c6("\ufff9")) |
| 54 | self.failIf(in_table_c6("\ufffe")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 55 | |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 56 | self.failUnless(in_table_c7("\u2ff0")) |
| 57 | self.failIf(in_table_c7("\u2ffc")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 58 | |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 59 | self.failUnless(in_table_c8("\u0340")) |
| 60 | self.failIf(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 |
| 63 | # self.failUnless(in_table_c9(u"\U000E0001")) |
| 64 | # self.failIf(in_table_c8(u"\U000E0002")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 65 | |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 66 | self.failUnless(in_table_d1("\u05be")) |
| 67 | self.failIf(in_table_d1("\u05bf")) |
Martin v. Löwis | b4cb664 | 2003-04-19 12:57:57 +0000 | [diff] [blame] | 68 | |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 69 | self.failUnless(in_table_d2("\u0041")) |
| 70 | self.failIf(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(): |
| 93 | test_support.run_unittest(StringprepTests) |
| 94 | |
| 95 | if __name__ == '__main__': |
| 96 | test_main() |