Example #1
0
def cli(program, rebuild):
    """Interprets a PROGRAM file as a Tale program."""

    if rebuild:
        rebuild_grammar()

    from tale.core import execute

    code = program.read()
    execute(code)
Example #2
0
def test_wrong_indentation():
    # Arrange.
    program = """
x =
    1
   2
x
"""

    # Act & Assert.
    with pytest.raises(Exception):
        execute(program)
Example #3
0
def test_invalid_comment():
    # Arrange.
    program = """
- A.
1
"""

    # Act & Assert.
    with pytest.raises(Exception):
        out = execute(program)
Example #4
0
def test_minus_operator():
    # Arrange.
    program = """
2 - 1
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 1
Example #5
0
def test_one_expression():
    # Arrange.
    program = """
x
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 'x'
Example #6
0
def test_plus_operator():
    # Arrange.
    program = """
1 + 2
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 3
Example #7
0
def test_simple_keyword_form_returns_arg():
    # Arrange.
    program = """
just: (x) = x
just: 1
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 1
Example #8
0
def test_keyword_form_with_prefix_first_arg():
    # Arrange.
    program = """
(x) just: (y) = x
1 just: 2
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 1
Example #9
0
def test_same_unary_form_called_many_times():
    # Arrange.
    program = """
(x) just = x
1 just just
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 1
Example #10
0
def test_pattern_matching_of_keyword_form_with_prefix():
    # Arrange.
    program = """
1 plus: 2 = 3
1 plus: 2
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 3
Example #11
0
def test_not_matched_expression():
    # Arrange.
    program = """
(x) just = x
1 jusx
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == '1jusx'
Example #12
0
def test_two_expressions():
    # Arrange.
    program = """
x
y
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 'y'
Example #13
0
def test_overriden():
    # Arrange.
    program = """
py: (x) = x
py: 1
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 1
Example #14
0
def test_random():
    # Arrange.
    program = """
x = py: "import random; result = random.randint", 1, 1
x
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 1
Example #15
0
def test_invalid_first_arg():
    # Arrange.
    program = """
x = py: 1
x
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 'py:1'
Example #16
0
def test_one_comment():
    # Arrange.
    program = """
-- A.
1
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 1
Example #17
0
def test_simple_keyword_form():
    # Arrange.
    program = """
just: (x) = 1
just: 2
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 1
Example #18
0
def test_keyword_form_has_less_priority_than_binary():
    # Arrange.
    program = """
just: (x) = x
just: 1 + 2
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 3
Example #19
0
def test_type():
    # Arrange.
    program = """
x = "a"
x type
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 'String'
Example #20
0
def test_simple_assignment():
    # Arrange.
    program = """
(x) just = x
1 just
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 1
Example #21
0
def test_keyword_form_with_two_parts_second_arg():
    # Arrange.
    program = """
add: (x) to: (y) = y
add: 1 to: 2
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 2
Example #22
0
def test_type():
    # Arrange.
    program = """
x = 1
x type
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 'Int'
def test_simple_form():
    # Arrange.
    program = """
-(x) = x
-1
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 1
Example #24
0
def test_multiple_prefix_operators_in_expression():
    # Arrange.
    program = """
-(x) = x + 1

-(-1)
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 3
Example #25
0
def test_unary():
    # Arrange.
    program = """
(x), (y) first = x

1, 2 first
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 1
Example #26
0
def test_keyword():
    # Arrange.
    program = """
second: (x), (y) = y

second: 1, 2
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 2
Example #27
0
def test_compound_binary_expression():
    # Arrange.
    program = """
(x) + (y) = y

a + b + c + d
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 'd'
Example #28
0
def test_first_argument():
    # Arrange.
    program = """
(x) + (y) = x

a + b
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 'a'
Example #29
0
def test_second_argument():
    # Arrange.
    program = """
(x) + (y) = y

a + b
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 'b'
Example #30
0
def test_simple_prefix_operator():
    # Arrange.
    program = """
-(x) = x

-1
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 1