Exemplo n.º 1
0
    def test_default_tape_length(self, finite_tape: FiniteTape) -> None:
        finite_tape.shift_right(29_999)

        with pytest.raises(OutOfBoundsError) as exc_info:
            finite_tape.shift_right(1)

        assert "Pointer is out of tape bounds" in str(exc_info.value)
Exemplo n.º 2
0
    def test_out_of_right_bound_error_do_not_change_tape_state(
            self, finite_tape: FiniteTape) -> None:
        finite_tape.set(1)

        with pytest.raises(OutOfBoundsError):
            finite_tape.shift_right(10)

        assert finite_tape.get() == 1
Exemplo n.º 3
0
def _create_machine() -> Machine:
    return MachineImpl(
        LexerImpl(),
        ParserImpl(),
        TranslatorImpl(),
        InterpreterImpl(FiniteTape()),
    )
Exemplo n.º 4
0
def machine() -> Machine:
    lexer = LexerImpl()
    parser = ParserImpl()
    translator = TranslatorImpl()
    interpreter = InterpreterImpl(FiniteTape())

    return MachineImpl(lexer, parser, translator, interpreter)
Exemplo n.º 5
0
def repl() -> Repl:
    return ReplImpl(
        MachineImpl(
            LexerImpl(),
            ParserImpl(),
            TranslatorImpl(),
            InterpreterImpl(FiniteTape()),
        ), )
Exemplo n.º 6
0
def repl() -> None:
    """Run brainfuck REPL."""
    ReplImpl(
        MachineImpl(
            LexerImpl(),
            ParserImpl(),
            TranslatorImpl(),
            InterpreterImpl(FiniteTape()),
        )
    ).run(sys.stdin, sys.stdout)
Exemplo n.º 7
0
def finite_tape(request: SubRequest) -> Tape:
    marker: t.Optional[Mark] = request.node.get_closest_marker("finite_tape_length")
    finite_tape_length = marker.args[0] if marker is not None else None

    return FiniteTape(finite_tape_length)
Exemplo n.º 8
0
import typing as t

import pytest
from _pytest.fixtures import SubRequest
from _pytest.mark import Mark

from bfpy.core.interpreter.tape import Tape, FiniteTape


@pytest.fixture
def finite_tape(request: SubRequest) -> Tape:
    marker: t.Optional[Mark] = request.node.get_closest_marker("finite_tape_length")
    finite_tape_length = marker.args[0] if marker is not None else None

    return FiniteTape(finite_tape_length)


@pytest.fixture(params=[FiniteTape()])
def tape(request: SubRequest) -> Tape:
    return t.cast(Tape, request.param)
Exemplo n.º 9
0
    def test_out_of_left_bound(self, finite_tape: FiniteTape,
                               steps: int) -> None:
        with pytest.raises(OutOfBoundsError) as exc_info:
            finite_tape.shift_left(steps)

        assert "Pointer is out of tape bounds" in str(exc_info.value)
Exemplo n.º 10
0
    def test_can_not_create_finite_tape_with_invalid_length(
            self, tape_length: int) -> None:
        with pytest.raises(ValueError) as exc_info:
            FiniteTape(tape_length)

        assert str(exc_info.value) == "Length of finite tape should be >= 0"
Exemplo n.º 11
0
def interpreter() -> Interpreter:
    return InterpreterImpl(FiniteTape())