def test_lex(self): # noqa -- this is formatted like real code source = """ if ( 4 ) { avariable = 1 + 1 anothervariable = a - 314 } """ # noqa -- this is formatted like real code expected_lexing = ['if', '(', '4', ')', '{', # noqa 'avariable', '=', '1', '+', '1', # noqa 'anothervariable', '=', 'a', '-', '314', # noqa '}'] result = lex(source) self.assertEqual(result, expected_lexing) # noqa -- this is formatted like real code source = """ function afunction ( a b c ) { avariable = 1 + 1 anothervariable = a - 314 return anothervariable } """ # noqa -- this is formatted like real code expected_lexing = ['function', 'afunction', '(', 'a', 'b', 'c', ')', '{', # noqa 'avariable', '=', '1', '+', '1', # noqa 'anothervariable', '=', 'a', '-', '314', # noqa 'return', 'anothervariable', '}'] result = lex(source) self.assertEqual(result, expected_lexing)
def interpret_helper(self, file_name): file_path = path.join(self.base_path, file_name) with open(file_path, 'r') as f: source = f.read() tokens = lex(source) ast = parse(tokens) scope = {} interpret_statement_list(None, ast, scope) return ast, scope