Exemplo n.º 1
0
def test_if_named_then_else():
    inc_type = Func[[IntType], IntType]
    check_expr_type(
        """
        if (inc 1) :then (inc 2) :else (inc 3)
        """,
        Tuple.typed(Union[IntType, ], [
            Symbol.typed(IF3_TYPE, 'if'),
            Tuple.typed(IntType, [
                Symbol.typed(inc_type, 'inc'),
                Number.typed(IntType, 1),
            ]),
            Keyword('then'),
            Tuple.typed(IntType, [
                Symbol.typed(inc_type, 'inc'),
                Number.typed(IntType, 2),
            ]),
            Keyword('else'),
            Tuple.typed(IntType, [
                Symbol.typed(inc_type, 'inc'),
                Number.typed(IntType, 3),
            ]),
        ]),
        {'inc': inc_type},
    )
Exemplo n.º 2
0
def test_list():
    foo_type = Func[[ListType[Union[IntType, StringType]]], IntType]
    check_expr_type(
        """
        foo [1 2 3]
        """,
        Tuple.typed(IntType, [
            Symbol.typed(foo_type, 'foo'),
            List.typed(ListType[Union[IntType, ]], [
                Number.typed(IntType, 1),
                Number.typed(IntType, 2),
                Number.typed(IntType, 3),
            ]),
        ]),
        {'foo': foo_type},
    )
    check_expr_type(
        """
        foo [1 2 "3"]
        """,
        Tuple.typed(IntType, [
            Symbol.typed(foo_type, 'foo'),
            List.typed(ListType[Union[IntType, StringType]], [
                Number.typed(IntType, 1),
                Number.typed(IntType, 2),
                String.typed(StringType, '3'),
            ]),
        ]),
        {'foo': foo_type},
    )
    with py.test.raises(TypeCheckError):
        check_expr('foo [1 2 "3"]',
                   {'foo': Func[[ListType[IntType]], IntType]})
Exemplo n.º 3
0
def test_list():
    check_parse(
        'foo [:k1 v1 1 (foo 2)]',
        List([
            Tuple([
                Symbol('foo'),
                List([
                    Keyword('k1'),
                    Symbol('v1'),
                    Number(1),
                    Tuple([Symbol('foo'), Number(2)])
                ])
            ]),
        ]),
    )
Exemplo n.º 4
0
def test_indent():
    check_parse(
        """
        foo
          "bar"
        """,
        List([
            Tuple([Symbol('foo'), String('bar')]),
        ]),
    )
    check_parse(
        """
        foo
          "bar"
          5
          "baz"
        """,
        List([
            Tuple([
                Symbol('foo'),
                Tuple([
                    Symbol('join'),
                    List([String('bar'),
                          Number(5), String('baz')])
                ])
            ]),
        ]),
    )
Exemplo n.º 5
0
def test_if_then():
    inc_type = Func[[IntType], IntType]
    check_expr_type(
        """
        if (inc 1) (inc 2)
        """,
        Tuple.typed(Option[IntType], [
            Symbol.typed(IF1_TYPE, 'if'),
            Tuple.typed(IntType, [
                Symbol.typed(inc_type, 'inc'),
                Number.typed(IntType, 1),
            ]),
            Tuple.typed(IntType, [
                Symbol.typed(inc_type, 'inc'),
                Number.typed(IntType, 2),
            ]),
        ]),
        {'inc': inc_type},
    )
Exemplo n.º 6
0
def test_func():
    inc_type = Func[[IntType], IntType]
    check_expr_type(
        'inc 1',
        Tuple.typed(IntType, [Symbol.typed(inc_type, 'inc'),
                              Number.typed(IntType, 1)]),
        {'inc': inc_type},
    )

    inc_step_type = Func[[IntType, NamedArg['step', IntType]], IntType]
    check_expr_type(
        'inc-step 1 :step 2',
        Tuple.typed(IntType, [Symbol.typed(inc_step_type, 'inc-step'),
                              Number.typed(IntType, 1),
                              Keyword('step'), Number.typed(IntType, 2)]),
        {'inc-step': inc_step_type},
    )
    with py.test.raises(TypeCheckError):
        check_expr('inc "foo"', {'inc': inc_type})
Exemplo n.º 7
0
def test_implicit_tuple():
    check_parse(
        'foo :bar 5 "baz"',
        List([
            Tuple([Symbol('foo'),
                   Keyword('bar'),
                   Number(5),
                   String('baz')]),
        ]),
    )
Exemplo n.º 8
0
def test_explicit_tuple():
    check_parse(
        'foo (bar 5) "baz"',
        List([
            Tuple([
                Symbol('foo'),
                Tuple([Symbol('bar'), Number(5)]),
                String('baz')
            ]),
        ]),
    )
Exemplo n.º 9
0
def test_nested_indent():
    check_parse(
        """
        foo
          bar
            1
          baz
            2
        """,
        List([
            Tuple([
                Symbol('foo'),
                Tuple([
                    Symbol('join'),
                    List([
                        Tuple([Symbol('bar'), Number(1)]),
                        Tuple([Symbol('baz'), Number(2)])
                    ])
                ])
            ]),
        ]),
    )
Exemplo n.º 10
0
def test_dict():
    check_parse(
        'foo {:k1 v1 :k2 (v2 3)}',
        List([
            Tuple([
                Symbol('foo'),
                Dict([
                    Keyword('k1'),
                    Symbol('v1'),
                    Keyword('k2'),
                    Tuple([Symbol('v2'), Number(3)])
                ])
            ]),
        ]),
    )
Exemplo n.º 11
0
def test_let():
    inc_type = Func[[IntType], IntType]
    check_expr_type(
        'let [x 1] (inc x)',
        Tuple.typed(IntType, [
            Symbol.typed(LET_TYPE, 'let'),
            List([
                Symbol.typed(IntType, 'x'),
                Number.typed(IntType, 1),
            ]),
            Tuple.typed(IntType, [
                Symbol.typed(inc_type, 'inc'),
                Symbol.typed(IntType, 'x'),
            ]),
        ]),
        {'inc': inc_type},
    )