Exemple #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)
Exemple #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)
Exemple #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)
Exemple #4
0
 def f(x: Type):
     return match(x)(lambda T: {
         T:
         T,
         Type.pointer(Type.function(Type('int'), empty_list(Type))):
         Type('bool'),
     })
Exemple #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)]
Exemple #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)]
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #10
0
def test_int_list_concat_rhs_empty_ok():
    from tmppy import empty_list
    assert [2, 3] + empty_list(int) == [2, 3]
Exemple #11
0
 def f(x: bool):
     return empty_list(1)  # error: Unsupported type declaration.
Exemple #12
0
def test_empty_list_success():
    from tmppy import empty_list
    assert empty_list(bool) == empty_list(bool)
Exemple #13
0
 def f(x: bool):
     return empty_list(
         bool, bool)  # error: empty_list\(\) takes 1 argument. Got: 2
Exemple #14
0
def test_sum_empty_list_success():
    from tmppy import empty_list
    assert sum(empty_list(int)) == 0
Exemple #15
0
def test_all_empty_list_success():
    from tmppy import empty_list
    assert all(empty_list(bool)) == True
Exemple #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)
Exemple #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')
    ]
Exemple #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)
Exemple #19
0
def test_any_empty_list_success():
    from tmppy import empty_list
    assert any(empty_list(bool)) == False
Exemple #20
0
def test_int_list_concat_lhs_empty_ok():
    from tmppy import empty_list
    assert empty_list(int) + [2, 3] == [2, 3]
Exemple #21
0
def test_type_list_in_empty():
    from tmppy import Type, empty_list
    assert not (Type('int') in empty_list(Type))
Exemple #22
0
def test_int_list_in_empty():
    from tmppy import empty_list
    assert not (1 in empty_list(int))
Exemple #23
0
def test_bool_list_in_empty():
    from tmppy import empty_list
    assert not (False in empty_list(bool))
Exemple #24
0
 def f(x: bool):
     return empty_list(bool,
                       x=x)  # error: Keyword arguments are not supported.
Exemple #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)
Exemple #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)))
Exemple #27
0
def test_bool_list_concat_rhs_empty_ok():
    from tmppy import empty_list
    assert [False, True] + empty_list(bool) == [False, True]