11import pytest
22from src .core .library .alchemy .enums import FilterState
33from src .core .library .alchemy .library import Library
4+ from src .core .query_lang .util import ParsingError
45
56
67def verify_count (lib : Library , query : str , count : int ):
@@ -19,6 +20,7 @@ def verify_count(lib: Library, query: str, count: int):
1920 ("special:untagged" , 1 ),
2021 ("filetype:png" , 23 ),
2122 ("filetype:jpg" , 6 ),
23+ ("filetype:'jpg'" , 6 ),
2224 ("tag_id:1011" , 5 ),
2325 ("tag_id:1038" , 11 ),
2426 ("doesnt exist" , 0 ),
@@ -72,3 +74,51 @@ def test_and(search_library: Library, query: str, count: int):
7274)
7375def test_or (search_library : Library , query : str , count : int ):
7476 verify_count (search_library , query , count )
77+
78+
79+ @pytest .mark .parametrize (
80+ ["query" , "count" ],
81+ [
82+ ("not unexistant" , 29 ),
83+ ("not path:*" , 0 ),
84+ ("not not path:*" , 29 ),
85+ ("not special:untagged" , 28 ),
86+ ("not filetype:png" , 6 ),
87+ ("not filetype:jpg" , 23 ),
88+ ("not tag_id:1011" , 24 ),
89+ ("not tag_id:1038" , 18 ),
90+ ("not green" , 24 ),
91+ ("tag:favorite" , 0 ),
92+ ("not circle" , 18 ),
93+ ("not tag:square" , 18 ),
94+ ("circle and not square" , 6 ),
95+ ("not circle and square" , 6 ),
96+ ("special:untagged or not filetype:jpg" , 24 ),
97+ ("not square or green" , 20 ),
98+ ],
99+ )
100+ def test_not (search_library : Library , query : str , count : int ):
101+ verify_count (search_library , query , count )
102+
103+
104+ @pytest .mark .parametrize (
105+ ["query" , "count" ],
106+ [
107+ ("(tag_id:1041)" , 11 ),
108+ ("(((tag_id:1041)))" , 11 ),
109+ ("not (not tag_id:1041)" , 11 ),
110+ ("((circle) and (not square))" , 6 ),
111+ ("(not ((square) OR (green)))" , 15 ),
112+ ("filetype:png and (tag:square or green)" , 12 ),
113+ ],
114+ )
115+ def test_parentheses (search_library : Library , query : str , count : int ):
116+ verify_count (search_library , query , count )
117+
118+
119+ @pytest .mark .parametrize (
120+ "invalid_query" , ["asd AND" , "asd AND AND" , "tag:(" , "(asd" , "asd[]" , "asd]" , ":" , "tag: :" ]
121+ )
122+ def test_syntax (search_library : Library , invalid_query : str ):
123+ with pytest .raises (ParsingError ) as e_info : # noqa: F841
124+ search_library .search_library (FilterState .from_search_query (invalid_query ))
0 commit comments