|
| 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 | + |
| 4 | +from test.test_support import verify, vereq |
| 5 | +import sha |
| 6 | + |
| 7 | +import stringprep |
| 8 | +from stringprep import * |
| 9 | + |
| 10 | +verify(in_table_a1(u"\u0221")) |
| 11 | +verify(not in_table_a1(u"\u0222")) |
| 12 | + |
| 13 | +verify(in_table_b1(u"\u00ad")) |
| 14 | +verify(not in_table_b1(u"\u00ae")) |
| 15 | + |
| 16 | +verify(map_table_b2(u"\u0041"), u"\u0061") |
| 17 | +verify(map_table_b2(u"\u0061"), u"\u0061") |
| 18 | + |
| 19 | +verify(map_table_b3(u"\u0041"), u"\u0061") |
| 20 | +verify(map_table_b3(u"\u0061"), u"\u0061") |
| 21 | + |
| 22 | +verify(in_table_c11(u"\u0020")) |
| 23 | +verify(not in_table_c11(u"\u0021")) |
| 24 | + |
| 25 | +verify(in_table_c12(u"\u00a0")) |
| 26 | +verify(not in_table_c12(u"\u00a1")) |
| 27 | + |
| 28 | +verify(in_table_c12(u"\u00a0")) |
| 29 | +verify(not in_table_c12(u"\u00a1")) |
| 30 | + |
| 31 | +verify(in_table_c11_c12(u"\u00a0")) |
| 32 | +verify(not in_table_c11_c12(u"\u00a1")) |
| 33 | + |
| 34 | +verify(in_table_c21(u"\u001f")) |
| 35 | +verify(not in_table_c21(u"\u0020")) |
| 36 | + |
| 37 | +verify(in_table_c22(u"\u009f")) |
| 38 | +verify(not in_table_c22(u"\u00a0")) |
| 39 | + |
| 40 | +verify(in_table_c21_c22(u"\u009f")) |
| 41 | +verify(not in_table_c21_c22(u"\u00a0")) |
| 42 | + |
| 43 | +verify(in_table_c3(u"\ue000")) |
| 44 | +verify(not in_table_c3(u"\uf900")) |
| 45 | + |
| 46 | +verify(in_table_c4(u"\uffff")) |
| 47 | +verify(not in_table_c4(u"\u0000")) |
| 48 | + |
| 49 | +verify(in_table_c5(u"\ud800")) |
| 50 | +verify(not in_table_c5(u"\ud7ff")) |
| 51 | + |
| 52 | +verify(in_table_c6(u"\ufff9")) |
| 53 | +verify(not in_table_c6(u"\ufffe")) |
| 54 | + |
| 55 | +verify(in_table_c7(u"\u2ff0")) |
| 56 | +verify(not in_table_c7(u"\u2ffc")) |
| 57 | + |
| 58 | +verify(in_table_c8(u"\u0340")) |
| 59 | +verify(not in_table_c8(u"\u0342")) |
| 60 | + |
| 61 | +# C.9 is not in the bmp |
| 62 | +# verify(in_table_c9(u"\U000E0001")) |
| 63 | +# verify(not in_table_c8(u"\U000E0002")) |
| 64 | + |
| 65 | +verify(in_table_d1(u"\u05be")) |
| 66 | +verify(not in_table_d1(u"\u05bf")) |
| 67 | + |
| 68 | +verify(in_table_d2(u"\u0041")) |
| 69 | +verify(not in_table_d2(u"\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 | +# of the database. |
| 75 | + |
| 76 | +# predicates = [k for k in dir(stringprep) if k.startswith("in_table")] |
| 77 | +# predicates.sort() |
| 78 | +# for p in predicates: |
| 79 | +# f = getattr(stringprep, p) |
| 80 | +# # Collect all BMP code points |
| 81 | +# data = ["0"] * 0x10000 |
| 82 | +# for i in range(0x10000): |
| 83 | +# if f(unichr(i)): |
| 84 | +# data[i] = "1" |
| 85 | +# data = "".join(data) |
| 86 | +# h = sha.sha() |
| 87 | +# h.update(data) |
| 88 | +# print p,h.hexdigest() |
| 89 | + |
| 90 | + |
0 commit comments