def test_lexer_exposition(self): """Test Exposition tokens are as expected.""" correctlist = [] tokenlist = [] with open('sampleprograms/4_exposition.ntr') as f: m = lexer.LexerForNarratr() m.input(f.read()) t = m.token() while t: tokenlist.append(str(t)) t = m.token() with open('tests/lexed_exposition') as f: for line in f: correctlist.append(line.rstrip()) self.assertEqual(cmp(tokenlist, correctlist), 0, "Exposition lexing does not match expected tokens.")
def test_lexer_helloworld(self): """Test Hello World tokens are as expected.""" # some lists correctlist = [] tokenlist = [] # look at correct list of tokens with open('tests/lexed_helloworld') as f: for line in f: correctlist.append(line.rstrip()) # look at what lexer outputs with open('sampleprograms/0_helloworld.ntr') as f: m = lexer.LexerForNarratr() m.input(f.read()) t = m.token() while t: tokenlist.append(str(t)) t = m.token() # check for equivalence self.assertEqual(cmp(tokenlist, correctlist), 0, "Hello World lexing does not match expected tokens.")