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)
def test_wrong_indentation(): # Arrange. program = """ x = 1 2 x """ # Act & Assert. with pytest.raises(Exception): execute(program)
def test_invalid_comment(): # Arrange. program = """ - A. 1 """ # Act & Assert. with pytest.raises(Exception): out = execute(program)
def test_minus_operator(): # Arrange. program = """ 2 - 1 """ # Act. out = execute(program) # Assert. assert out == 1
def test_one_expression(): # Arrange. program = """ x """ # Act. out = execute(program) # Assert. assert out == 'x'
def test_plus_operator(): # Arrange. program = """ 1 + 2 """ # Act. out = execute(program) # Assert. assert out == 3
def test_simple_keyword_form_returns_arg(): # Arrange. program = """ just: (x) = x just: 1 """ # Act. out = execute(program) # Assert. assert out == 1
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
def test_same_unary_form_called_many_times(): # Arrange. program = """ (x) just = x 1 just just """ # Act. out = execute(program) # Assert. assert out == 1
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
def test_not_matched_expression(): # Arrange. program = """ (x) just = x 1 jusx """ # Act. out = execute(program) # Assert. assert out == '1jusx'
def test_two_expressions(): # Arrange. program = """ x y """ # Act. out = execute(program) # Assert. assert out == 'y'
def test_overriden(): # Arrange. program = """ py: (x) = x py: 1 """ # Act. out = execute(program) # Assert. assert out == 1
def test_random(): # Arrange. program = """ x = py: "import random; result = random.randint", 1, 1 x """ # Act. out = execute(program) # Assert. assert out == 1
def test_invalid_first_arg(): # Arrange. program = """ x = py: 1 x """ # Act. out = execute(program) # Assert. assert out == 'py:1'
def test_one_comment(): # Arrange. program = """ -- A. 1 """ # Act. out = execute(program) # Assert. assert out == 1
def test_simple_keyword_form(): # Arrange. program = """ just: (x) = 1 just: 2 """ # Act. out = execute(program) # Assert. assert out == 1
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
def test_type(): # Arrange. program = """ x = "a" x type """ # Act. out = execute(program) # Assert. assert out == 'String'
def test_simple_assignment(): # Arrange. program = """ (x) just = x 1 just """ # Act. out = execute(program) # Assert. assert out == 1
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
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
def test_multiple_prefix_operators_in_expression(): # Arrange. program = """ -(x) = x + 1 -(-1) """ # Act. out = execute(program) # Assert. assert out == 3
def test_unary(): # Arrange. program = """ (x), (y) first = x 1, 2 first """ # Act. out = execute(program) # Assert. assert out == 1
def test_keyword(): # Arrange. program = """ second: (x), (y) = y second: 1, 2 """ # Act. out = execute(program) # Assert. assert out == 2
def test_compound_binary_expression(): # Arrange. program = """ (x) + (y) = y a + b + c + d """ # Act. out = execute(program) # Assert. assert out == 'd'
def test_first_argument(): # Arrange. program = """ (x) + (y) = x a + b """ # Act. out = execute(program) # Assert. assert out == 'a'
def test_second_argument(): # Arrange. program = """ (x) + (y) = y a + b """ # Act. out = execute(program) # Assert. assert out == 'b'
def test_simple_prefix_operator(): # Arrange. program = """ -(x) = x -1 """ # Act. out = execute(program) # Assert. assert out == 1