contrib/anything-grep.el: anything-grep-multiline: revert to `t'
[anything-config.git] / developer-tools / unit-test-match-plugin.el
blob20ea1fa0dff06863b6b337ed75b7925f65d0908e
1 ;;; unit-test-match-plugin.el -- unit-tests for match-plugin.
3 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
4 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
5 (dont-compile
6 (when (fboundp 'expectations)
7 (require 'anything)
8 (require 'anything-match-plugin)
9 (expectations
10 (desc "anything-mp-3-get-patterns-internal")
11 (expect '((identity . "foo"))
12 (anything-mp-3-get-patterns-internal "foo"))
13 (expect '((identity . "foo") (identity . "bar"))
14 (anything-mp-3-get-patterns-internal "foo bar"))
15 (expect '((identity . "foo") (not . "bar"))
16 (anything-mp-3-get-patterns-internal "foo !bar"))
17 (expect '((identity . ".") (not . "bar") (identity . "foo"))
18 (anything-mp-3-get-patterns-internal "!bar foo"))
19 (desc "agp-command-line")
20 (expect "grep -ih foo /f1"
21 (agp-command-line "foo" '("/f1")))
22 (expect "grep -ih foo /f1 | grep -ih bar"
23 (agp-command-line "foo bar" '("/f1")))
24 (expect "grep -ih foo /f1 | grep -ih -v bar"
25 (agp-command-line "foo !bar" '("/f1")))
26 (expect "grep -ih foo /f1 /f\\ 2 | grep -ih -v bar | grep -ih baz"
27 (agp-command-line "foo !bar baz" '("/f1" "/f 2")))
28 (expect (concat "grep -ih foo " (expand-file-name "~/.emacs.el"))
29 (agp-command-line "foo" '("~/.emacs.el")))
30 (expect "grep -ih f\\ o /f\\ 1"
31 (agp-command-line "f o" '("/f 1")))
32 (expect "grep -ih foo /f1 | head -n 5"
33 (agp-command-line "foo" '("/f1") 5))
34 (expect "grep -ih foo /f1 | head -n 5 | nkf -w"
35 (agp-command-line "foo" '("/f1") 5 "nkf -w"))
36 (expect "cat /f1 | head -n 5 | nkf -w"
37 (agp-command-line "" '("/f1") 5 "nkf -w"))
38 (expect "tac /f1 | grep -ih foo"
39 (agp-command-line "foo" '("/f1") nil nil t))
40 (expect "tac /f1 | grep -ih foo | head -n 5 | nkf -w"
41 (agp-command-line "foo" '("/f1") 5 "nkf -w" t))
42 (expect "tac /f1 | head -n 5 | nkf -w"
43 (agp-command-line "" '("/f1") 5 "nkf -w" t))
44 (desc "anything-mp-1-search")
45 (expect (non-nil)
46 (with-temp-buffer
47 (insert "fire\nthunder\n")
48 (goto-char 1)
49 (anything-mp-1-search "th+ r" nil t)))
50 (desc "anything-mp-2-search")
51 (expect (non-nil)
52 (with-temp-buffer
53 (insert "fire\nthunder\n")
54 (goto-char 1)
55 (anything-mp-2-search "h+ r" nil t)))
56 (expect nil
57 (with-temp-buffer
58 (insert "fire\nthunder\n")
59 (goto-char 1)
60 (anything-mp-2-search "r th+" nil t)))
61 (desc "anything-mp-3-search")
62 (expect (non-nil)
63 (with-temp-buffer
64 (insert "fire\nthunder\n")
65 (goto-char 1)
66 (anything-mp-3-search "h+ r" nil t)))
67 (expect (non-nil)
68 (with-temp-buffer
69 (insert "fire\nthunder\n")
70 (goto-char 1)
71 (anything-mp-3-search "th+ r" nil t)))
72 (expect (non-nil)
73 (with-temp-buffer
74 (insert "fire\nthunder\n")
75 (goto-char 1)
76 (anything-mp-3-search "r th+" nil t)))
77 (expect nil
78 (with-temp-buffer
79 (insert "fire\nthunder\n")
80 (goto-char 1)
81 (anything-mp-3-search "under hue" nil t)))
82 (expect (non-nil)
83 (with-temp-buffer
84 (insert "fire\nthunder\n")
85 (goto-char 1)
86 (anything-mp-3-search "r th+ n" nil t)))
87 (desc "anything-mp-3-search")
88 (expect (non-nil)
89 (with-temp-buffer
90 (insert "fire\nthunder\n")
91 (goto-char 1)
92 (anything-mp-3-search "th der" nil t)))
93 (expect nil
94 (with-temp-buffer
95 (insert "fire\nthunder\n")
96 (goto-char 1)
97 (anything-mp-3-search "th ders" nil t)))
98 (desc "anything-mp-3-search not")
99 (expect t
100 (with-temp-buffer
101 (insert "threshold\nthunder\n")
102 (goto-char 1)
103 (anything-mp-3-search "h !der" nil t)))
104 (expect t
105 (with-temp-buffer
106 (insert "threshold\nthunder\n")
107 (goto-char 1)
108 (anything-mp-3-search "!der h" nil t)))
109 (desc "anything-mp-3p-search")
110 (expect (non-nil)
111 (with-temp-buffer
112 (insert "fire\nthunder\n")
113 (goto-char 1)
114 (anything-mp-3p-search "th der" nil t)))
115 (expect nil
116 (with-temp-buffer
117 (insert "fire\nthunder\n")
118 (goto-char 1)
119 (anything-mp-3p-search "h ders" nil t)))
120 (desc "anything-mp-3p-search not")
121 (expect t
122 (with-temp-buffer
123 (insert "\nthreshold\nthunder\n")
124 (goto-char 1)
125 (anything-mp-3p-search "th !der" nil t)))
126 (expect nil
127 (with-temp-buffer
128 (insert "threshold\nthunder\n")
129 (goto-char 1)
130 (anything-mp-3p-search "h !der" nil t)))
131 (desc "anything-mp-3-search-backward")
132 (expect (non-nil)
133 (with-temp-buffer
134 (insert "fire\nthunder\n")
135 (goto-char (point-max))
136 (anything-mp-3-search-backward "h der" nil t)))
137 (expect nil
138 (with-temp-buffer
139 (insert "fire\nthunder\n")
140 (goto-char (point-max))
141 (anything-mp-3-search-backward "th ders" nil t)))
142 (desc "anything-mp-3-search-backward not")
143 (expect t
144 (with-temp-buffer
145 (insert "threshold\nthunder\n")
146 (goto-char (point-max))
147 (anything-mp-3-search-backward "h !der" nil t)))
148 (expect t
149 (with-temp-buffer
150 (insert "threshold\nthunder\n")
151 (goto-char (point-max))
152 (anything-mp-3-search-backward "!der h" nil t)))
153 (desc "anything-mp-3p-search-backward")
154 (expect (non-nil)
155 (with-temp-buffer
156 (insert "fire\nthunder\n")
157 (goto-char (point-max))
158 (anything-mp-3p-search-backward "th der" nil t)))
159 (expect nil
160 (with-temp-buffer
161 (insert "fire\nthunder\n")
162 (goto-char (point-max))
163 (anything-mp-3p-search-backward "h der" nil t)))
164 (desc "anything-mp-3p-search-backward not")
165 (expect t
166 (with-temp-buffer
167 (insert "\nthreshold\nthunder\n")
168 (goto-char (point-max))
169 (anything-mp-3p-search-backward "th !der" nil t)))
170 (expect nil
171 (with-temp-buffer
172 (insert "threshold\nthunder\n")
173 (goto-char (point-max))
174 (anything-mp-3p-search-backward "h !der" nil t)))
175 (desc "anything-mp-1-match")
176 (expect (non-nil)
177 (anything-mp-1-match "thunder" "th+ r"))
178 (desc "anything-mp-2-match")
179 (expect (non-nil)
180 (anything-mp-2-match "thunder" "h+ r"))
181 (expect nil
182 (anything-mp-2-match "thunder" "r th+"))
183 (desc "anything-mp-3-match")
184 (expect (non-nil)
185 (anything-mp-3-match "thunder" "h+ r"))
186 (expect (non-nil)
187 (anything-mp-3-match "thunder" "th+ r"))
188 (expect (non-nil)
189 (anything-mp-3-match "thunder" "r th+"))
190 (expect nil
191 (anything-mp-3-match "thunder" "under hue"))
192 (expect (non-nil)
193 (anything-mp-3-match "thunder" "r th+ n"))
194 (desc "anything-mp-3-match not")
195 (expect (non-nil)
196 (anything-mp-3-match "threshold" "th !der"))
197 (expect (non-nil)
198 (anything-mp-3-match "threshold" "!der th"))
199 (desc "anything-mp-3-match")
200 (expect (non-nil)
201 (anything-mp-3-match "thunder" "h der"))
202 (expect nil
203 (anything-mp-3-match "thunder" "h ders"))
204 (desc "anything-mp-3p-match")
205 (expect (non-nil)
206 (anything-mp-3p-match "thunder" "th der"))
207 (expect nil
208 (anything-mp-3p-match "thunder" "h der"))
209 (desc "anything-mp-3p-match not")
210 (expect (non-nil)
211 (anything-mp-3p-match "threshold" "th !der"))
212 (expect nil
213 (anything-mp-3p-match "threshold" "h !der"))
214 (desc "with identity match")
215 (expect '(identity)
216 (assoc-default 'match
217 (car (anything-compile-sources
218 '(((name . "FOO")
219 (candidates-in-buffer)))
220 '(anything-compile-source--candidates-in-buffer
221 anything-compile-source--match-plugin)))))
222 (expect '(identity)
223 (assoc-default 'match
224 (car (anything-compile-sources
225 '(((name . "FOO")
226 (match identity)))
227 '(anything-compile-source--match-plugin)))))
228 (desc "functional")
229 (expect '(("FOO" ("thunder")))
230 (anything-test-candidates '(((name . "FOO")
231 (candidates "fire" "thunder")))
232 "th r"
233 '(anything-compile-source--match-plugin)))
234 (expect '(("FOO" ("one two")))
235 (let ((anything-mp-space-regexp "\\\\ "))
236 (anything-test-candidates '(((name . "FOO")
237 (candidates "one two" "three four")))
238 "e\\ t"
239 '(anything-compile-source--match-plugin))))
240 (expect '(("FOO" ("one two")))
241 (let ((anything-mp-space-regexp " "))
242 (anything-test-candidates '(((name . "FOO")
243 (candidates "one two" "three four")))
244 "e t"
245 '(anything-compile-source--match-plugin))))
246 (expect '(("FOO" ("thunder")))
247 (anything-test-candidates '(((name . "FOO")
248 (init
249 . (lambda ()
250 (with-current-buffer (anything-candidate-buffer 'global)
251 (insert "fire\nthunder\nthanks\n"))))
252 (candidates-in-buffer)))
253 "th r"
254 '(anything-compile-source--candidates-in-buffer
255 anything-compile-source--match-plugin)))
256 (expect '(("FOO" ("foo" "foobar")))
257 (anything-test-candidates '(((name . "FOO")
258 (candidates "foobar" "foo")))
259 "foo"
260 '(anything-compile-source--match-plugin)))
261 (expect '(("FOO" ("foo" "foobar")))
262 (anything-test-candidates '(((name . "FOO")
263 (init
264 . (lambda ()
265 (with-current-buffer (anything-candidate-buffer 'global)
266 (insert "foobar\nfoo\n"))))
267 (candidates-in-buffer)))
268 "foo"
269 '(anything-compile-source--candidates-in-buffer
270 anything-compile-source--match-plugin)))
271 (expect '(("FOO" ("foo")))
272 (anything-test-candidates '(((name . "FOO")
273 (init
274 . (lambda ()
275 (with-current-buffer (anything-candidate-buffer 'global)
276 (insert "foo\n"))))
277 (candidates-in-buffer)))
278 "foo"
279 '(anything-compile-source--candidates-in-buffer
280 anything-compile-source--match-plugin)))
281 (expect '(("FOO" ("foo")))
282 (anything-test-candidates '(((name . "FOO")
283 (init
284 . (lambda ()
285 (with-current-buffer (anything-candidate-buffer 'global)
286 (insert "bar\nfoo\ntest\n"))))
287 (candidates-in-buffer)))
288 "foo"
289 '(anything-compile-source--candidates-in-buffer
290 anything-compile-source--match-plugin)))
291 (expect '(("FOO" ("foobar" "foo")))
292 (anything-test-candidates '(((name . "FOO")
293 (init
294 . (lambda ()
295 (with-current-buffer (anything-candidate-buffer 'global)
296 (insert "foobar\nfoo\n"))))
297 (candidates-in-buffer)))
299 '(anything-compile-source--candidates-in-buffer
300 anything-compile-source--match-plugin)))
301 (expect '(("FOO" ("foo" "foobar")))
302 (anything-test-candidates '(((name . "FOO")
303 (init
304 . (lambda ()
305 (with-current-buffer (anything-candidate-buffer 'global)
306 (insert "foobar\nfoo\n"))))
307 (candidates-in-buffer)
308 (search-from-end)))
309 "foo"
310 '(anything-compile-source--candidates-in-buffer
311 anything-compile-source--match-plugin)))
312 (expect '(("FOO" ("elisp" "elp")))
313 (anything-test-candidates '(((name . "FOO")
314 (init
315 . (lambda ()
316 (with-current-buffer (anything-candidate-buffer 'global)
317 (insert "elp\nelisp\n"))))
318 (candidates-in-buffer)
319 (search-from-end)))
320 "el p"
321 '(anything-compile-source--candidates-in-buffer
322 anything-compile-source--match-plugin)))
323 (expect '(("FOO" ("elisp" )))
324 (anything-test-candidates '(((name . "FOO")
325 (init
326 . (lambda ()
327 (with-current-buffer (anything-candidate-buffer 'global)
328 (insert "elp\nelisp\n"))))
329 (candidates-in-buffer)
330 (search-from-end)))
331 "el+ isp"
332 '(anything-compile-source--candidates-in-buffer
333 anything-compile-source--match-plugin)))
334 ;; prefix multi -> multi
335 (expect '(("FOO" ("info.el" "elisp-info")))
336 (anything-test-candidates '(((name . "FOO")
337 (init
338 . (lambda ()
339 (with-current-buffer (anything-candidate-buffer 'global)
340 (insert "info.el\nelisp-info\n"))))
341 (candidates-in-buffer)))
342 "el info"
343 '(anything-compile-source--candidates-in-buffer
344 anything-compile-source--match-plugin)))
345 ;; multi not
346 (expect '(("FOO" ("info.el")))
347 (anything-test-candidates '(((name . "FOO")
348 (init
349 . (lambda ()
350 (with-current-buffer (anything-candidate-buffer 'global)
351 (insert "info.el\nelisp-info\n"))))
352 (candidates-in-buffer)))
353 "info !elisp"
354 '(anything-compile-source--candidates-in-buffer
355 anything-compile-source--match-plugin)))
356 (expect '(("FOO" ("info.el")))
357 (anything-test-candidates '(((name . "FOO")
358 (init
359 . (lambda ()
360 (with-current-buffer (anything-candidate-buffer 'global)
361 (insert "info.el\nelisp-info\n"))))
362 (candidates-in-buffer)))
363 "!elisp info"
364 '(anything-compile-source--candidates-in-buffer
365 anything-compile-source--match-plugin)))
366 (expect '(("FOO" ("info.el")))
367 (anything-test-candidates '(((name . "FOO")
368 (candidates "info.el" "elisp-info.el")))
369 "info !elisp"
370 '(anything-compile-source--match-plugin)))
371 (expect '(("FOO" ("info.el")))
372 (anything-test-candidates '(((name . "FOO")
373 (candidates "info.el" "elisp-info.el")))
374 "!elisp info"
375 '(anything-compile-source--match-plugin)))
377 ;; (anything-compile-sources '(((name . "test"))) anything-compile-source-functions)