@@ -76,6 +76,203 @@ fn test_simple() {
7676 ) ;
7777}
7878
79+ static AND_EXTRA_FILES : & [ & str ] = & [
80+ "a.foo" ,
81+ "one/b.foo" ,
82+ "one/two/c.foo" ,
83+ "one/two/C.Foo2" ,
84+ "one/two/three/baz-quux" ,
85+ "one/two/three/Baz-Quux2" ,
86+ "one/two/three/d.foo" ,
87+ "fdignored.foo" ,
88+ "gitignored.foo" ,
89+ ".hidden.foo" ,
90+ "A-B.jpg" ,
91+ "A-C.png" ,
92+ "B-A.png" ,
93+ "B-C.png" ,
94+ "C-A.jpg" ,
95+ "C-B.png" ,
96+ "e1 e2" ,
97+ ] ;
98+
99+ /// AND test
100+ #[ test]
101+ fn test_and_basic ( ) {
102+ let te = TestEnv :: new ( DEFAULT_DIRS , AND_EXTRA_FILES ) ;
103+
104+ te. assert_output (
105+ & [ "foo" , "--and" , "c" ] ,
106+ "one/two/C.Foo2
107+ one/two/c.foo
108+ one/two/three/directory_foo/" ,
109+ ) ;
110+
111+ te. assert_output (
112+ & [ "f" , "--and" , "[ad]" , "--and" , "[_]" ] ,
113+ "one/two/three/directory_foo/" ,
114+ ) ;
115+
116+ te. assert_output (
117+ & [ "f" , "--and" , "[ad]" , "--and" , "[.]" ] ,
118+ "a.foo
119+ one/two/three/d.foo" ,
120+ ) ;
121+
122+ te. assert_output ( & [ "Foo" , "--and" , "C" ] , "one/two/C.Foo2" ) ;
123+
124+ te. assert_output ( & [ "foo" , "--and" , "asdasdasdsadasd" ] , "" ) ;
125+ }
126+
127+ #[ test]
128+ fn test_and_empty_pattern ( ) {
129+ let te = TestEnv :: new ( DEFAULT_DIRS , AND_EXTRA_FILES ) ;
130+ te. assert_output ( & [ "Foo" , "--and" , "2" , "--and" , "" ] , "one/two/C.Foo2" ) ;
131+ }
132+
133+ #[ test]
134+ fn test_and_bad_pattern ( ) {
135+ let te = TestEnv :: new ( DEFAULT_DIRS , AND_EXTRA_FILES ) ;
136+
137+ te. assert_failure ( & [ "Foo" , "--and" , "2" , "--and" , "[" , "--and" , "C" ] ) ;
138+ te. assert_failure ( & [ "Foo" , "--and" , "[" , "--and" , "2" , "--and" , "C" ] ) ;
139+ te. assert_failure ( & [ "Foo" , "--and" , "2" , "--and" , "C" , "--and" , "[" ] ) ;
140+ te. assert_failure ( & [ "[" , "--and" , "2" , "--and" , "C" , "--and" , "Foo" ] ) ;
141+ }
142+
143+ #[ test]
144+ fn test_and_pattern_starts_with_dash ( ) {
145+ let te = TestEnv :: new ( DEFAULT_DIRS , AND_EXTRA_FILES ) ;
146+
147+ te. assert_output (
148+ & [ "baz" , "--and" , "quux" ] ,
149+ "one/two/three/Baz-Quux2
150+ one/two/three/baz-quux" ,
151+ ) ;
152+ te. assert_output (
153+ & [ "baz" , "--and" , "-" ] ,
154+ "one/two/three/Baz-Quux2
155+ one/two/three/baz-quux" ,
156+ ) ;
157+ te. assert_output (
158+ & [ "Quu" , "--and" , "x" , "--and" , "-" ] ,
159+ "one/two/three/Baz-Quux2" ,
160+ ) ;
161+ }
162+
163+ #[ test]
164+ fn test_and_plus_extension ( ) {
165+ let te = TestEnv :: new ( DEFAULT_DIRS , AND_EXTRA_FILES ) ;
166+
167+ te. assert_output (
168+ & [
169+ "A" ,
170+ "--and" ,
171+ "B" ,
172+ "--extension" ,
173+ "jpg" ,
174+ "--extension" ,
175+ "png" ,
176+ ] ,
177+ "A-B.jpg
178+ B-A.png" ,
179+ ) ;
180+
181+ te. assert_output (
182+ & [
183+ "A" ,
184+ "--extension" ,
185+ "jpg" ,
186+ "--and" ,
187+ "B" ,
188+ "--extension" ,
189+ "png" ,
190+ ] ,
191+ "A-B.jpg
192+ B-A.png" ,
193+ ) ;
194+ }
195+
196+ #[ test]
197+ fn test_and_plus_type ( ) {
198+ let te = TestEnv :: new ( DEFAULT_DIRS , AND_EXTRA_FILES ) ;
199+
200+ te. assert_output (
201+ & [ "c" , "--type" , "d" , "--and" , "foo" ] ,
202+ "one/two/three/directory_foo/" ,
203+ ) ;
204+
205+ te. assert_output (
206+ & [ "c" , "--type" , "f" , "--and" , "foo" ] ,
207+ "one/two/C.Foo2
208+ one/two/c.foo" ,
209+ ) ;
210+ }
211+
212+ #[ test]
213+ fn test_and_plus_glob ( ) {
214+ let te = TestEnv :: new ( DEFAULT_DIRS , AND_EXTRA_FILES ) ;
215+
216+ te. assert_output ( & [ "*foo" , "--glob" , "--and" , "c*" ] , "one/two/c.foo" ) ;
217+ }
218+
219+ #[ test]
220+ fn test_and_plus_fixed_strings ( ) {
221+ let te = TestEnv :: new ( DEFAULT_DIRS , AND_EXTRA_FILES ) ;
222+
223+ te. assert_output (
224+ & [ "foo" , "--fixed-strings" , "--and" , "c" , "--and" , "." ] ,
225+ "one/two/c.foo
226+ one/two/C.Foo2" ,
227+ ) ;
228+
229+ te. assert_output (
230+ & [ "foo" , "--fixed-strings" , "--and" , "[c]" , "--and" , "." ] ,
231+ "" ,
232+ ) ;
233+
234+ te. assert_output (
235+ & [ "Foo" , "--fixed-strings" , "--and" , "C" , "--and" , "." ] ,
236+ "one/two/C.Foo2" ,
237+ ) ;
238+ }
239+
240+ #[ test]
241+ fn test_and_plus_ignore_case ( ) {
242+ let te = TestEnv :: new ( DEFAULT_DIRS , AND_EXTRA_FILES ) ;
243+
244+ te. assert_output (
245+ & [ "Foo" , "--ignore-case" , "--and" , "C" , "--and" , "[.]" ] ,
246+ "one/two/C.Foo2
247+ one/two/c.foo" ,
248+ ) ;
249+ }
250+
251+ #[ test]
252+ fn test_and_plus_case_sensitive ( ) {
253+ let te = TestEnv :: new ( DEFAULT_DIRS , AND_EXTRA_FILES ) ;
254+
255+ te. assert_output (
256+ & [ "foo" , "--case-sensitive" , "--and" , "c" , "--and" , "[.]" ] ,
257+ "one/two/c.foo" ,
258+ ) ;
259+ }
260+
261+ #[ test]
262+ fn test_and_plus_full_path ( ) {
263+ let te = TestEnv :: new ( DEFAULT_DIRS , AND_EXTRA_FILES ) ;
264+
265+ te. assert_output (
266+ & [ "three" , "--full-path" , "--and" , "foo" , "--and" , "dir" ] ,
267+ "one/two/three/directory_foo/" ,
268+ ) ;
269+
270+ te. assert_output (
271+ & [ "three" , "--full-path" , "--and" , "two" , "--and" , "dir" ] ,
272+ "one/two/three/directory_foo/" ,
273+ ) ;
274+ }
275+
79276/// Test each pattern type with an empty pattern.
80277#[ test]
81278fn test_empty_pattern ( ) {
0 commit comments