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)
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)
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)
def f(x: Type): return match(x)(lambda T: { T: T, Type.pointer(Type.function(Type('int'), empty_list(Type))): Type('bool'), })
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)]
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)]
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)
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)
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)
def test_int_list_concat_rhs_empty_ok(): from tmppy import empty_list assert [2, 3] + empty_list(int) == [2, 3]
def f(x: bool): return empty_list(1) # error: Unsupported type declaration.
def test_empty_list_success(): from tmppy import empty_list assert empty_list(bool) == empty_list(bool)
def f(x: bool): return empty_list( bool, bool) # error: empty_list\(\) takes 1 argument. Got: 2
def test_sum_empty_list_success(): from tmppy import empty_list assert sum(empty_list(int)) == 0
def test_all_empty_list_success(): from tmppy import empty_list assert all(empty_list(bool)) == True
def test_type_list_concat_both_empty_ok(): from tmppy import Type, empty_list assert empty_list(Type) + empty_list(Type) == empty_list(Type)
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') ]
def test_bool_list_concat_both_empty_ok(): from tmppy import empty_list assert empty_list(bool) + empty_list(bool) == empty_list(bool)
def test_any_empty_list_success(): from tmppy import empty_list assert any(empty_list(bool)) == False
def test_int_list_concat_lhs_empty_ok(): from tmppy import empty_list assert empty_list(int) + [2, 3] == [2, 3]
def test_type_list_in_empty(): from tmppy import Type, empty_list assert not (Type('int') in empty_list(Type))
def test_int_list_in_empty(): from tmppy import empty_list assert not (1 in empty_list(int))
def test_bool_list_in_empty(): from tmppy import empty_list assert not (False in empty_list(bool))
def f(x: bool): return empty_list(bool, x=x) # error: Keyword arguments are not supported.
def test_int_list_concat_both_empty_ok(): from tmppy import empty_list assert empty_list(int) + empty_list(int) == empty_list(int)
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)))
def test_bool_list_concat_rhs_empty_ok(): from tmppy import empty_list assert [False, True] + empty_list(bool) == [False, True]