Ejemplo n.º 1
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]})
Ejemplo n.º 2
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},
    )
Ejemplo n.º 3
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},
    )
Ejemplo n.º 4
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})
Ejemplo n.º 5
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},
    )