1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#!/usr/bin/env python3
"""Basic tests for selectui functionality."""
from thefuzz import fuzz
from selectui import SelectUI
def test_filtering_logic():
"""Test the filtering logic."""
items = [
{"title": "Python Developer", "subtitle": "Backend"},
{"title": "Frontend Engineer", "subtitle": "React"},
{"title": "DevOps Engineer", "subtitle": "AWS"},
]
# Test exact search (case insensitive)
query = "python"
filtered = []
for item in items:
title = item.get('title', '').lower()
subtitle = item.get('subtitle', '').lower()
if query in title or query in subtitle:
filtered.append(item)
assert len(filtered) == 1
assert filtered[0]["title"] == "Python Developer"
print("✓ Basic filtering logic passed")
def test_fuzzy_search_logic():
"""Test fuzzy search logic."""
items = [
{"title": "Python Developer", "subtitle": "Backend"},
{"title": "Frontend Engineer", "subtitle": "React"},
]
# Fuzzy match with typo
query = "Pythn"
filtered = []
for item in items:
title = item.get('title', '')
subtitle = item.get('subtitle', '')
title_score = fuzz.partial_ratio(query, title)
subtitle_score = fuzz.partial_ratio(query, subtitle)
if title_score > 60 or subtitle_score > 60:
filtered.append(item)
assert len(filtered) == 1
assert filtered[0]["title"] == "Python Developer"
print("✓ Fuzzy search logic passed")
def test_ui_initialization():
"""Test UI can be initialized."""
items = [
{"title": "Item 1", "subtitle": "Sub 1"},
{"title": "Item 2", "subtitle": "Sub 2"},
]
ui = SelectUI(items)
assert ui.items == items
assert ui.filtered_items == items
assert not ui.fuzzy_search
assert not ui.case_sensitive
print("✓ UI initialization passed")
def test_ui_initialization_empty():
"""Test UI can be initialized with empty items (for async loading)."""
ui = SelectUI()
assert ui.items == []
assert ui.filtered_items == []
assert not ui.fuzzy_search
assert not ui.case_sensitive
assert ui.stdin_fd is None
assert not ui._stream_complete
print("✓ UI empty initialization passed")
if __name__ == "__main__":
test_filtering_logic()
test_fuzzy_search_logic()
test_ui_initialization()
test_ui_initialization_empty()
print("\n✅ All tests passed!")
|