def test_name() -> None: class SomeStruct(Struct): field: UInt16 data = SomeStruct() assert type_name(SomeStruct.field) == 'uint16_t' assert type_name(data.field) == 'uint16_t'
def test_name() -> None: class Data(Union): u16: UInt16 u8: UInt8 data = Data(0) assert type_name(Data) == 'Data' assert type_name(data) == 'Data'
def test_name() -> None: class SomeStruct(Struct): field1: UInt8 field2: UInt16 field3: UInt16 data = SomeStruct(0) assert type_name(SomeStruct) == 'SomeStruct' assert type_name(data) == 'SomeStruct'
def test_name() -> None: data_t = create_union('Data', { 'u16': UInt16, 'u8': UInt8, }) data = data_t(0) assert type_name(data_t) == 'Data' assert type_name(data) == 'Data'
def test_name() -> None: some_t = create_struct('SomeStruct', { 'field1': UInt8, 'field2': UInt16, 'field3': UInt16, }) data = some_t(0) assert type_name(some_t) == 'SomeStruct' assert type_name(data) == 'SomeStruct'
def test_clone() -> None: clone = clone_type(Float) data = clone(0) assert clone is not Float assert sizeof(clone) == 4 assert type_name(clone) == 'float' assert data == 0.0 clone2 = clone_type(clone, name='Float') assert type_name(clone2) == 'Float' clone3 = clone_type(clone2) assert type_name(clone3) == 'Float'
def test_clone() -> None: arr_t = typeof(Array(UInt16, 4)) clone = clone_type(arr_t) assert clone is not arr_t assert clone.item_type() is UInt16 assert clone.length() == 4 assert type_name(clone) == 'uint16_t[4]' clone2 = clone_type(clone, name='uint16x4') assert type_name(clone2) == 'uint16x4' clone3 = clone_type(clone2) assert type_name(clone3) == 'uint16x4'
def test_clone() -> None: bytes_t = Bytes[Literal[5]] clone = clone_type(bytes_t) data = clone(0) assert clone is not bytes_t assert sizeof(clone) == 5 assert type_name(clone) == 'char[5]' assert bytes(data) == b'\x00\x00\x00\x00\x00' clone2 = clone_type(clone, name='str_5') assert type_name(clone2) == 'str_5' clone3 = clone_type(clone2) assert type_name(clone3) == 'str_5'
def test_clone() -> None: ptr_t = Pointer16[UInt32] clone = clone_type(ptr_t) data = clone(0) assert clone is not ptr_t assert sizeof(clone) == 2 assert clone.int_type() is UInt16 assert clone.ref_type() is UInt32 assert type_name(clone) == 'uint32_t *' assert bytes(data) == b'\x00\x00' clone2 = clone_type(clone, name='PUINT32') assert type_name(clone2) == 'PUINT32' clone3 = clone_type(clone2) assert type_name(clone3) == 'PUINT32'
def test_clone() -> None: class Data(Union): u16: UInt16 u8: UInt8 clone = clone_type(Data) data = clone(0) assert clone is not Data assert sizeof(clone) == 2 assert type_name(clone) == 'Data' assert tuple(i for i in clone) == ('u16', 'u8') assert offsetof(clone, 'u16') == 0 assert 'u32' not in clone assert bytes(data) == b'\x00\x00'
def test_clone() -> None: class SomeStruct(Struct): field1: UInt8 field2: UInt16 field3: UInt16 clone = clone_type(SomeStruct) data = clone(0) assert clone is not SomeStruct assert sizeof(clone) == 5 assert type_name(clone) == 'SomeStruct' assert tuple(i for i in clone) == ('field1', 'field2', 'field3') assert offsetof(clone, 'field3') == 3 assert 'field4' not in clone assert bytes(data) == b'\x00\x00\x00\x00\x00'
def test_name_fwdred() -> None: data = Pointer32(ForwardRef, 0) ptr_t = typeof(data) assert type_name(ptr_t) == 'void *' assert type_name(data) == 'void *'
def test_name_void() -> None: data = Pointer32(Void, 0) ptr_t = typeof(data) assert type_name(ptr_t) == 'void *' assert type_name(data) == 'void *'
def test_name_2() -> None: data = Pointer32(UInt16, 0) ptr_t = typeof(data) assert type_name(ptr_t) == 'uint16_t *' assert type_name(data) == 'uint16_t *'
def test_rename() -> None: class SomeStruct(Struct): field: UInt8 rename(SomeStruct, 'AnotherName') assert type_name(SomeStruct) == 'AnotherName'
def test_name_2() -> None: data = Bytes(5, b'abcde') bytes_t = typeof(data) assert type_name(bytes_t) == 'char[5]' assert type_name(data) == 'char[5]'
def test_name_1() -> None: bytes_t = Bytes[Literal[5]] data = bytes_t(0) assert type_name(bytes_t) == 'char[5]' assert type_name(data) == 'char[5]'
def test_name() -> None: data = Array(UInt16, 4) arr_t = typeof(data) assert type_name(arr_t) == 'uint16_t[4]' assert type_name(data) == 'uint16_t[4]'
def test_name_1() -> None: ptr_t = Pointer32[UInt16] data = ptr_t(0) assert type_name(ptr_t) == 'uint16_t *' assert type_name(data) == 'uint16_t *'
def test_type_name_bad() -> None: with raises(TypeError): _ = type_name('Invalid value') # type: ignore