File: lexer_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 (36 lines) | stat: -rw-r--r-- 971 bytes parent folder | download | duplicates (4)
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
from fontTools.voltLib.error import VoltLibError
from fontTools.voltLib.lexer import Lexer
import unittest


def lex(s):
    return [(typ, tok) for (typ, tok, _) in Lexer(s, "test.vtp")]


class LexerTest(unittest.TestCase):
    def __init__(self, methodName):
        unittest.TestCase.__init__(self, methodName)

    def test_empty(self):
        self.assertEqual(lex(""), [])
        self.assertEqual(lex("\t"), [])

    def test_string(self):
        self.assertEqual(
            lex('"foo" "bar"'), [(Lexer.STRING, "foo"), (Lexer.STRING, "bar")]
        )
        self.assertRaises(VoltLibError, lambda: lex('"foo\n bar"'))

    def test_name(self):
        self.assertEqual(
            lex("DEF_FOO bar.alt1"), [(Lexer.NAME, "DEF_FOO"), (Lexer.NAME, "bar.alt1")]
        )

    def test_number(self):
        self.assertEqual(lex("123 -456"), [(Lexer.NUMBER, 123), (Lexer.NUMBER, -456)])


if __name__ == "__main__":
    import sys

    sys.exit(unittest.main())