File: ast_test.py

package info (click to toggle)
fonttools 4.61.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,588 kB
  • sloc: python: 145,091; xml: 103; makefile: 24
file content (48 lines) | stat: -rw-r--r-- 1,564 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from fontTools.feaLib import ast
import unittest


class AstTest(unittest.TestCase):
    def test_glyphname_escape(self):
        statement = ast.GlyphClass()
        for name in ("BASE", "NULL", "foo", "a"):
            statement.append(ast.GlyphName(name))
        self.assertEqual(statement.asFea(), r"[\BASE \NULL foo a]")

    def test_valuerecord_none(self):
        statement = ast.ValueRecord(xPlacement=10, xAdvance=20)
        self.assertEqual(statement.asFea(), "<10 0 20 0>")

    def test_valuerecord_empty(self):
        statement = ast.ValueRecord()
        self.assertEqual(statement.asFea(), "<NULL>")

    def test_non_object_location(self):
        el = ast.Element(location=("file.fea", 1, 2))
        self.assertEqual(el.location.file, "file.fea")
        self.assertEqual(el.location.line, 1)
        self.assertEqual(el.location.column, 2)

    def test_single_pos_statement_empty_valuerecord(self):
        statement = ast.SinglePosStatement(
            pos=[(ast.GlyphName("a"), ast.ValueRecord())],
            prefix=[],
            suffix=[],
            forceChain=False,
        )
        self.assertEqual(statement.asFea(), "pos a <NULL>;")

    def test_single_pos_statement_empty_valuerecord_chain(self):
        statement = ast.SinglePosStatement(
            pos=[(ast.GlyphName("a"), ast.ValueRecord())],
            prefix=[],
            suffix=[],
            forceChain=True,
        )
        self.assertEqual(statement.asFea(), "pos a' <NULL>;")


if __name__ == "__main__":
    import sys

    sys.exit(unittest.main())