-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_filters.py
More file actions
73 lines (62 loc) · 3.52 KB
/
verify_filters.py
File metadata and controls
73 lines (62 loc) · 3.52 KB
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
#!/usr/bin/env python3
"""
Simple verification script for the new filter functionality
"""
# Just test basic functionality without creating a GUI
def test_filter_options():
# Basic text matching logic test (isolated from GUI)
def text_matches(text, pattern, match_case=False, match_whole_word=False, use_regex=False):
"""Standalone version of the text matching logic"""
import re
if not text or not pattern:
return not pattern # If pattern is empty, match everything
try:
if use_regex:
# Use regular expression matching
flags = 0 if match_case else re.IGNORECASE
if match_whole_word:
# Add word boundaries for whole word matching
pattern = r'\b' + pattern + r'\b'
return bool(re.search(pattern, text, flags))
else:
# Use simple text matching
search_text = text if match_case else text.lower()
search_pattern = pattern if match_case else pattern.lower()
if match_whole_word:
# Split text into words and check for exact matches
words = re.findall(r'\b\w+\b', search_text)
return search_pattern in words
else:
# Simple substring matching
return search_pattern in search_text
except re.error:
# If regex is invalid, fall back to simple substring matching
search_text = text if match_case else text.lower()
search_pattern = pattern if match_case else pattern.lower()
return search_pattern in search_text
# Test cases
test_cases = [
("Hello World", "hello", False, False, False, True), # case insensitive
("Hello World", "Hello", True, False, False, True), # case sensitive
("Hello World", "hello", True, False, False, False), # case sensitive fail
("Hello World", "ell", False, True, False, False), # whole word fail
("Hello World", "hello", False, True, False, True), # whole word success
("Hello World", "h.*o", False, False, True, True), # regex success
("Hello World", "^world", False, False, True, False), # regex fail
("", "", False, False, False, True), # empty pattern matches empty text
("Hello", "", False, False, False, True), # empty pattern matches any text
("", "hello", False, False, False, False), # non-empty pattern doesn't match empty text
]
print("Testing filter options...")
all_passed = True
for i, (text, pattern, match_case, match_whole_word, use_regex, expected) in enumerate(test_cases):
result = text_matches(text, pattern, match_case, match_whole_word, use_regex)
status = "PASS" if result == expected else "FAIL"
if result != expected:
all_passed = False
print(f"Test {i+1}: {status} - text='{text}', pattern='{pattern}', case={match_case}, whole={match_whole_word}, regex={use_regex}, expected={expected}, got={result}")
print(f"\nOverall result: {'All tests passed!' if all_passed else 'Some tests failed.'}")
return all_passed
if __name__ == "__main__":
success = test_filter_options()
print(f"\nFilter functionality verification: {'SUCCESS' if success else 'FAILED'}")