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