diff --git a/tests/test_query/test_handlers/test_parsers.py b/tests/test_query/test_handlers/test_parsers.py index 20c2fc4..f74f6a8 100644 --- a/tests/test_query/test_handlers/test_parsers.py +++ b/tests/test_query/test_handlers/test_parsers.py @@ -24,6 +24,12 @@ class TestFileQueryParser: "* FROM '.' WHERE atime >= '2024-02-20'", ] + file_search_query_with_size_fields_test_params = [ + "size, size[B] FROM . WHERE type = '.py' AND size[KiB] > 512", + "size[b],size,size[TiB] FROM ABSOLUTE .", + "size[MB], size[GB], size[B] FROM . WHERE size[MiB] > 10", + ] + # The following list comprises results for the file search query test comprising sub-lists, # each with a length of 2. The first element of each sub-list signifies whether the path is # absolute (True) or relative (False) whereas the second element is a list comprising names @@ -37,6 +43,12 @@ class TestFileQueryParser: [False, list(constants.FILE_FIELDS)], ] + file_search_query_with_size_fields_test_results = [ + [False, ["B", "B"], ["size", "size[B]"]], + [True, ["b", "B", "TiB"], ["size[b]", "size", "size[TiB]"]], + [False, ["MB", "GB", "B"], ["size[MB]", "size[GB]", "size[B]"]], + ] + @pytest.mark.parametrize( ("subquery", "results"), zip(file_search_query_test_params, file_search_query_test_results), @@ -58,3 +70,31 @@ def test_file_search_query_parser(self, subquery, results) -> None: assert search_query.path == path assert [field.field for field in search_query.fields] == columns assert search_query.columns == columns + + @pytest.mark.parametrize( + ("subquery", "results"), + zip( + file_search_query_with_size_fields_test_params, + file_search_query_with_size_fields_test_results, + ), + ) + def test_file_search_query_parser_with_size_fields(self, subquery, results) -> None: + """ + Tests the file query parser with search queries comprising size fields. + """ + + query: list[str] = tools.parse_query(subquery) + + parser = FileQueryParser(query, "search") + search_query: SearchQuery = parser.parse_query() + + path: Path = Path(".") + units: list[str] = results[1] + columns: list[str] = results[2] + + if results[0]: + path = path.resolve() + + assert search_query.path == path + assert [field.unit for field in search_query.fields] == units + assert search_query.columns == columns