Skip to content

Commit 1a2d468

Browse files
author
Matheus Rosa
committed
Update fuzzyfinder function to accept integer inputs
1 parent cd9ab8c commit 1a2d468

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

fuzzyfinder/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def fuzzyfinder(text, collection):
1616
input.
1717
"""
1818
suggestions = []
19+
text = str(text) if not isinstance(text, str) else text
1920
pat = '.*?'.join(map(re.escape, text))
2021
regex = re.compile(pat)
2122
for item in collection:

tests/test_fuzzyfinder.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def collection():
1919
'user_group.doc',
2020
'users.txt',
2121
'accounts.txt',
22+
'123.py',
23+
'test123test.py'
2224
]
2325

2426
def test_substring_match(collection):
@@ -50,3 +52,9 @@ def test_fuzzy_match_greedy(collection):
5052
results = fuzzyfinder(text, collection)
5153
expected = ['user_group.doc', 'users.txt', 'api_user.doc']
5254
assert list(results) == expected
55+
56+
def test_fuzzy_integer_input(collection):
57+
text = 123
58+
results = fuzzyfinder(text, collection)
59+
expected = ['123.py', 'test123test.py']
60+
assert list(results) == expected

0 commit comments

Comments
 (0)