Skip to content

Commit 1fd741a

Browse files
authored
Enhanced Directory Pattern Matching Test Coverage (#123)
1 parent e8663c6 commit 1fd741a

File tree

1 file changed

+56
-4
lines changed

1 file changed

+56
-4
lines changed

tests/test_query_ingestion.py

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,62 @@ def test_include_nonexistent_extension(temp_directory: Path, sample_query: dict[
9696

9797

9898
# single folder patterns
99-
# TODO: test with include patterns: ['src/*']
100-
# TODO: test with include patterns: ['/src/*']
101-
# TODO: test with include patterns: ['/src/']
102-
# TODO: test with include patterns: ['/src*']
99+
def test_include_src_star_pattern(temp_directory: Path, sample_query: dict[str, Any]) -> None:
100+
"""
101+
Test that when using 'src/*' as include pattern, files under the src directory
102+
are included.
103+
Note: Windows is not supported - test converts Windows paths to Unix-style for validation.
104+
"""
105+
sample_query["local_path"] = temp_directory
106+
sample_query["include_patterns"] = ["src/*"]
107+
108+
result = _scan_directory(temp_directory, query=sample_query)
109+
assert result is not None, "Result should not be None"
110+
111+
files = _extract_files_content(query=sample_query, node=result, max_file_size=1_000_000)
112+
# Convert Windows paths to Unix-style for test validation
113+
file_paths = {f["path"].replace("\\", "/") for f in files}
114+
expected_paths = {"src/subfile1.txt", "src/subfile2.py", "src/subdir/file_subdir.txt", "src/subdir/file_subdir.py"}
115+
assert file_paths == expected_paths, "Missing or unexpected files in result"
116+
117+
118+
def test_include_src_recursive(temp_directory: Path, sample_query: dict[str, Any]) -> None:
119+
"""
120+
Test that when using 'src/**' as include pattern, all files under src
121+
directory are included recursively.
122+
Note: Windows is not supported - test converts Windows paths to Unix-style for validation.
123+
"""
124+
sample_query["local_path"] = temp_directory
125+
sample_query["include_patterns"] = ["src/**"]
126+
127+
result = _scan_directory(temp_directory, query=sample_query)
128+
assert result is not None, "Result should not be None"
129+
130+
files = _extract_files_content(query=sample_query, node=result, max_file_size=1_000_000)
131+
# Convert Windows paths to Unix-style for test validation
132+
file_paths = {f["path"].replace("\\", "/") for f in files}
133+
expected_paths = {"src/subfile1.txt", "src/subfile2.py", "src/subdir/file_subdir.txt", "src/subdir/file_subdir.py"}
134+
assert file_paths == expected_paths, "Missing or unexpected files in result"
135+
136+
137+
def test_include_src_wildcard_prefix(temp_directory: Path, sample_query: dict[str, Any]) -> None:
138+
"""
139+
Test that when using 'src*' as include pattern, it matches the src directory
140+
and any paths that start with 'src'.
141+
Note: Windows is not supported - test converts Windows paths to Unix-style for validation.
142+
"""
143+
sample_query["local_path"] = temp_directory
144+
sample_query["include_patterns"] = ["src*"]
145+
146+
result = _scan_directory(temp_directory, query=sample_query)
147+
assert result is not None, "Result should not be None"
148+
149+
files = _extract_files_content(query=sample_query, node=result, max_file_size=1_000_000)
150+
# Convert Windows paths to Unix-style for test validation
151+
file_paths = {f["path"].replace("\\", "/") for f in files}
152+
expected_paths = {"src/subfile1.txt", "src/subfile2.py", "src/subdir/file_subdir.txt", "src/subdir/file_subdir.py"}
153+
assert file_paths == expected_paths, "Missing or unexpected files in result"
154+
103155

104156
# multiple patterns
105157
# TODO: test with multiple include patterns: ['*.txt', '*.py']

0 commit comments

Comments
 (0)