mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-13 15:57:14 +03:00
checked negatives, added test to that effect
This commit is contained in:
parent
1c3c29abb6
commit
3133cba0a4
@ -81,8 +81,9 @@ def _apply(target: UPDATABLE_DATA, key: str, to_set: Any = None, delete: bool =
|
||||
if idx is None:
|
||||
raise ValueError(f'Cannot use string {key!r} as int for index into Sequence')
|
||||
|
||||
if delete:
|
||||
if len(target) > idx:
|
||||
if delete and len(target) > 0:
|
||||
length = len(target)
|
||||
if (idx > 0 and length > idx) or idx >= -length:
|
||||
target.pop(idx)
|
||||
|
||||
elif len(target) == idx:
|
||||
|
@ -15,7 +15,10 @@ from killswitch import UPDATABLE_DATA
|
||||
(['this', 'is', 'a', 'test'], '1', '', None, ['this', None, 'a', 'test']),
|
||||
({'now': 'with', 'a': 'dict'}, 'now', 'delete', None, {'a': 'dict'}),
|
||||
({'now': 'with', 'a': 'dict'}, 'now', '', None, {'now': None, 'a': 'dict'}),
|
||||
(['test append'], '1', '', 'yay', ['test append', 'yay'])
|
||||
(['test append'], '1', '', 'yay', ['test append', 'yay']),
|
||||
(['test neg del'], '-1', 'delete', None, []),
|
||||
(['test neg del'], '-1337', 'delete', None, ['test neg del']),
|
||||
(['test neg del'], '-2', 'delete', None, ['test neg del']),
|
||||
]
|
||||
)
|
||||
def test_apply(source: UPDATABLE_DATA, key: str, action: str, to_set: Any, result: UPDATABLE_DATA) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user