mirror of https://github.com/Nonannet/pelfy.git
__contains__ for lists added with test
This commit is contained in:
parent
de88f387e9
commit
2e865b0785
|
|
@ -265,6 +265,14 @@ class elf_list(Generic[_T]):
|
||||||
def __iter__(self) -> Iterator[_T]:
|
def __iter__(self) -> Iterator[_T]:
|
||||||
return iter(self._data)
|
return iter(self._data)
|
||||||
|
|
||||||
|
def __contains__(self, item: Union[str, int, _T]) -> bool:
|
||||||
|
if isinstance(item, str):
|
||||||
|
return any(getattr(el, 'name', '') == item for el in self._data)
|
||||||
|
elif isinstance(item, int):
|
||||||
|
return 0 <= item < len(self._data)
|
||||||
|
else:
|
||||||
|
return item in self._data
|
||||||
|
|
||||||
def _compact_table(self) -> tuple[list[str], list[list[Union[str, int]]], list[str]]:
|
def _compact_table(self) -> tuple[list[str], list[list[Union[str, int]]], list[str]]:
|
||||||
return [], [[]], []
|
return [], [[]], []
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,13 @@ def test_simple_c() -> None:
|
||||||
for reloc in elf.get_relocations():
|
for reloc in elf.get_relocations():
|
||||||
assert known_name(reloc.type), f"Relocation type {reloc.type} for {elf.architecture} in {path} is unknown."
|
assert known_name(reloc.type), f"Relocation type {reloc.type} for {elf.architecture} in {path} is unknown."
|
||||||
|
|
||||||
|
assert 'imageWidth' in elf.objects or 'read_float_ret' in elf.objects, path
|
||||||
|
assert 'leet456456456n4ghn4hf56n4f' not in elf.objects
|
||||||
|
assert 0 in elf.objects
|
||||||
|
assert 1000 not in elf.objects
|
||||||
|
assert elf.objects[0] in elf.symbols
|
||||||
|
assert elf.objects[0] not in elf.functions
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
test_simple_c()
|
test_simple_c()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue