aboutsummaryrefslogtreecommitdiff
path: root/Tests/voltLib/lexer_test.py
blob: a8e849b10bf79d8cfeaaa63c34ac96108342b7ea (plain)
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())