• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1from fontTools import agl
2import unittest
3
4
5class AglToUnicodeTest(unittest.TestCase):
6    def test_spec_examples(self):
7        # https://github.com/adobe-type-tools/agl-specification#3-examples
8        self.assertEqual(agl.toUnicode("Lcommaaccent"), "Ļ")
9        self.assertEqual(agl.toUnicode("uni20AC0308"), "\u20AC\u0308")
10        self.assertEqual(agl.toUnicode("u1040C"), "\U0001040C")
11        self.assertEqual(agl.toUnicode("uniD801DC0C"), "")
12        self.assertEqual(agl.toUnicode("uni20ac"), "")
13        self.assertEqual(
14            agl.toUnicode("Lcommaaccent_uni20AC0308_u1040C.alternate"),
15            "\u013B\u20AC\u0308\U0001040C")
16        self.assertEqual(agl.toUnicode("Lcommaaccent_uni013B_u013B"), "ĻĻĻ")
17        self.assertEqual(agl.toUnicode("foo"), "")
18        self.assertEqual(agl.toUnicode(".notdef"), "")
19
20    def test_aglfn(self):
21        self.assertEqual(agl.toUnicode("longs_t"), "ſt")
22        self.assertEqual(agl.toUnicode("f_f_i.alt123"), "ffi")
23
24    def test_uniABCD(self):
25        self.assertEqual(agl.toUnicode("uni0041"), "A")
26        self.assertEqual(agl.toUnicode("uni0041_uni0042_uni0043"), "ABC")
27        self.assertEqual(agl.toUnicode("uni004100420043"), "ABC")
28        self.assertEqual(agl.toUnicode("uni"), "")
29        self.assertEqual(agl.toUnicode("uni41"), "")
30        self.assertEqual(agl.toUnicode("uni004101"), "")
31        self.assertEqual(agl.toUnicode("uniDC00"), "")
32
33    def test_uABCD(self):
34        self.assertEqual(agl.toUnicode("u0041"), "A")
35        self.assertEqual(agl.toUnicode("u00041"), "A")
36        self.assertEqual(agl.toUnicode("u000041"), "A")
37        self.assertEqual(agl.toUnicode("u0000041"), "")
38        self.assertEqual(agl.toUnicode("u0041_uni0041_A.alt"), "AAA")
39
40    def test_union(self):
41        # Interesting test case because "uni" is a prefix of "union".
42        self.assertEqual(agl.toUnicode("union"), "∪")
43        # U+222A U+FE00 is a Standardized Variant for UNION WITH SERIFS.
44        self.assertEqual(agl.toUnicode("union_uniFE00"), "\u222A\uFE00")
45
46    def test_dingbats(self):
47        self.assertEqual(agl.toUnicode("a20", isZapfDingbats=True), "✔")
48        self.assertEqual(agl.toUnicode("a20.alt", isZapfDingbats=True), "✔")
49        self.assertEqual(agl.toUnicode("a206", isZapfDingbats=True), "❰")
50        self.assertEqual(agl.toUnicode("a20", isZapfDingbats=False), "")
51        self.assertEqual(agl.toUnicode("a0", isZapfDingbats=True), "")
52        self.assertEqual(agl.toUnicode("a207", isZapfDingbats=True), "")
53        self.assertEqual(agl.toUnicode("abcdef", isZapfDingbats=True), "")
54
55
56if __name__ == "__main__":
57    import sys
58    sys.exit(unittest.main())
59