Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zenlyj committed Nov 24, 2024
1 parent 8906179 commit 64a9d91
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/functional/p/potential_index_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,26 @@ def my_func():
# Test that we don't crash on more complicated indices/slices
# We do not raise here (currently)
print([1, 2, 3][2:3])


# Test for cases with unpacking operation
my_list = ["foo", "bar"]
my_set = {"foo", "bar"}
my_tuple = ("foo", "bar")
my_iterable = (*my_list, *my_set, *my_tuple, *("foo", "bar"))
my_non_iterable = None

print([*my_list][1])
print([*my_list][2]) # [potential-index-error]

print([*my_set][1])
print([*my_set][2]) # [potential-index-error]

print((*my_tuple,)[1])
print((*my_tuple,)[2]) # [potential-index-error]

print((*my_iterable,)[7])
print((*my_iterable,)[8]) # [potential-index-error]

print((*my_non_iterable,)[0])
print((*my_non_iterable,)[1]) # [potential-index-error]
5 changes: 5 additions & 0 deletions tests/functional/p/potential_index_error.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
potential-index-error:6:6:6:18::Invalid index for iterable length:INFERENCE
potential-index-error:7:6:7:18::Invalid index for iterable length:INFERENCE
potential-index-error:8:6:8:22::Invalid index for iterable length:INFERENCE
potential-index-error:36:6:36:19::Invalid index for iterable length:INFERENCE
potential-index-error:39:6:39:18::Invalid index for iterable length:INFERENCE
potential-index-error:42:6:42:21::Invalid index for iterable length:INFERENCE
potential-index-error:45:6:45:24::Invalid index for iterable length:INFERENCE
potential-index-error:48:6:48:28::Invalid index for iterable length:INFERENCE

0 comments on commit 64a9d91

Please sign in to comment.