Beispiel #1
0
def test_Function_definition_with_params_and_commands_gets_parsed():
    assert (
        parsed('{:(x,yy)print(3-4) a="x" print(a)}') ==
        [
            FunctionDefTree(
                [
                    SymbolTree("x"),
                    SymbolTree("yy")
                ],
                [
                    FunctionCallTree(
                        SymbolTree("print"),
                        [
                            OperationTree(
                                '-',
                                NumberTree('3'),
                                NumberTree('4')
                            )
                        ]
                    ),
                    AssignmentTree(SymbolTree("a"), StringTree("x")),
                    FunctionCallTree(SymbolTree("print"), [SymbolTree("a")])
                ]
            )
        ]
    )
Beispiel #2
0
def test_Empty_function_definition_gets_parsed():
    assert (
        parsed("{}") ==
        [
            FunctionDefTree([], [])
        ]
    )
Beispiel #3
0
def test_Trailing_comma_in_arg_list_is_ignored():
    assert (
        parsed("{:(aa,bb,)}") ==
        [
            FunctionDefTree(
                [
                    SymbolTree("aa"),
                    SymbolTree("bb"),
                ],
                []
            )
        ]
    )
Beispiel #4
0
def test_Empty_function_definition_with_params_gets_parsed():
    assert (
        parsed("{:(aa,bb,cc,dd)}") ==
        [
            FunctionDefTree(
                [
                    SymbolTree("aa"),
                    SymbolTree("bb"),
                    SymbolTree("cc"),
                    SymbolTree("dd"),
                ],
                []
            )
        ]
    )
Beispiel #5
0
def test_Multiple_commands_parse_into_multiple_expressions():
    program = """
    x=3
    func={:(a)print(a)}
    func(x)
    """
    assert (
        parsed(program) ==
        [
            AssignmentTree(SymbolTree('x'), NumberTree('3')),
            AssignmentTree(
                SymbolTree('func'),
                FunctionDefTree(
                    [SymbolTree('a')],
                    [
                        FunctionCallTree(
                            SymbolTree('print'), [SymbolTree('a')])
                    ]
                )
            ),
            FunctionCallTree(SymbolTree('func'), [SymbolTree('x')])
        ]
    )
Beispiel #6
0
def test_Spaces_are_allowed_where_unimportant():
    assert (
        parsed('''
        {:( x, y )
            x+y
            foo( 3 )
        }( 3, 4 )
        ''') ==
        [
            FunctionCallTree(
                FunctionDefTree(
                    [
                        SymbolTree("x"),
                        SymbolTree("y"),
                    ],
                    [
                        OperationTree(
                            '+',
                            SymbolTree("x"),
                            SymbolTree("y"),
                        ),
                        FunctionCallTree(
                            SymbolTree("foo"),
                            [
                                NumberTree("3"),
                            ]
                        ),
                    ]
                ),
                [
                    NumberTree("3"),
                    NumberTree("4"),
                ]
            )
        ]
    )