Ejemplo n.º 1
0
def test_custom_type_list_concat_both_empty_ok():
    from tmppy import empty_list

    class Int:
        def __init__(self, n: int):
            self.n = n

    assert empty_list(Int) + empty_list(Int) == empty_list(Int)
Ejemplo n.º 2
0
def test_custom_type_list_concat_both_empty_ok():
    from tmppy import empty_list

    @dataclass
    class Int:
        n: int

    assert empty_list(Int) + empty_list(Int) == empty_list(Int)
Ejemplo n.º 3
0
def test_match_expr_extract_list_empty():
    from tmppy import Type, match, empty_list

    def unpack_tuple(t: Type):
        return match(t)(lambda Ts: {
            Type.template_instantiation('std::tuple', [*Ts]): Ts
        })
    assert unpack_tuple(Type.template_instantiation('std::tuple', empty_list(Type))) \
        == empty_list(Type)
Ejemplo n.º 4
0
 def f(x: Type):
     return match(x)(lambda T: {
         T:
         T,
         Type.pointer(Type.function(Type('int'), empty_list(Type))):
         Type('bool'),
     })
Ejemplo n.º 5
0
def test_custom_type_list_concat_rhs_empty_ok():
    from tmppy import empty_list

    class Int:
        def __init__(self, n: int):
            self.n = n

    assert [Int(2), Int(3)] + empty_list(Int) == [Int(2), Int(3)]
Ejemplo n.º 6
0
def test_custom_type_list_concat_rhs_empty_ok():
    from tmppy import empty_list

    @dataclass
    class Int:
        n: int

    assert [Int(2), Int(3)] + empty_list(Int) == [Int(2), Int(3)]
Ejemplo n.º 7
0
def test_list_comprehension_from_int_list_throws_toplevel():
    from tmppy import empty_list

    class MyError(Exception):
        def __init__(self, b: bool):
            self.message = 'Something went wrong'
            self.b = b

    def f(n: int):
        if n == 1:
            raise MyError(True)
        return True

    assert [f(x) for x in [0, 1, 2]] == empty_list(bool)
Ejemplo n.º 8
0
def test_list_comprehension_from_type_list_throws_toplevel():
    from tmppy import empty_list, Type

    class MyError(Exception):
        def __init__(self, b: bool):
            self.message = 'Something went wrong'
            self.b = b

    def f(x: Type):
        if x == Type('float'):
            raise MyError(True)
        return True

    assert [f(x)
            for x in [Type('int'), Type('float'),
                      Type('double')]] == empty_list(bool)
Ejemplo n.º 9
0
def test_list_comprehension_from_custom_type_list_throws_toplevel():
    from tmppy import empty_list

    class Int:
        def __init__(self, n: int):
            self.n = n

    class MyError(Exception):
        def __init__(self, b: bool):
            self.message = 'Something went wrong'
            self.b = b

    def f(x: Int):
        if x == Int(1):
            raise MyError(True)
        return True

    assert [f(x) for x in [Int(0), Int(1), Int(2)]] == empty_list(bool)
Ejemplo n.º 10
0
def test_int_list_concat_rhs_empty_ok():
    from tmppy import empty_list
    assert [2, 3] + empty_list(int) == [2, 3]
Ejemplo n.º 11
0
 def f(x: bool):
     return empty_list(1)  # error: Unsupported type declaration.
Ejemplo n.º 12
0
def test_empty_list_success():
    from tmppy import empty_list
    assert empty_list(bool) == empty_list(bool)
Ejemplo n.º 13
0
 def f(x: bool):
     return empty_list(
         bool, bool)  # error: empty_list\(\) takes 1 argument. Got: 2
Ejemplo n.º 14
0
def test_sum_empty_list_success():
    from tmppy import empty_list
    assert sum(empty_list(int)) == 0
Ejemplo n.º 15
0
def test_all_empty_list_success():
    from tmppy import empty_list
    assert all(empty_list(bool)) == True
Ejemplo n.º 16
0
def test_type_list_concat_both_empty_ok():
    from tmppy import Type, empty_list
    assert empty_list(Type) + empty_list(Type) == empty_list(Type)
Ejemplo n.º 17
0
def test_type_list_concat_rhs_empty_ok():
    from tmppy import Type, empty_list
    assert [Type('float'), Type('double')] + empty_list(Type) == [
        Type('float'), Type('double')
    ]
Ejemplo n.º 18
0
def test_bool_list_concat_both_empty_ok():
    from tmppy import empty_list
    assert empty_list(bool) + empty_list(bool) == empty_list(bool)
Ejemplo n.º 19
0
def test_any_empty_list_success():
    from tmppy import empty_list
    assert any(empty_list(bool)) == False
Ejemplo n.º 20
0
def test_int_list_concat_lhs_empty_ok():
    from tmppy import empty_list
    assert empty_list(int) + [2, 3] == [2, 3]
Ejemplo n.º 21
0
def test_type_list_in_empty():
    from tmppy import Type, empty_list
    assert not (Type('int') in empty_list(Type))
Ejemplo n.º 22
0
def test_int_list_in_empty():
    from tmppy import empty_list
    assert not (1 in empty_list(int))
Ejemplo n.º 23
0
def test_bool_list_in_empty():
    from tmppy import empty_list
    assert not (False in empty_list(bool))
Ejemplo n.º 24
0
 def f(x: bool):
     return empty_list(bool,
                       x=x)  # error: Keyword arguments are not supported.
Ejemplo n.º 25
0
def test_int_list_concat_both_empty_ok():
    from tmppy import empty_list
    assert empty_list(int) + empty_list(int) == empty_list(int)
Ejemplo n.º 26
0
def test_type_function_pointer_literal_with_no_args_success():
    from tmppy import Type, empty_list
    assert Type.pointer(Type.function(Type('int'),
                                      empty_list(Type))) == Type.pointer(
                                          Type.function(
                                              Type('int'), empty_list(Type)))
Ejemplo n.º 27
0
def test_bool_list_concat_rhs_empty_ok():
    from tmppy import empty_list
    assert [False, True] + empty_list(bool) == [False, True]