コード例 #1
0
ファイル: tests.py プロジェクト: fbaew/schoolwork
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
コード例 #2
0
ファイル: showOutput.py プロジェクト: fbaew/schoolwork
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)