You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.5 KiB
68 lines
1.5 KiB
import sys
|
|
import unittest
|
|
|
|
import antlr3
|
|
|
|
|
|
class TestBaseRecognizer(unittest.TestCase):
|
|
"""Tests for BaseRecognizer class"""
|
|
|
|
def testGetRuleInvocationStack(self):
|
|
"""BaseRecognizer._getRuleInvocationStack()"""
|
|
|
|
rules = antlr3.BaseRecognizer._getRuleInvocationStack(__name__)
|
|
self.assertEqual(
|
|
rules,
|
|
['testGetRuleInvocationStack']
|
|
)
|
|
|
|
|
|
class TestTokenSource(unittest.TestCase):
|
|
"""Testcase to the antlr3.TokenSource class"""
|
|
|
|
|
|
def testIteratorInterface(self):
|
|
"""TokenSource.next()"""
|
|
|
|
class TrivialToken(object):
|
|
def __init__(self, type):
|
|
self.type = type
|
|
|
|
class TestSource(antlr3.TokenSource):
|
|
def __init__(self):
|
|
self.tokens = [
|
|
TrivialToken(1),
|
|
TrivialToken(2),
|
|
TrivialToken(3),
|
|
TrivialToken(4),
|
|
TrivialToken(antlr3.EOF),
|
|
]
|
|
|
|
def nextToken(self):
|
|
return self.tokens.pop(0)
|
|
|
|
|
|
src = TestSource()
|
|
tokens = []
|
|
for token in src:
|
|
tokens.append(token.type)
|
|
|
|
self.assertEqual(tokens, [1, 2, 3, 4])
|
|
|
|
|
|
|
|
class TestLexer(unittest.TestCase):
|
|
|
|
def testInit(self):
|
|
"""Lexer.__init__()"""
|
|
|
|
class TLexer(antlr3.Lexer):
|
|
api_version = 'HEAD'
|
|
|
|
stream = antlr3.StringStream('foo')
|
|
TLexer(stream)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main(testRunner=unittest.TextTestRunner(verbosity=2))
|