| 1 |
|
| 2 |
|
| 3 |
import sys, fontforge, unittest, re |
| 4 |
|
| 5 |
|
| 6 |
class UnicodeTests(unittest.TestCase): |
| 7 |
def test_UnicodeNameFromLib(self): |
| 8 |
for i in [-1, 0, 0x110000, 0x1100001]: |
| 9 |
self.assertEqual( |
| 10 |
"", fontforge.UnicodeNameFromLib(i), f"{i} should have no name" |
| 11 |
) |
| 12 |
|
| 13 |
|
| 14 |
self.assertEqual( |
| 15 |
"BOX DRAWINGS LIGHT DIAGONAL UPPER CENTRE TO MIDDLE RIGHT AND MIDDLE LEFT TO LOWER CENTRE", |
| 16 |
fontforge.UnicodeNameFromLib(0x1FBA9), |
| 17 |
) |
| 18 |
|
| 19 |
|
| 20 |
for i in range(0x110000): |
| 21 |
name = fontforge.UnicodeNameFromLib(i) |
| 22 |
self.assertTrue(name.isascii(), f"U+{i:04X} is all ascii") |
| 23 |
|
| 24 |
def test_UnicodeAnnotationFromLib(self): |
| 25 |
for i in [-1, 0x110000, 0x1100001]: |
| 26 |
self.assertEqual( |
| 27 |
"", |
| 28 |
fontforge.UnicodeAnnotationFromLib(i), |
| 29 |
f"{i} should have no annotation", |
| 30 |
) |
| 31 |
|
| 32 |
|
| 33 |
annot = fontforge.UnicodeAnnotationFromLib(0x27) |
| 34 |
self.assertTrue( |
| 35 |
annot.startswith("= apostrophe-quote (1.0)"), "apostrophe has annotation" |
| 36 |
) |
| 37 |
|
| 38 |
|
| 39 |
annot = fontforge.UnicodeAnnotationFromLib(0x2052) |
| 40 |
self.assertIn("abzüglich", annot) |
| 41 |
|
| 42 |
def test_unicode_blocks(self): |
| 43 |
self.assertGreater(fontforge.UnicodeBlockCountFromLib(), 0) |
| 44 |
for i in range(fontforge.UnicodeBlockCountFromLib()): |
| 45 |
self.assertGreater(len(fontforge.UnicodeBlockNameFromLib(i)), 0) |
| 46 |
self.assertGreaterEqual(fontforge.UnicodeBlockStartFromLib(i), 0) |
| 47 |
self.assertGreaterEqual( |
| 48 |
fontforge.UnicodeBlockEndFromLib(i), |
| 49 |
fontforge.UnicodeBlockStartFromLib(i), |
| 50 |
) |
| 51 |
|
| 52 |
def test_UnicodeNamesListVersion(self): |
| 53 |
self.assertIsNotNone( |
| 54 |
re.match( |
| 55 |
r"NamesList-Version: \d+(?:\.\d+)+", fontforge.UnicodeNamesListVersion() |
| 56 |
) |
| 57 |
) |
| 58 |
|
| 59 |
def test_UnicodeNames2FromLib(self): |
| 60 |
for i in [-1, 0, 1, 0x110000, 0x1100001]: |
| 61 |
self.assertEqual( |
| 62 |
"", |
| 63 |
fontforge.UnicodeNames2FromLib(i), |
| 64 |
f"{i} should have no formal alias", |
| 65 |
) |
| 66 |
self.assertEqual( |
| 67 |
"WEIERSTRASS ELLIPTIC FUNCTION", fontforge.UnicodeNames2FromLib(0x2118) |
| 68 |
) |
| 69 |
self.assertEqual( |
| 70 |
"PRESENTATION FORM FOR VERTICAL RIGHT WHITE LENTICULAR BRACKET", |
| 71 |
fontforge.UnicodeNames2FromLib(0xFE18), |
| 72 |
) |
| 73 |
|
| 74 |
|
| 75 |
if __name__ == "__main__": |
| 76 |
unittest.main() |