2015-09-30 09:49:41 +01:00
|
|
|
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")]
|
|
|
|
|
2015-12-08 16:33:34 +00:00
|
|
|
|
2015-09-30 09:49:41 +01:00
|
|
|
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):
|
2022-12-13 11:26:36 +00:00
|
|
|
self.assertEqual(
|
|
|
|
lex('"foo" "bar"'), [(Lexer.STRING, "foo"), (Lexer.STRING, "bar")]
|
|
|
|
)
|
2015-09-30 09:49:41 +01:00
|
|
|
self.assertRaises(VoltLibError, lambda: lex('"foo\n bar"'))
|
|
|
|
|
2015-10-07 14:04:59 +01:00
|
|
|
def test_name(self):
|
2022-12-13 11:26:36 +00:00
|
|
|
self.assertEqual(
|
|
|
|
lex("DEF_FOO bar.alt1"), [(Lexer.NAME, "DEF_FOO"), (Lexer.NAME, "bar.alt1")]
|
|
|
|
)
|
2015-10-07 14:04:59 +01:00
|
|
|
|
2015-09-30 09:49:41 +01:00
|
|
|
def test_number(self):
|
2022-12-13 11:26:36 +00:00
|
|
|
self.assertEqual(lex("123 -456"), [(Lexer.NUMBER, 123), (Lexer.NUMBER, -456)])
|
|
|
|
|
2015-09-30 09:49:41 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2017-01-11 13:05:35 +00:00
|
|
|
import sys
|
2022-12-13 11:26:36 +00:00
|
|
|
|
2017-01-11 13:05:35 +00:00
|
|
|
sys.exit(unittest.main())
|