2003-04-19 09:57:57 -03:00
|
|
|
# To fully test this module, we would need a copy of the stringprep tables.
|
2015-01-18 05:42:50 -04:00
|
|
|
# Since we don't have them, this test checks only a few code points.
|
2003-04-19 09:57:57 -03:00
|
|
|
|
2007-04-06 16:27:40 -03:00
|
|
|
import unittest
|
|
|
|
from test import test_support
|
2003-04-19 09:57:57 -03:00
|
|
|
|
|
|
|
from stringprep import *
|
|
|
|
|
2007-04-06 16:27:40 -03:00
|
|
|
class StringprepTests(unittest.TestCase):
|
|
|
|
def test(self):
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(in_table_a1(u"\u0221"))
|
|
|
|
self.assertFalse(in_table_a1(u"\u0222"))
|
2003-04-19 09:57:57 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(in_table_b1(u"\u00ad"))
|
|
|
|
self.assertFalse(in_table_b1(u"\u00ae"))
|
2003-04-19 09:57:57 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(map_table_b2(u"\u0041"), u"\u0061")
|
|
|
|
self.assertTrue(map_table_b2(u"\u0061"), u"\u0061")
|
2003-04-19 09:57:57 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(map_table_b3(u"\u0041"), u"\u0061")
|
|
|
|
self.assertTrue(map_table_b3(u"\u0061"), u"\u0061")
|
2003-04-19 09:57:57 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(in_table_c11(u"\u0020"))
|
|
|
|
self.assertFalse(in_table_c11(u"\u0021"))
|
2003-04-19 09:57:57 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(in_table_c12(u"\u00a0"))
|
|
|
|
self.assertFalse(in_table_c12(u"\u00a1"))
|
2003-04-19 09:57:57 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(in_table_c12(u"\u00a0"))
|
|
|
|
self.assertFalse(in_table_c12(u"\u00a1"))
|
2003-04-19 09:57:57 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(in_table_c11_c12(u"\u00a0"))
|
|
|
|
self.assertFalse(in_table_c11_c12(u"\u00a1"))
|
2003-04-19 09:57:57 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(in_table_c21(u"\u001f"))
|
|
|
|
self.assertFalse(in_table_c21(u"\u0020"))
|
2003-04-19 09:57:57 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(in_table_c22(u"\u009f"))
|
|
|
|
self.assertFalse(in_table_c22(u"\u00a0"))
|
2003-04-19 09:57:57 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(in_table_c21_c22(u"\u009f"))
|
|
|
|
self.assertFalse(in_table_c21_c22(u"\u00a0"))
|
2003-04-19 09:57:57 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(in_table_c3(u"\ue000"))
|
|
|
|
self.assertFalse(in_table_c3(u"\uf900"))
|
2003-04-19 09:57:57 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(in_table_c4(u"\uffff"))
|
|
|
|
self.assertFalse(in_table_c4(u"\u0000"))
|
2003-04-19 09:57:57 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(in_table_c5(u"\ud800"))
|
|
|
|
self.assertFalse(in_table_c5(u"\ud7ff"))
|
2003-04-19 09:57:57 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(in_table_c6(u"\ufff9"))
|
|
|
|
self.assertFalse(in_table_c6(u"\ufffe"))
|
2003-04-19 09:57:57 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(in_table_c7(u"\u2ff0"))
|
|
|
|
self.assertFalse(in_table_c7(u"\u2ffc"))
|
2003-04-19 09:57:57 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(in_table_c8(u"\u0340"))
|
|
|
|
self.assertFalse(in_table_c8(u"\u0342"))
|
2003-04-19 09:57:57 -03:00
|
|
|
|
2007-04-06 16:27:40 -03:00
|
|
|
# C.9 is not in the bmp
|
2009-06-30 19:57:08 -03:00
|
|
|
# self.assertTrue(in_table_c9(u"\U000E0001"))
|
|
|
|
# self.assertFalse(in_table_c8(u"\U000E0002"))
|
2003-04-19 09:57:57 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(in_table_d1(u"\u05be"))
|
|
|
|
self.assertFalse(in_table_d1(u"\u05bf"))
|
2003-04-19 09:57:57 -03:00
|
|
|
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(in_table_d2(u"\u0041"))
|
|
|
|
self.assertFalse(in_table_d2(u"\u0040"))
|
2003-04-19 09:57:57 -03:00
|
|
|
|
2007-04-06 16:27:40 -03:00
|
|
|
# This would generate a hash of all predicates. However, running
|
|
|
|
# it is quite expensive, and only serves to detect changes in the
|
|
|
|
# unicode database. Instead, stringprep.py asserts the version of
|
|
|
|
# the database.
|
2003-04-19 09:57:57 -03:00
|
|
|
|
2007-04-06 16:27:40 -03:00
|
|
|
# import hashlib
|
|
|
|
# predicates = [k for k in dir(stringprep) if k.startswith("in_table")]
|
|
|
|
# predicates.sort()
|
|
|
|
# for p in predicates:
|
|
|
|
# f = getattr(stringprep, p)
|
|
|
|
# # Collect all BMP code points
|
|
|
|
# data = ["0"] * 0x10000
|
|
|
|
# for i in range(0x10000):
|
|
|
|
# if f(unichr(i)):
|
|
|
|
# data[i] = "1"
|
|
|
|
# data = "".join(data)
|
|
|
|
# h = hashlib.sha1()
|
|
|
|
# h.update(data)
|
|
|
|
# print p, h.hexdigest()
|
|
|
|
|
|
|
|
def test_main():
|
|
|
|
test_support.run_unittest(StringprepTests)
|
2007-04-25 03:30:05 -03:00
|
|
|
|
2007-04-06 16:27:40 -03:00
|
|
|
if __name__ == '__main__':
|
|
|
|
test_main()
|