1# -*- coding: utf-8 -*- 2from __future__ import (print_function, division, absolute_import, 3 unicode_literals) 4from fontTools.misc.py23 import * 5from fontTools import agl 6import unittest 7 8 9class AglToUnicodeTest(unittest.TestCase): 10 def test_spec_examples(self): 11 # https://github.com/adobe-type-tools/agl-specification#3-examples 12 # 13 # TODO: Currently, we only handle AGLFN instead of legacy AGL names. 14 # Therefore, the test cases below use Iogonek instead of Lcommaaccent. 15 # Change Iogonek to Lcommaaccent as soon as the implementation has 16 # been fixed to also support legacy AGL names. 17 # https://github.com/fonttools/fonttools/issues/775 18 self.assertEqual(agl.toUnicode("Iogonek"), "Į") 19 self.assertEqual(agl.toUnicode("uni20AC0308"), "\u20AC\u0308") 20 self.assertEqual(agl.toUnicode("u1040C"), "\U0001040C") 21 self.assertEqual(agl.toUnicode("uniD801DC0C"), "") 22 self.assertEqual(agl.toUnicode("uni20ac"), "") 23 self.assertEqual( 24 agl.toUnicode("Iogonek_uni20AC0308_u1040C.alternate"), 25 "\u012E\u20AC\u0308\U0001040C") 26 self.assertEqual(agl.toUnicode("Iogonek_uni012E_u012E"), "ĮĮĮ") 27 self.assertEqual(agl.toUnicode("foo"), "") 28 self.assertEqual(agl.toUnicode(".notdef"), "") 29 30 def test_aglfn(self): 31 self.assertEqual(agl.toUnicode("longs_t"), "ſt") 32 self.assertEqual(agl.toUnicode("f_f_i.alt123"), "ffi") 33 34 def test_uniABCD(self): 35 self.assertEqual(agl.toUnicode("uni0041"), "A") 36 self.assertEqual(agl.toUnicode("uni0041_uni0042_uni0043"), "ABC") 37 self.assertEqual(agl.toUnicode("uni004100420043"), "ABC") 38 self.assertEqual(agl.toUnicode("uni"), "") 39 self.assertEqual(agl.toUnicode("uni41"), "") 40 self.assertEqual(agl.toUnicode("uni004101"), "") 41 self.assertEqual(agl.toUnicode("uniDC00"), "") 42 43 def test_uABCD(self): 44 self.assertEqual(agl.toUnicode("u0041"), "A") 45 self.assertEqual(agl.toUnicode("u00041"), "A") 46 self.assertEqual(agl.toUnicode("u000041"), "A") 47 self.assertEqual(agl.toUnicode("u0000041"), "") 48 self.assertEqual(agl.toUnicode("u0041_uni0041_A.alt"), "AAA") 49 50 def test_union(self): 51 # Interesting test case because "uni" is a prefix of "union". 52 self.assertEqual(agl.toUnicode("union"), "∪") 53 # U+222A U+FE00 is a Standardized Variant for UNION WITH SERIFS. 54 self.assertEqual(agl.toUnicode("union_uniFE00"), "\u222A\uFE00") 55 56 def test_dingbats(self): 57 self.assertEqual(agl.toUnicode("a20", isZapfDingbats=True), "✔") 58 self.assertEqual(agl.toUnicode("a20.alt", isZapfDingbats=True), "✔") 59 self.assertEqual(agl.toUnicode("a206", isZapfDingbats=True), "❰") 60 self.assertEqual(agl.toUnicode("a20", isZapfDingbats=False), "") 61 self.assertEqual(agl.toUnicode("a0", isZapfDingbats=True), "") 62 self.assertEqual(agl.toUnicode("a207", isZapfDingbats=True), "") 63 self.assertEqual(agl.toUnicode("abcdef", isZapfDingbats=True), "") 64 65 66if __name__ == "__main__": 67 import sys 68 sys.exit(unittest.main()) 69