[antlr-interest] antlr python unit testing
Laurie Harper
laurie at holoweb.net
Thu May 3 01:09:37 PDT 2007
I'm using ANTLR for Python and have my lexer and parser partially
working. I would like to start writing unit tests to identify exactly
what is and isn't right in what I have so far. (Call it test-first
debugging ;-)
This is a total newbie question but, how do I pass input into my lexer
or parser from a Python script, rather than having it come from stdin?
Ideally, I'd like to create a lexer instance and a parser instance and
then write unit tests that exercise specific rules with varying input,
al la:
import unittest
class LexerTests(unittest.TestCase):
def setUp(self):
self.L = lexer()
self.P = parser(self.L)
def test_lexer(self):
input = "specimen input"
# *****
self.L.INJECT_INPUT_CHARACTERS(input)
# *****
self.failUnlessEqual(some_result, self.L.nextToken())
def test_parser(self):
input = "specimen input"
# *****
self.L.INJECT_INPUT_CHARACTERS(input)
# *****
self.failUnlessEqual(some_result, self.P.someRule()
How do I achieve the INJECT_INPUT_CHARACTERS(input) part?
L.
More information about the antlr-interest
mailing list