Exemplo n.º 1
0
def test_sub_nonexistant_file(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text(
        """
        HOWTO Test scriic
        SUB ./nonexistant.sub
        """
    )

    runner = FileRunner(tmp_file.absolute())
    with pytest.raises(FileNotFoundError):
        runner.run()
Exemplo n.º 2
0
def test_sub_param_and_return(tmp_path):
    tmp_file_1 = tmp_path / "test1.scriic"
    tmp_file_1.write_text(
        """
        HOWTO Test scriic
        val = SUB ./test2.scriic
        PRM param = ABC
        GO
        DO Subscriic returned [val]
        """
    )

    tmp_file_2 = tmp_path / "test2.scriic"
    tmp_file_2.write_text(
        """
        HOWTO Test subscriic with <param>
        DO Received [param]
        RETURN DEF
        """
    )

    runner = FileRunner(tmp_file_1.absolute())
    instruction = runner.run()

    assert len(instruction.children) == 2
    assert instruction.children[0].text() == "Test subscriic with ABC"
    assert len(instruction.children[0].children) == 1
    assert instruction.children[0].children[0].text() == "Received ABC"
    assert instruction.children[1].text() == "Subscriic returned DEF"
Exemplo n.º 3
0
def test_sub_return(tmp_path):
    tmp_file_1 = tmp_path / "test1.scriic"
    tmp_file_1.write_text(
        """
        HOWTO Test scriic
        val = SUB ./test2.scriic
        DO Subscriic returned [val]
        """
    )

    tmp_file_2 = tmp_path / "test2.scriic"
    tmp_file_2.write_text(
        """
        HOWTO Test subscriic
        RETURN ABC
        """
    )

    runner = FileRunner(tmp_file_1.absolute())
    instruction = runner.run()

    assert len(instruction.children) == 2
    assert instruction.children[0].text() == "Test subscriic"
    assert len(instruction.children[0].children) == 0
    assert instruction.children[1].text() == "Subscriic returned ABC"
Exemplo n.º 4
0
def test_sub(tmp_path):
    tmp_file_1 = tmp_path / "test1.scriic"
    tmp_file_1.write_text(
        """
        HOWTO Test scriic
        DO This is in file 1
        SUB ./test2.scriic
        """
    )

    tmp_file_2 = tmp_path / "test2.scriic"
    tmp_file_2.write_text(
        """
        HOWTO Test subscriic
        DO This is in file 2
        """
    )

    runner = FileRunner(tmp_file_1.absolute())
    instruction = runner.run()

    assert len(instruction.children) == 2
    assert instruction.children[0].text() == "This is in file 1"
    assert instruction.children[1].text() == "Test subscriic"
    assert len(instruction.children[1].children) == 1
    assert instruction.children[1].children[0].text() == "This is in file 2"
Exemplo n.º 5
0
def test_sub_param(tmp_path):
    tmp_file_1 = tmp_path / "test1.scriic"
    tmp_file_1.write_text(
        """
        HOWTO Test scriic with <param>
        DO This is in file 1

        SUB ./test2.scriic
        PRM param = [param]
        GO
        """
    )

    tmp_file_2 = tmp_path / "test2.scriic"
    tmp_file_2.write_text(
        """
        HOWTO Test subscriic with <param>
        DO The value of param is [param]
        """
    )

    runner = FileRunner(tmp_file_1.absolute())
    instruction = runner.run({"param": "ABC"})

    assert len(instruction.children) == 2
    assert instruction.children[0].text() == "This is in file 1"
    assert instruction.children[1].text() == "Test subscriic with ABC"
    assert len(instruction.children[1].children) == 1
    assert instruction.children[1].children[0].text() == "The value of param is ABC"
Exemplo n.º 6
0
def test_unfinished_sub(tmp_path):
    tmp_file_1 = tmp_path / "test1.scriic"
    tmp_file_1.write_text(
        """
        HOWTO Test scriic
        SUB ./test2.scriic
        """
    )

    tmp_file_2 = tmp_path / "test2.scriic"
    tmp_file_2.write_text(
        """
        HOWTO Test subscriic with <param>
        """
    )

    runner = FileRunner(tmp_file_1.absolute())
    with pytest.raises(ScriicRuntimeException):
        runner.run()
Exemplo n.º 7
0
def test_title(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text("""
        HOWTO Test <param>
        """)

    runner = FileRunner(tmp_file.absolute())
    instruction = runner.run({"param": "scriic"})

    assert instruction.text() == "Test scriic"
    assert len(instruction.children) == 0
Exemplo n.º 8
0
def test_do_substitution(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text("""
        HOWTO Test <var>
        DO Test [var]!
        """)

    runner = FileRunner(tmp_file.absolute())
    instruction = runner.run({"var": "scriic"})

    assert instruction.children[0].text() == "Test scriic!"
Exemplo n.º 9
0
def test_sub_missing_return(tmp_path):
    tmp_file_1 = tmp_path / "test1.scriic"
    tmp_file_1.write_text(
        """
        HOWTO Test scriic
        val = SUB ./test2.scriic
        """
    )

    tmp_file_2 = tmp_path / "test2.scriic"
    tmp_file_2.write_text(
        """
        HOWTO Test subscriic
        DO not return anything
        """
    )

    runner = FileRunner(tmp_file_1.absolute())
    with pytest.raises(ScriicRuntimeException):
        runner.run()
Exemplo n.º 10
0
def test_do(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text("""
        HOWTO Test scriic
        DO Test scriic!
        DO Test scriic again!
        """)

    runner = FileRunner(tmp_file.absolute())
    instruction = runner.run()

    assert instruction.children[0].text() == "Test scriic!"
    assert instruction.children[1].text() == "Test scriic again!"
Exemplo n.º 11
0
def test_repeat_known(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text("""
        HOWTO Test scriic
        REPEAT 5
            DO Something
        END
        """)

    runner = FileRunner(tmp_file.absolute())
    instruction = runner.run()

    assert len(instruction.children) == 5
    for child in instruction.children:
        assert child.text() == "Something"
Exemplo n.º 12
0
def test_letters_known(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text("""
        HOWTO Test scriic
        char = LETTERS Hello
            DO [char]
        END
        """)

    runner = FileRunner(tmp_file.absolute())
    instruction = runner.run()

    assert len(instruction.children) == 5
    for i, char in enumerate("Hello"):
        assert instruction.children[i].text() == char
Exemplo n.º 13
0
def test_letters_no_var(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text("""
        HOWTO Test scriic
        LETTERS Hello
            DO Something
        END
        """)

    runner = FileRunner(tmp_file.absolute())
    instruction = runner.run()

    assert len(instruction.children) == 5
    for i in range(5):
        assert instruction.children[i].text() == "Something"
Exemplo n.º 14
0
def test_do_with_variable(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text("""
        HOWTO Test scriic
        var = DO Get some value
        DO Read [var]
        """)

    runner = FileRunner(tmp_file.absolute())
    instruction = runner.run()

    assert len(instruction.children) == 2
    assert instruction.children[0].text() == "Get some value"

    instruction.children[0].display_index = 1
    assert instruction.children[1].text() == "Read the result of instruction 1"
Exemplo n.º 15
0
def test_repeat_unknown(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text("""
        HOWTO Test scriic
        times = DO Get a number
        REPEAT times
            DO Something
        END
        """)

    runner = FileRunner(tmp_file.absolute())
    instruction = runner.run()

    assert len(instruction.children) == 3
    assert instruction.children[0].text() == "Get a number"
    instruction.children[0].display_index = 1
    assert instruction.children[1].text() == "Something"
    instruction.children[1].display_index = 2
    assert instruction.children[2].text() == (
        "Go to instruction 2 and repeat the number of times from instruction 1"
    )
Exemplo n.º 16
0
def test_letters_unknown(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text("""
        HOWTO Test scriic
        string = DO Get a string
        char = LETTERS [string]
            DO Say [char"]
        END
        """)

    runner = FileRunner(tmp_file.absolute())
    instruction = runner.run()

    assert len(instruction.children) == 4
    assert instruction.children[0].text() == "Get a string"
    instruction.children[0].display_index = 1
    assert instruction.children[1].text() == (
        "Get the first letter of the result of instruction 1, or the next letter "
        "if you are returning from a future instruction")
    instruction.children[1].display_index = 2
    assert instruction.children[2].text() == "Say the result of instruction 2"
    assert instruction.children[3].text() == (
        "If you haven't yet reached the last letter of the result of "
        "instruction 1, go to instruction 2")