Exemplo n.º 1
0
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 code_stream.next() == opcode_values.ADD
    assert code_stream.pc == 1
    assert code_stream.peek() == opcode_values.MUL
    assert code_stream.pc == 1
Exemplo n.º 2
0
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 code_stream.next() == opcode_values.ADD
    assert code_stream.pc == 1
    assert code_stream.peek() == opcode_values.MUL
    assert code_stream.pc == 1
Exemplo n.º 3
0
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 code_stream.next() == opcode_values.MUL
    assert code_stream.pc == 0
    assert code_stream.peek() == opcode_values.ADD
Exemplo n.º 4
0
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 code_stream.next() == opcode_values.MUL
    assert code_stream.pc == 0
    assert code_stream.peek() == opcode_values.ADD