def test_parse(self): lines = ['#this is a comment', '', 'mov eax, 2', 'nop'] self.assertEqual(len(Parser.parse_text(lines)), 2)
def run_program(program_file): lines = program_file.readlines() parser = Parser() instructions = parser.parse_text(lines) if len(instructions) == 0: die(1, 'nothing to run, aborting.') context = Context(instructions) view = MainView(100, 40, context) while True: view.paint() inp = input() if inp == 'r': context.run() elif inp == '': try: if not context.step(): break except Exception as e: die(1, str(e)) elif inp == 'a': die(0, 'exiting program.')
def test_parse_01(self): self.assertIsInstance(Parser.parse_text(['stc'])[0], Stc) self.assertIsInstance(Parser.parse_text(['clc'])[0], Clc)