def test_load_file(): fld = Field.load_file("tests/fld_test_program.txt") assert fld.width == 11 assert fld.height == 5 assert fld.get_symbol_at(0, 0) == ' ' assert fld.get_symbol_at(10, 0) == 'v' assert fld.get_symbol_at(10, 4) == '<' assert fld.get_symbol_at(0, 4) == '^'
def test_field_print(): try: field = Field.load_file("tests/fld_test_program.txt") stack = Stack() caret = Caret(stack, field, True) term = Terminal() runner.print_field(caret, field, term) except Exception as e: raise e
def main(execute=True): term = Terminal() if from_file: field = Field.load_file(filename) elif from_pipe: lines = sys.stdin.readlines() text = lines[0] for line in lines: text += line program = text field = Field.from_text(program) else: return stack = Stack() caret = Caret(stack, field, max(3, to_int(term.height) - field.height), debug) if debug: logger.set_output(caret) caret.executor.execute = execute logger.debug("Objects created") # if super_debug: # input("Continue?") if debug: try: char = readchar() if char == 'c': print('\nForced exit') return except Exception: print("You shouldn't use pipe without -p option") return # field height shouldn't change print_field(caret, field, term) caret.read_instruction(field) caret.execute_instruction() if caret.direction == Vec(0, 0): caret.direction = Right logger.debug("Starting loop") while caret.executor.execute: caret.move(field) caret.read_instruction(field) if debug or super_debug: print_field(caret, field, term) else: print(caret.diff, end='') caret.execute_instruction() if debug: char = readchar() if char == 'c': print('\nForced exit') return logger.debug("Move performed") print()