def doTest(testInput, expectedOutput): ''' Takes as input a string containing the name of the test file to be scanned, and a list containing the expected tokens (in order, of course.) Returns a boolean value indicating whether the test passed. ''' data = "" testCaseFile = open(testInput) for line in testCaseFile.readlines(): data += line mLexer = scanner.doScan(data) tokens = [] for tok in mLexer: #iter(mLexer.token, None): tokens += [repr(tok.type).strip("'")] if (tokens != expectedOutput): print "" print "What we expected:", expectedOutput print " What we found:", tokens return tokens == expectedOutput
import scanner import sys data = "" for line in sys.stdin.readlines(): data += line mLexer = scanner.doScan(data) for tok in mLexer: # iter(mLexer.token, None): print repr(tok.type), repr(tok.value)