@@ -187,6 +187,47 @@ def test_delete_query(self, subquery: str, is_absolute: bool) -> None:
187
187
examine_delete_query (parser , is_absolute )
188
188
189
189
190
+ class TestFileDataQueryParser :
191
+ """Tests the FileDataQueryParser class."""
192
+
193
+ search_query_test_params = [
194
+ "* FROM ." ,
195
+ "name, path, dataline FROM ABSOLUTE '.'" ,
196
+ "path, lineno, dataline FROM RELATIVE . WHERE type = '.py'" ,
197
+ "* FROM '.' WHERE lineno BETWEEN (0, 100)" ,
198
+ ]
199
+
200
+ # The following are test results for the search query tests comprising sub-lists, each with
201
+ # a variable length where the first element of each of them signifies whether the path is
202
+ # absolute (True) or relative (False) whereas the last element in it is a list comprising
203
+ # names of the search fields. All the remaining objects within the list are test specific
204
+ # and may differ in different tests.
205
+
206
+ search_query_test_results = [
207
+ [False , list (constants .DATA_FIELDS )],
208
+ [True , ["name" , "path" , "dataline" ]],
209
+ [False , ["path" , "lineno" , "dataline" ]],
210
+ [False , list (constants .DATA_FIELDS )],
211
+ ]
212
+
213
+ @pytest .mark .parametrize (
214
+ ("subquery" , "results" ),
215
+ zip (search_query_test_params , search_query_test_results ),
216
+ )
217
+ def test_search_query (self , subquery : str , results : list [Any ]) -> None :
218
+ """
219
+ Tests the file data query parser with search queries.
220
+ """
221
+
222
+ query : list [str ] = tools .parse_query (subquery )
223
+ parser = FileDataQueryParser (query )
224
+
225
+ search_query : SearchQuery = examine_search_query (parser , results )
226
+ fields : list [str ] = results [1 ]
227
+
228
+ assert [field .field for field in search_query .fields ] == fields
229
+
230
+
190
231
class TestDirectoryQueryParser :
191
232
"""Tests the DirectoryQueryParser class"""
192
233
0 commit comments