1from __future__ import print_function, division, absolute_import
2from __future__ import unicode_literals
3from fontTools.voltLib.error import VoltLibError
4from fontTools.voltLib.lexer import Lexer
5import unittest
6
7
8def lex(s):
9    return [(typ, tok) for (typ, tok, _) in Lexer(s, "test.vtp")]
10
11
12class LexerTest(unittest.TestCase):
13    def __init__(self, methodName):
14        unittest.TestCase.__init__(self, methodName)
15
16    def test_empty(self):
17        self.assertEqual(lex(""), [])
18        self.assertEqual(lex("\t"), [])
19
20    def test_string(self):
21        self.assertEqual(lex('"foo" "bar"'),
22                         [(Lexer.STRING, "foo"), (Lexer.STRING, "bar")])
23        self.assertRaises(VoltLibError, lambda: lex('"foo\n bar"'))
24
25    def test_name(self):
26        self.assertEqual(lex('DEF_FOO bar.alt1'),
27                         [(Lexer.NAME, "DEF_FOO"), (Lexer.NAME, "bar.alt1")])
28
29    def test_number(self):
30        self.assertEqual(lex("123 -456"),
31                         [(Lexer.NUMBER, 123), (Lexer.NUMBER, -456)])
32
33if __name__ == "__main__":
34    import sys
35    sys.exit(unittest.main())
36