@@ -157,6 +157,12 @@ class TestDirectoryQueryParser:
157
157
"* FROM ABSOLUTE '.' WHERE atime >= '2024-02-20'" ,
158
158
]
159
159
160
+ search_query_with_field_aliases_test_params = [
161
+ "filename, filepath FROM ABSOLUTE ." ,
162
+ "filepath, ctime,atime FROM . WHERE atime <= '2023-01-01' AND ctime >= '2006-02-20'" ,
163
+ "filename, mtime FROM RELATIVE . WHERE mtime BETWEEN ('2021-03-12', '2021-04-12')" ,
164
+ ]
165
+
160
166
# The following list comprises results for the file search query test comprising sub-lists,
161
167
# each with a length of 2. The first element of each sub-list signifies whether the path is
162
168
# absolute (True) or relative (False) whereas the second element is a list comprising names
@@ -169,6 +175,12 @@ class TestDirectoryQueryParser:
169
175
[True , list (constants .DIR_FIELDS )],
170
176
]
171
177
178
+ search_query_with_field_aliases_test_results = [
179
+ [True , ["name" , "path" ], ["filename" , "filepath" ]],
180
+ [False , ["path" , "create_time" , "access_time" ], ["filepath" , "ctime" , "atime" ]],
181
+ [False , ["name" , "modify_time" ], ["filename" , "mtime" ]],
182
+ ]
183
+
172
184
@pytest .mark .parametrize (
173
185
("subquery" , "results" ),
174
186
zip (search_query_test_params , search_query_test_results ),
@@ -183,3 +195,23 @@ def test_search_query(self, subquery, results) -> None:
183
195
fields : list [str ] = results [1 ]
184
196
185
197
assert [field .field for field in search_query .fields ] == fields
198
+
199
+ @pytest .mark .parametrize (
200
+ ("subquery" , "results" ),
201
+ zip (
202
+ search_query_with_field_aliases_test_params ,
203
+ search_query_with_field_aliases_test_results ,
204
+ ),
205
+ )
206
+ def test_search_query_with_field_aliases (self , subquery , results ) -> None :
207
+ """
208
+ Tests the file query parser with search queries comprising field aliases.
209
+ """
210
+
211
+ query : list [str ] = tools .parse_query (subquery )
212
+ parser = FileQueryParser (query , "search" )
213
+
214
+ search_query : SearchQuery = examine_search_query (parser , results )
215
+ fields : list [str ] = results [1 ]
216
+
217
+ assert [field .field for field in search_query .fields ] == fields
0 commit comments