Repository navigation
Expand file tree
/
Copy pathtestrecognizers.py
More file actions
67 lines (44 loc) · 1.53 KB
/
Copy pathtestrecognizers.py
File metadata and controls
67 lines (44 loc) · 1.53 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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))