예제 #1
0
파일: cli.py 프로젝트: tale-lang/tale
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)
예제 #2
0
def test_wrong_indentation():
    # Arrange.
    program = """
x =
    1
   2
x
"""

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

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

    # Act.
    out = execute(program)

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

    # Act.
    out = execute(program)

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

    # Act.
    out = execute(program)

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

    # Act.
    out = execute(program)

    # Assert.
    assert out == 1
예제 #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
예제 #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
예제 #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
예제 #11
0
def test_not_matched_expression():
    # Arrange.
    program = """
(x) just = x
1 jusx
"""

    # Act.
    out = execute(program)

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

    # Act.
    out = execute(program)

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

    # Act.
    out = execute(program)

    # Assert.
    assert out == 1
예제 #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
예제 #15
0
def test_invalid_first_arg():
    # Arrange.
    program = """
x = py: 1
x
"""

    # Act.
    out = execute(program)

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

    # Act.
    out = execute(program)

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

    # Act.
    out = execute(program)

    # Assert.
    assert out == 1
예제 #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
예제 #19
0
def test_type():
    # Arrange.
    program = """
x = "a"
x type
"""

    # Act.
    out = execute(program)

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

    # Act.
    out = execute(program)

    # Assert.
    assert out == 1
예제 #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
예제 #22
0
def test_type():
    # Arrange.
    program = """
x = 1
x type
"""

    # Act.
    out = execute(program)

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

    # Act.
    out = execute(program)

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

-(-1)
"""

    # Act.
    out = execute(program)

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

1, 2 first
"""

    # Act.
    out = execute(program)

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

second: 1, 2
"""

    # Act.
    out = execute(program)

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

a + b + c + d
"""

    # Act.
    out = execute(program)

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

a + b
"""

    # Act.
    out = execute(program)

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

a + b
"""

    # Act.
    out = execute(program)

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

-1
"""

    # Act.
    out = execute(program)

    # Assert.
    assert out == 1