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")
6 (when (fboundp 'expectations
)
8 (require 'anything-match-plugin
)
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")
47 (insert "fire\nthunder\n")
49 (anything-mp-1-search "th+ r" nil t
)))
50 (desc "anything-mp-2-search")
53 (insert "fire\nthunder\n")
55 (anything-mp-2-search "h+ r" nil t
)))
58 (insert "fire\nthunder\n")
60 (anything-mp-2-search "r th+" nil t
)))
61 (desc "anything-mp-3-search")
64 (insert "fire\nthunder\n")
66 (anything-mp-3-search "h+ r" nil t
)))
69 (insert "fire\nthunder\n")
71 (anything-mp-3-search "th+ r" nil t
)))
74 (insert "fire\nthunder\n")
76 (anything-mp-3-search "r th+" nil t
)))
79 (insert "fire\nthunder\n")
81 (anything-mp-3-search "under hue" nil t
)))
84 (insert "fire\nthunder\n")
86 (anything-mp-3-search "r th+ n" nil t
)))
87 (desc "anything-mp-3-search")
90 (insert "fire\nthunder\n")
92 (anything-mp-3-search "th der" nil t
)))
95 (insert "fire\nthunder\n")
97 (anything-mp-3-search "th ders" nil t
)))
98 (desc "anything-mp-3-search not")
101 (insert "threshold\nthunder\n")
103 (anything-mp-3-search "h !der" nil t
)))
106 (insert "threshold\nthunder\n")
108 (anything-mp-3-search "!der h" nil t
)))
109 (desc "anything-mp-3p-search")
112 (insert "fire\nthunder\n")
114 (anything-mp-3p-search "th der" nil t
)))
117 (insert "fire\nthunder\n")
119 (anything-mp-3p-search "h ders" nil t
)))
120 (desc "anything-mp-3p-search not")
123 (insert "\nthreshold\nthunder\n")
125 (anything-mp-3p-search "th !der" nil t
)))
128 (insert "threshold\nthunder\n")
130 (anything-mp-3p-search "h !der" nil t
)))
131 (desc "anything-mp-3-search-backward")
134 (insert "fire\nthunder\n")
135 (goto-char (point-max))
136 (anything-mp-3-search-backward "h der" nil t
)))
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")
145 (insert "threshold\nthunder\n")
146 (goto-char (point-max))
147 (anything-mp-3-search-backward "h !der" nil t
)))
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")
156 (insert "fire\nthunder\n")
157 (goto-char (point-max))
158 (anything-mp-3p-search-backward "th der" nil t
)))
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")
167 (insert "\nthreshold\nthunder\n")
168 (goto-char (point-max))
169 (anything-mp-3p-search-backward "th !der" nil t
)))
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")
177 (anything-mp-1-match "thunder" "th+ r"))
178 (desc "anything-mp-2-match")
180 (anything-mp-2-match "thunder" "h+ r"))
182 (anything-mp-2-match "thunder" "r th+"))
183 (desc "anything-mp-3-match")
185 (anything-mp-3-match "thunder" "h+ r"))
187 (anything-mp-3-match "thunder" "th+ r"))
189 (anything-mp-3-match "thunder" "r th+"))
191 (anything-mp-3-match "thunder" "under hue"))
193 (anything-mp-3-match "thunder" "r th+ n"))
194 (desc "anything-mp-3-match not")
196 (anything-mp-3-match "threshold" "th !der"))
198 (anything-mp-3-match "threshold" "!der th"))
199 (desc "anything-mp-3-match")
201 (anything-mp-3-match "thunder" "h der"))
203 (anything-mp-3-match "thunder" "h ders"))
204 (desc "anything-mp-3p-match")
206 (anything-mp-3p-match "thunder" "th der"))
208 (anything-mp-3p-match "thunder" "h der"))
209 (desc "anything-mp-3p-match not")
211 (anything-mp-3p-match "threshold" "th !der"))
213 (anything-mp-3p-match "threshold" "h !der"))
214 (desc "with identity match")
216 (assoc-default 'match
217 (car (anything-compile-sources
219 (candidates-in-buffer)))
220 '(anything-compile-source--candidates-in-buffer
221 anything-compile-source--match-plugin
)))))
223 (assoc-default 'match
224 (car (anything-compile-sources
227 '(anything-compile-source--match-plugin)))))
229 (expect '(("FOO" ("thunder")))
230 (anything-test-candidates '(((name .
"FOO")
231 (candidates "fire" "thunder")))
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")))
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")))
245 '(anything-compile-source--match-plugin))))
246 (expect '(("FOO" ("thunder")))
247 (anything-test-candidates '(((name .
"FOO")
250 (with-current-buffer (anything-candidate-buffer 'global
)
251 (insert "fire\nthunder\nthanks\n"))))
252 (candidates-in-buffer)))
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")))
260 '(anything-compile-source--match-plugin)))
261 (expect '(("FOO" ("foo" "foobar")))
262 (anything-test-candidates '(((name .
"FOO")
265 (with-current-buffer (anything-candidate-buffer 'global
)
266 (insert "foobar\nfoo\n"))))
267 (candidates-in-buffer)))
269 '(anything-compile-source--candidates-in-buffer
270 anything-compile-source--match-plugin
)))
271 (expect '(("FOO" ("foo")))
272 (anything-test-candidates '(((name .
"FOO")
275 (with-current-buffer (anything-candidate-buffer 'global
)
277 (candidates-in-buffer)))
279 '(anything-compile-source--candidates-in-buffer
280 anything-compile-source--match-plugin
)))
281 (expect '(("FOO" ("foo")))
282 (anything-test-candidates '(((name .
"FOO")
285 (with-current-buffer (anything-candidate-buffer 'global
)
286 (insert "bar\nfoo\ntest\n"))))
287 (candidates-in-buffer)))
289 '(anything-compile-source--candidates-in-buffer
290 anything-compile-source--match-plugin
)))
291 (expect '(("FOO" ("foobar" "foo")))
292 (anything-test-candidates '(((name .
"FOO")
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")
305 (with-current-buffer (anything-candidate-buffer 'global
)
306 (insert "foobar\nfoo\n"))))
307 (candidates-in-buffer)
310 '(anything-compile-source--candidates-in-buffer
311 anything-compile-source--match-plugin
)))
312 (expect '(("FOO" ("elisp" "elp")))
313 (anything-test-candidates '(((name .
"FOO")
316 (with-current-buffer (anything-candidate-buffer 'global
)
317 (insert "elp\nelisp\n"))))
318 (candidates-in-buffer)
321 '(anything-compile-source--candidates-in-buffer
322 anything-compile-source--match-plugin
)))
323 (expect '(("FOO" ("elisp" )))
324 (anything-test-candidates '(((name .
"FOO")
327 (with-current-buffer (anything-candidate-buffer 'global
)
328 (insert "elp\nelisp\n"))))
329 (candidates-in-buffer)
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")
339 (with-current-buffer (anything-candidate-buffer 'global
)
340 (insert "info.el\nelisp-info\n"))))
341 (candidates-in-buffer)))
343 '(anything-compile-source--candidates-in-buffer
344 anything-compile-source--match-plugin
)))
346 (expect '(("FOO" ("info.el")))
347 (anything-test-candidates '(((name .
"FOO")
350 (with-current-buffer (anything-candidate-buffer 'global
)
351 (insert "info.el\nelisp-info\n"))))
352 (candidates-in-buffer)))
354 '(anything-compile-source--candidates-in-buffer
355 anything-compile-source--match-plugin
)))
356 (expect '(("FOO" ("info.el")))
357 (anything-test-candidates '(((name .
"FOO")
360 (with-current-buffer (anything-candidate-buffer 'global
)
361 (insert "info.el\nelisp-info\n"))))
362 (candidates-in-buffer)))
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")))
370 '(anything-compile-source--match-plugin)))
371 (expect '(("FOO" ("info.el")))
372 (anything-test-candidates '(((name .
"FOO")
373 (candidates "info.el" "elisp-info.el")))
375 '(anything-compile-source--match-plugin)))
377 ;; (anything-compile-sources '(((name . "test"))) anything-compile-source-functions)