def test_peek_returns_next_opcode_without_changing_code_stream_location(): code_stream = CodeStream(b'\x01\x02\x30') assert code_stream.pc == 0 assert code_stream.peek() == opcode_values.ADD assert code_stream.pc == 0 assert next(code_stream) == opcode_values.ADD assert code_stream.pc == 1 assert code_stream.peek() == opcode_values.MUL assert code_stream.pc == 1
def test_seek_reverts_to_original_stream_position_when_context_exits(): code_stream = CodeStream(b'\x01\x02\x30') assert code_stream.pc == 0 with code_stream.seek(1): assert code_stream.pc == 1 assert next(code_stream) == opcode_values.MUL assert code_stream.pc == 0 assert code_stream.peek() == opcode_values.ADD