1 ;;; unit tests for anything.el
2 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
3 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
6 (defmacro anything-test-update
(sources pattern
)
7 "Test helper macro for anything. It is meant for testing *anything* buffer contents."
8 `(progn (stub anything-get-sources
=> ,sources
)
9 (stub anything-log-run-hook
=> nil
)
10 (stub run-with-idle-timer
=> nil
)
11 (let (anything-test-mode (anything-pattern ,pattern
))
16 (when (fboundp 'expectations
)
18 (desc "anything-current-buffer")
20 (with-current-buffer (get-buffer-create "__a_buffer")
21 (anything-test-candidates '(((name .
"FOO"))) "")
23 (buffer-name anything-current-buffer
)
24 (kill-buffer "__a_buffer")
26 (desc "anything-buffer-file-name")
27 (expect (regexp "/__a_file__")
28 (with-current-buffer (get-buffer-create "__a_file__")
29 (setq buffer-file-name
"/__a_file__")
30 (anything-test-candidates '(((name .
"FOO"))) "")
32 anything-buffer-file-name
33 ;;(kill-buffer "__a_file__")
35 (desc "anything-interpret-value")
37 (anything-interpret-value "literal"))
39 (anything-interpret-value (lambda () "lambda")))
40 (expect "lambda with source name"
41 (let ((source '((name .
"lambda with source name"))))
42 (anything-interpret-value (lambda () anything-source-name
) source
)))
43 (expect "function symbol"
44 (flet ((f () "function symbol"))
45 (anything-interpret-value 'f
)))
46 (expect "variable symbol"
47 (let ((v "variable symbol"))
48 (anything-interpret-value 'v
)))
49 (expect (error error
*)
50 (anything-interpret-value 'unbounded-1
))
51 (desc "anything-compile-sources")
52 (expect '(((name .
"foo")))
53 (anything-compile-sources '(((name .
"foo"))) nil
)
55 (expect '(((name .
"foo") (type . test
) (action . identity
)))
56 (let ((anything-type-attributes '((test (action . identity
)))))
57 (anything-compile-sources '(((name .
"foo") (type . test
)))
58 '(anything-compile-source--type))))
59 (desc "anything-sources accepts symbols")
60 (expect '(((name .
"foo")))
61 (let* ((foo '((name .
"foo"))))
62 (anything-compile-sources '(foo) nil
)))
63 (desc "anything-get-sources action")
64 (expect '(((name .
"Actions") (candidates . actions
)))
65 (stub anything-action-window
=> t
)
66 (let (anything-compiled-sources
67 (anything-sources '(((name .
"Actions") (candidates . actions
)))))
68 (anything-get-sources)))
69 (desc "get-buffer-create candidates-buffer")
70 (expect '(((name .
"many") (init . many-init
)
71 (candidates-in-buffer . anything-candidates-in-buffer
)
72 (candidates . anything-candidates-in-buffer
)
73 (volatile) (match identity
)))
74 (anything-compile-sources
75 '(((name .
"many") (init . many-init
)
76 (candidates-in-buffer . anything-candidates-in-buffer
)))
77 '(anything-compile-source--candidates-in-buffer)))
78 (expect '(((name .
"many") (init . many-init
)
79 (candidates-in-buffer)
80 (candidates . anything-candidates-in-buffer
)
81 (volatile) (match identity
)))
82 (anything-compile-sources
83 '(((name .
"many") (init . many-init
)
84 (candidates-in-buffer)))
85 '(anything-compile-source--candidates-in-buffer)))
86 (expect '(((name .
"many") (init . many-init
)
87 (candidates-in-buffer)
90 (candidates . anything-candidates-in-buffer
)
91 (volatile) (match identity
)))
92 (let ((anything-type-attributes '((test (action . identity
)))))
93 (anything-compile-sources
94 '(((name .
"many") (init . many-init
)
95 (candidates-in-buffer)
97 '(anything-compile-source--type
98 anything-compile-source--candidates-in-buffer
))))
100 (desc "anything-get-candidates")
101 (expect '("foo" "bar")
102 (anything-get-candidates '((name .
"foo") (candidates "foo" "bar"))))
103 (expect '("FOO" "BAR")
104 (anything-get-candidates '((name .
"foo") (candidates "foo" "bar")
105 (candidate-transformer
106 .
(lambda (cands) (mapcar 'upcase cands
))))))
107 (expect '("foo" "bar")
108 (anything-get-candidates '((name .
"foo")
109 (candidates .
(lambda () '("foo" "bar"))))))
110 (expect '("foo" "bar")
111 (let ((var '("foo" "bar")))
112 (anything-get-candidates '((name .
"foo")
113 (candidates . var
)))))
114 (expect (error error
*)
115 (anything-get-candidates '((name .
"foo")
116 (candidates .
"err"))))
117 (expect (error error
*)
119 (anything-get-candidates '((name .
"foo")
120 (candidates . var
)))))
121 (expect (error error
*)
122 (anything-get-candidates '((name .
"foo")
123 (candidates . unDeFined-syMbol
))))
124 (desc "anything-compute-matches")
125 (expect '("foo" "bar")
126 (let ((anything-pattern ""))
127 (anything-compute-matches '((name .
"FOO") (candidates "foo" "bar") (volatile)))))
129 (let ((anything-pattern "oo"))
130 (anything-compute-matches '((name .
"FOO") (candidates "foo" "bar") (volatile)))))
132 (let ((anything-pattern "^b"))
133 (anything-compute-matches '((name .
"FOO") (candidates "foo" "bar") (volatile)))))
135 (let ((anything-pattern "")
136 (anything-candidate-number-limit 2))
137 (anything-compute-matches '((name .
"FOO") (candidates "a" "b" "c") (volatile)))))
139 (let ((anything-pattern ".")
140 (anything-candidate-number-limit 2))
141 (anything-compute-matches '((name .
"FOO") (candidates "a" "b" "c") (volatile)))))
142 (expect '("a" "b" "c")
143 (let ((anything-pattern "")
144 anything-candidate-number-limit
)
145 (anything-compute-matches '((name .
"FOO") (candidates "a" "b" "c") (volatile)))))
146 (expect '("a" "b" "c")
147 (let ((anything-pattern "[abc]")
148 anything-candidate-number-limit
)
149 (anything-compute-matches '((name .
"FOO") (candidates "a" "b" "c") (volatile)))))
151 (let ((anything-pattern "[abc]")
152 anything-candidate-number-limit
)
153 (anything-compute-matches '((name .
"FOO") (candidates a b c
) (volatile)))))
154 (expect '(("foo" .
"FOO") ("bar" .
"BAR"))
155 (let ((anything-pattern ""))
156 (anything-compute-matches '((name .
"FOO") (candidates ("foo" .
"FOO") ("bar" .
"BAR")) (volatile)))))
157 (expect '(("foo" .
"FOO"))
158 (let ((anything-pattern "foo"))
159 (anything-compute-matches '((name .
"FOO") (candidates ("foo" .
"FOO") ("bar" .
"foo")) (volatile)))))
160 ;; using anything-test-candidate-list
161 (desc "anything-test-candidates")
162 (expect '(("FOO" ("foo" "bar")))
163 (anything-test-candidates '(((name .
"FOO") (candidates "foo" "bar")))))
164 (expect '(("FOO" ("bar")))
165 (anything-test-candidates '(((name .
"FOO") (candidates "foo" "bar"))) "ar"))
166 (expect '(("T1" ("hoge" "aiue"))
167 ("T2" ("test" "boke")))
168 (anything-test-candidates '(((name .
"T1") (candidates "hoge" "aiue"))
169 ((name .
"T2") (candidates "test" "boke")))))
170 (expect '(("T1" ("hoge"))
172 (anything-test-candidates '(((name .
"T1") (candidates "hoge" "aiue"))
173 ((name .
"T2") (candidates "test" "boke"))) "o"))
174 (desc "requires-pattern attribute")
176 (anything-test-candidates '(((name .
"FOO") (candidates "foo" "bar")
177 (requires-pattern .
1)))))
178 (expect '(("FOO" ("bar")))
179 (anything-test-candidates '(((name .
"FOO") (candidates "foo" "bar")
180 (requires-pattern .
1))) "b"))
181 (desc "delayed attribute(for test)")
182 (expect '(("T2" ("boke"))
184 (anything-test-candidates
185 '(((name .
"T1") (candidates "hoge" "aiue") (delayed))
186 ((name .
"T2") (candidates "test" "boke")))
188 (desc "match attribute(prefix search)")
189 (expect '(("FOO" ("bar")))
190 (anything-test-candidates
191 '(((name .
"FOO") (candidates "foo" "bar")
192 (match (lambda (c) (string-match (concat "^" anything-pattern
) c
)))))
195 (anything-test-candidates
196 '(((name .
"FOO") (candidates "foo" "bar")
197 (match (lambda (c) (string-match (concat "^" anything-pattern
) c
)))))
201 (anything-test-candidates
202 '(((name .
"TestSource") (candidates "a")
203 (match (lambda (c) (setq x anything-source-name
)))))
206 (desc "init attribute")
207 (expect '(("FOO" ("bar")))
209 (anything-test-candidates
210 '(((name .
"FOO") (init .
(lambda () (setq v
'("foo" "bar"))))
213 (desc "candidate-transformer attribute")
214 (expect '(("FOO" ("BAR")))
215 (anything-test-candidates '(((name .
"FOO") (candidates "foo" "bar")
216 (candidate-transformer
217 .
(lambda (cands) (mapcar 'upcase cands
)))))
219 (desc "filtered-candidate-transformer attribute")
221 (expect '(("FOO" ("BAR")))
222 (anything-test-candidates '(((name .
"FOO") (candidates "foo" "bar")
223 (filtered-candidate-transformer
224 .
(lambda (cands src
) (mapcar 'upcase cands
)))))
226 (desc "anything-transform-candidates in process")
227 (expect (mock (anything-composed-funcall-with-source
228 '((name .
"FOO") (candidates "foo" "bar")
229 (filtered-candidate-transformer
230 .
(lambda (cands src
) (mapcar 'upcase cands
))))
231 (lambda (cands src
) (mapcar 'upcase cands
))
233 '((name .
"FOO") (candidates "foo" "bar")
234 (filtered-candidate-transformer
235 .
(lambda (cands src
) (mapcar 'upcase cands
))))
237 (stub anything-process-candidate-transformer
=> '("foo" "bar"))
238 (anything-transform-candidates
240 '((name .
"FOO") (candidates "foo" "bar")
241 (filtered-candidate-transformer
242 .
(lambda (cands src
) (mapcar 'upcase cands
))))
245 (desc "anything-candidates-in-buffer-1")
247 (anything-candidates-in-buffer-1
249 'buffer-substring-no-properties
'(re-search-forward) 50 nil
))
250 (expect '("foo+" "bar+" "baz+")
252 (insert "foo+\nbar+\nbaz+\n")
253 (anything-candidates-in-buffer-1
255 'buffer-substring-no-properties
'(re-search-forward) 5 nil
)))
256 (expect '("foo+" "bar+")
258 (insert "foo+\nbar+\nbaz+\n")
259 (anything-candidates-in-buffer-1
261 'buffer-substring-no-properties
'(re-search-forward) 2 nil
)))
264 (insert "foo+\nbar+\nbaz+\n")
265 (anything-candidates-in-buffer-1
266 (current-buffer) "oo\\+"
267 'buffer-substring-no-properties
'(re-search-forward) 50 nil
)))
270 (insert "foo+\nbar+\nbaz+\n")
271 (anything-candidates-in-buffer-1
272 (current-buffer) "oo+"
273 #'buffer-substring-no-properties
'(search-forward) 50 nil
)))
274 (expect '("foo+" "bar+")
276 (insert "foo+\nbar+\nbaz+\n")
277 (anything-candidates-in-buffer-1
279 'buffer-substring-no-properties
'(re-search-forward) 2 nil
)))
280 (expect '(("foo+" "FOO+"))
282 (insert "foo+\nbar+\nbaz+\n")
283 (anything-candidates-in-buffer-1
284 (current-buffer) "oo\\+"
286 (let ((l (buffer-substring-no-properties s e
)))
287 (list l
(upcase l
))))
288 '(re-search-forward) 50 nil
)))
289 (desc "anything-candidates-in-buffer")
290 (expect '(("TEST" ("foo+" "bar+" "baz+")))
291 (anything-test-candidates
294 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
295 (insert "foo+\nbar+\nbaz+\n"))))
296 (candidates . anything-candidates-in-buffer
)
299 (expect '(("TEST" ("foo+" "bar+" "baz+")))
300 (let (anything-candidate-number-limit)
301 (anything-test-candidates
304 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
305 (insert "foo+\nbar+\nbaz+\n"))))
306 (candidates . anything-candidates-in-buffer
)
309 (expect '(("TEST" ("foo+")))
310 (anything-test-candidates
313 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
314 (insert "foo+\nbar+\nbaz+\n"))))
315 (candidates . anything-candidates-in-buffer
)
319 ;; BUG remain empty string, but the pattern is rare case.
320 (expect '(("a" ("" "a" "b")))
321 (anything-test-candidates
324 (with-current-buffer (anything-candidate-buffer 'global
)
326 (candidates-in-buffer)))
328 (desc "search attribute")
329 (expect '(("TEST" ("foo+")))
330 (anything-test-candidates
333 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
334 (insert "foo+\nbar+\nbaz+\nooo\n"))))
335 (search search-forward
)
336 (candidates . anything-candidates-in-buffer
)
340 (expect '(("TEST" ("foo+" "ooo")))
341 (anything-test-candidates
344 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
345 (insert "foo+\nbar+\nbaz+\nooo\n"))))
346 (search search-forward re-search-forward
)
347 (candidates . anything-candidates-in-buffer
)
351 (expect '(("TEST" ("foo+" "ooo")))
352 (anything-test-candidates
355 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
356 (insert "foo+\nbar+\nbaz+\nooo\n"))))
357 (search re-search-forward search-forward
)
358 (candidates . anything-candidates-in-buffer
)
362 (expect '(("TEST" ("ooo" "foo+")))
363 (anything-test-candidates
366 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
367 (insert "bar+\nbaz+\nooo\nfoo+\n"))))
368 (search re-search-forward search-forward
)
369 (candidates . anything-candidates-in-buffer
)
373 ;; faster exact match
374 (expect '(("TEST" ("bar+")))
375 (anything-test-candidates
378 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
379 (insert "bar+\nbaz+\nooo\nfoo+\n"))))
380 (search (lambda (pattern &rest _
)
381 (and (search-forward (concat "\n" pattern
"\n") nil t
)
383 (candidates . anything-candidates-in-buffer
)
387 ;; faster prefix match
388 (expect '(("TEST" ("bar+")))
389 (anything-test-candidates
392 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
393 (insert "bar+\nbaz+\nooo\nfoo+\n"))))
394 (search (lambda (pattern &rest _
)
395 (search-forward (concat "\n" pattern
) nil t
)))
396 (candidates . anything-candidates-in-buffer
)
400 (desc "anything-current-buffer-is-modified")
401 (expect '(("FOO" ("modified")))
402 (let ((sources '(((name .
"FOO")
405 (if (anything-current-buffer-is-modified)
407 '("unmodified"))))))))
409 (clrhash anything-tick-hash
)
411 (anything-test-candidates sources
))))
412 (expect '(("FOO" ("unmodified")))
413 (let ((sources '(((name .
"FOO")
416 (if (anything-current-buffer-is-modified)
418 '("unmodified"))))))))
420 (clrhash anything-tick-hash
)
422 (anything-test-candidates sources
)
423 (anything-test-candidates sources
))))
424 (expect '(("FOO" ("modified")))
425 (let ((sources '(((name .
"FOO")
428 (if (anything-current-buffer-is-modified)
430 '("unmodified"))))))))
432 (clrhash anything-tick-hash
)
434 (anything-test-candidates sources
)
436 (anything-test-candidates sources
))))
437 (expect '(("BAR" ("modified")))
438 (let ((sources1 '(((name .
"FOO")
441 (if (anything-current-buffer-is-modified)
443 '("unmodified")))))))
444 (sources2 '(((name .
"BAR")
447 (if (anything-current-buffer-is-modified)
449 '("unmodified"))))))))
451 (clrhash anything-tick-hash
)
453 (anything-test-candidates sources1
)
454 (anything-test-candidates sources2
))))
455 (expect '(("FOO" ("unmodified")))
456 (let ((sources1 '(((name .
"FOO")
459 (if (anything-current-buffer-is-modified)
461 '("unmodified")))))))
462 (sources2 '(((name .
"BAR")
465 (if (anything-current-buffer-is-modified)
467 '("unmodified"))))))))
469 (clrhash anything-tick-hash
)
471 (anything-test-candidates sources1
)
472 (anything-test-candidates sources2
)
473 (anything-test-candidates sources1
))))
474 (expect '(("BAR" ("unmodified")))
475 (let ((sources1 '(((name .
"FOO")
478 (if (anything-current-buffer-is-modified)
480 '("unmodified")))))))
481 (sources2 '(((name .
"BAR")
484 (if (anything-current-buffer-is-modified)
486 '("unmodified"))))))))
488 (clrhash anything-tick-hash
)
490 (anything-test-candidates sources1
)
491 (anything-test-candidates sources2
)
492 (anything-test-candidates sources2
))))
493 (expect '(("BAR" ("modified")))
494 (let ((sources1 '(((name .
"FOO")
497 (if (anything-current-buffer-is-modified)
499 '("unmodified")))))))
500 (sources2 '(((name .
"BAR")
503 (if (anything-current-buffer-is-modified)
505 '("unmodified"))))))))
507 (clrhash anything-tick-hash
)
509 (anything-test-candidates sources1
)
510 (anything-test-candidates sources2
)
512 (anything-test-candidates sources2
)))))
513 (desc "anything-source-name")
516 (anything-test-candidates '(((name .
"FOO")
518 .
(lambda () (setq v anything-source-name
)))
523 (anything-test-candidates '(((name .
"FOO")
526 (setq v anything-source-name
)
531 (anything-test-candidates '(((name .
"FOO")
533 (candidate-transformer
535 (setq v anything-source-name
)
540 (anything-test-candidates '(((name .
"FOO")
542 (filtered-candidate-transformer
544 (setq v anything-source-name
)
549 (anything-test-candidates '(((name .
"FOO")
553 (setq v anything-source-name
)
555 (action . identity
))))
556 (anything-execute-selection-action)
558 (desc "anything-candidate-buffer create")
559 (expect " *anything candidates:FOO*"
560 (let* (anything-candidate-buffer-alist
561 (anything-source-name "FOO")
562 (buf (anything-candidate-buffer 'global
)))
563 (prog1 (buffer-name buf
)
565 (expect " *anything candidates:FOO*aTestBuffer"
566 (let* (anything-candidate-buffer-alist
567 (anything-source-name "FOO")
568 (anything-current-buffer (get-buffer-create "aTestBuffer"))
569 (buf (anything-candidate-buffer 'local
)))
570 (prog1 (buffer-name buf
)
571 (kill-buffer anything-current-buffer
)
574 (let (anything-candidate-buffer-alist
575 (anything-source-name "FOO") buf
)
576 (with-current-buffer (anything-candidate-buffer 'global
)
578 (setq buf
(anything-candidate-buffer 'global
))
579 (prog1 (buffer-size buf
)
581 (desc "anything-candidate-buffer get-buffer")
582 (expect " *anything candidates:FOO*"
583 (let* (anything-candidate-buffer-alist
584 (anything-source-name "FOO")
585 (buf (anything-candidate-buffer 'global
)))
586 (prog1 (buffer-name (anything-candidate-buffer))
588 (expect " *anything candidates:FOO*aTestBuffer"
589 (let* (anything-candidate-buffer-alist
590 (anything-source-name "FOO")
591 (anything-current-buffer (get-buffer-create "aTestBuffer"))
592 (buf (anything-candidate-buffer 'local
)))
593 (prog1 (buffer-name (anything-candidate-buffer))
594 (kill-buffer anything-current-buffer
)
596 (expect " *anything candidates:FOO*"
597 (let* (anything-candidate-buffer-alist
598 (anything-source-name "FOO")
599 (buf-local (anything-candidate-buffer 'local
))
600 (buf-global (anything-candidate-buffer 'global
)))
601 (prog1 (buffer-name (anything-candidate-buffer))
602 (kill-buffer buf-local
)
603 (kill-buffer buf-global
))))
604 (expect " *anything candidates:FOO*aTestBuffer"
605 (let* (anything-candidate-buffer-alist
606 (anything-source-name "FOO")
607 (anything-current-buffer (get-buffer-create "aTestBuffer"))
608 (buf-global (anything-candidate-buffer 'global
))
609 (buf-local (anything-candidate-buffer 'local
)))
610 (prog1 (buffer-name (anything-candidate-buffer))
611 (kill-buffer buf-local
)
612 (kill-buffer buf-global
))))
614 (let* (anything-candidate-buffer-alist
615 (anything-source-name "NOP__"))
616 (anything-candidate-buffer)))
617 (desc "anything-candidate-buffer register-buffer")
618 (expect " *anything test candidates*"
619 (let (anything-candidate-buffer-alist
620 (buf (get-buffer-create " *anything test candidates*")))
621 (with-current-buffer buf
623 (prog1 (buffer-name (anything-candidate-buffer buf
))
624 (kill-buffer (current-buffer))))))
625 (expect " *anything test candidates*"
626 (let (anything-candidate-buffer-alist
627 (buf (get-buffer-create " *anything test candidates*")))
628 (with-current-buffer buf
630 (anything-candidate-buffer buf
)
631 (prog1 (buffer-name (anything-candidate-buffer))
632 (kill-buffer (current-buffer))))))
634 (let (anything-candidate-buffer-alist
635 (buf (get-buffer-create " *anything test candidates*")))
636 (with-current-buffer buf
638 (anything-candidate-buffer buf
)
639 (prog1 (buffer-string)
640 (kill-buffer (current-buffer))))))
642 (let (anything-candidate-buffer-alist
643 (anything-source-name "foo")
644 (buf1 (get-buffer-create "buf1"))
645 (buf2 (get-buffer-create "buf2")))
646 (anything-candidate-buffer buf1
)
647 (anything-candidate-buffer buf2
)
648 (prog1 (buffer-name (anything-candidate-buffer buf1
))
650 (kill-buffer buf2
))))
651 (desc "action attribute")
653 (anything-test-candidates
656 (action ("identity" . identity
)))))
657 (anything-execute-selection-action))
659 (anything-test-candidates
662 (action ("identity" .
(lambda (c) (identity c
)))))))
663 (anything-execute-selection-action))
664 (desc "anything-get-default-action")
666 (anything-get-default-action '(("upcase" . upcase
))))
668 (anything-get-default-action '(("downcase" . downcase
))))
669 (expect (lambda (x) (capitalize x
))
670 (anything-get-default-action (lambda (x) (capitalize x
))))
672 (anything-get-default-action 'identity
))
673 (desc "anything-execute-selection-action")
675 (anything-execute-selection-action
676 "foo" '(("upcase" . upcase
)) nil
))
678 (anything-execute-selection-action
679 "foo" '(("upcase" .
(lambda (c) (upcase c
)))) nil
))
681 (desc "display-to-real attribute")
683 (anything-test-candidates
686 (display-to-real . upcase
)
687 (action ("identity" . identity
)))))
688 (anything-execute-selection-action))
689 (desc "cleanup test")
692 (anything-test-candidates
694 (cleanup .
(lambda () (setq v
'cleaned
))))))
696 (desc "anything-get-current-source")
697 ;; in init/candidates/action/candidate-transformer/filtered-candidate-transformer
698 ;; display-to-real/cleanup function
702 (anything-funcall-with-source '((name .
"FOO")) 'anything-get-current-source
)))
706 (anything-test-candidates
708 (init .
(lambda () (setq v
(anything-get-current-source)))))))
709 (assoc-default 'name v
)))
713 (anything-test-candidates
715 (candidates .
(lambda () (setq v
(anything-get-current-source)) '("a"))))))
716 (assoc-default 'name v
)))
720 (anything-test-candidates
724 .
(lambda (c) (setq v
(anything-get-current-source)) c
)))))
725 (anything-execute-selection-action)
726 (assoc-default 'name v
)))
727 ;; candidate-transformer
730 (anything-test-candidates
733 (candidate-transformer
734 .
(lambda (c) (setq v
(anything-get-current-source)) c
)))))
735 (assoc-default 'name v
)))
736 ;; filtered-candidate-transformer
739 (anything-test-candidates
742 (filtered-candidate-transformer
743 .
(lambda (c s
) (setq v
(anything-get-current-source)) c
)))))
744 (assoc-default 'name v
)))
745 ;; action-transformer
748 (anything-test-candidates
752 .
(lambda (a c
) (setq v
(anything-get-current-source)) a
))
753 (action . identity
))))
754 (anything-execute-selection-action)
755 (assoc-default 'name v
)))
759 (anything-test-candidates
761 (init .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
763 (candidates-in-buffer)
765 .
(lambda (c) (setq v
(anything-get-current-source)) c
))
766 (action . identity
))))
767 (anything-execute-selection-action)
768 (assoc-default 'name v
)))
772 (anything-test-candidates
776 .
(lambda () (setq v
(anything-get-current-source)))))))
777 (assoc-default 'name v
)))
778 ;; candidates are displayed
780 (anything-test-candidates
783 (action ("identity" . identity
)))))
784 (assoc-default 'name
(anything-get-current-source)))
785 (desc "anything-attr")
787 (anything-funcall-with-source
790 (anything-attr 'name
))))
793 (anything-test-candidates
796 (init .
(lambda () (setq v
(anything-attr 'hoge
))))
801 (anything-test-candidates
803 (init .
(lambda () (setq v
(anything-attr 'hoge
))))
808 (anything-test-candidates
810 (hoge) ;INCOMPATIBLE!
811 (init .
(lambda () (setq v
(anything-attr 'hoge
))))
814 (desc "anything-attr*")
816 (let (v (value1 "generic"))
817 (anything-test-candidates
820 (init .
(lambda () (setq v
(anything-attr* 'hoge
)))))))
822 (desc "anything-attr-defined")
825 (anything-test-candidates
828 (init .
(lambda () (setq v
(anything-attr-defined 'hoge
))))
833 (anything-test-candidates
835 (init .
(lambda () (setq v
(anything-attr-defined 'hoge
))))
838 (desc "anything-attrset")
839 (expect '((name .
"FOO") (hoge .
77))
840 (let ((src '((name .
"FOO") (hoge))))
841 (anything-attrset 'hoge
77 src
)
844 (anything-attrset 'hoge
77 '((name .
"FOO") (hoge))))
846 (expect '((name .
"FOO") (hoge .
77))
847 (let ((src '((name .
"FOO") (hoge .
1))))
848 (anything-attrset 'hoge
77 src
)
851 (expect '((name .
"FOO") (hoge .
77) (x))
852 (let ((src '((name .
"FOO") (x))))
853 (anything-attrset 'hoge
77 src
)
856 (anything-attrset 'hoge
77 '((name .
"FOO"))))
857 (desc "anything-preselect")
860 (with-current-buffer (anything-create-anything-buffer t
)
861 (let ((anything-pattern "")
862 (anything-test-mode t
))
863 (anything-process-source '((name .
"test")
864 (candidates "hoge" "foo" "bar")))
865 (anything-preselect "foo")
866 (anything-get-selection))))
869 (with-current-buffer (anything-create-anything-buffer t
)
870 (let ((anything-pattern "")
871 (anything-test-mode t
))
872 (anything-process-source '((name .
"test")
873 (candidates "hoge" "foo" "bar")))
874 (anything-preselect "fo+")
875 (anything-get-selection))))
876 ;; no match -> first entry
878 (with-current-buffer (anything-create-anything-buffer t
)
879 (let ((anything-pattern "")
880 (anything-test-mode t
))
881 (anything-process-source '((name .
"test")
882 (candidates "hoge" "foo" "bar")))
883 (anything-preselect "not found")
884 (anything-get-selection))))
885 (desc "anything-check-new-input")
887 (stub anything-update
)
888 (stub anything-action-window
)
889 (let ((anything-pattern "pattern"))
890 (anything-check-new-input "newpattern")
892 ;; anything-input == nil when action window is available
894 (stub anything-update
)
895 (stub anything-action-window
=> t
)
896 (let ((anything-pattern "pattern")
898 (anything-check-new-input "newpattern")
900 ;; anything-input == anything-pattern unless action window is available
902 (stub anything-update
)
903 (stub anything-action-window
=> nil
)
904 (let ((anything-pattern "pattern")
906 (anything-check-new-input "newpattern")
908 (expect (mock (anything-update))
909 (stub anything-action-window
)
910 (let (anything-pattern)
911 (anything-check-new-input "foo")))
912 (desc "anything-update")
913 (expect (mock (anything-process-source '((name .
"1"))))
914 (anything-test-update '(((name .
"1"))) ""))
915 ;; (find-function 'anything-update)
916 ;; TODO el-mock.el should express 2nd call of function.
917 ;; (expect (mock (anything-process-source '((name . "2"))))
918 ;; (stub anything-get-sources => '(((name . "1")) ((name . "2"))))
919 ;; (stub anything-log-run-hook)
920 ;; (stub anything-maybe-fit-frame)
921 ;; (stub run-with-idle-timer)
922 ;; (anything-update))
923 (expect (mock (run-with-idle-timer * nil
'anything-process-delayed-sources
924 '(((name .
"2") (delayed)))))
925 (stub anything-get-sources
=> '(((name .
"1"))
926 ((name .
"2") (delayed))))
927 (stub anything-log-run-hook
)
928 (stub anything-maybe-fit-frame
)
929 (let ((anything-pattern "") anything-test-mode
)
932 (desc "requires-pattern attribute")
933 (expect (not-called anything-process-source
)
934 (anything-test-update '(((name .
"1") (requires-pattern))) ""))
935 (expect (not-called anything-process-source
)
936 (anything-test-update '(((name .
"1") (requires-pattern .
3))) "xx"))
938 (desc "anything-normalize-sources")
939 (expect '(anything-c-source-test)
940 (anything-normalize-sources 'anything-c-source-test
))
941 (expect '(anything-c-source-test)
942 (anything-normalize-sources '(anything-c-source-test)))
943 (expect '(anything-c-source-test)
944 (let ((anything-sources '(anything-c-source-test)))
945 (anything-normalize-sources nil
)))
946 (expect '(((name .
"test")))
947 (anything-normalize-sources '((name .
"test"))))
948 (expect '(((name .
"test")))
949 (anything-normalize-sources '(((name .
"test")))))
950 (desc "anything-get-action")
951 (expect '(("identity" . identity
))
952 (stub buffer-size
=> 1)
953 (stub anything-get-current-source
=> '((name .
"test")
954 (action ("identity" . identity
))))
955 (anything-get-action))
957 (stub buffer-size
=> 1)
958 (stub anything-get-current-source
=> '((name .
"test")
959 (action . identity
)))
960 (anything-get-action))
961 (expect '((("identity" . identity
)) "action-transformer is called")
962 (stub buffer-size
=> 1)
963 (stub anything-get-current-source
965 (action ("identity" . identity
))
967 .
(lambda (actions selection
)
968 (list actions selection
)))))
969 (stub anything-get-selection
=> "action-transformer is called")
970 (anything-get-action))
971 (desc "anything-select-nth-action")
972 (expect (error error
*)
973 (stub anything-get-selection
=> nil
)
974 (anything-select-nth-action 0))
975 (desc "anything-get-nth-action")
977 (anything-get-nth-action 2 '(("0" . car
) ("1" . cdr
) ("2" . cadr
))))
978 (expect (error error
*)
979 (anything-get-nth-action 2 '(("0" . car
))))
981 (anything-get-nth-action 0 'identity
))
982 (expect (error error
*)
983 (anything-get-nth-action 1 'identity
))
984 (expect (error error
*)
985 (anything-get-nth-action 0 'unbound-function-xxx
))
986 (expect (error error
*)
987 (anything-get-nth-action 0 "invalid data"))
988 (desc "anything-funcall-foreach")
989 (expect (mock (upcase "foo"))
990 (stub anything-get-sources
=> '(((init .
(lambda () (upcase "foo"))))))
991 (anything-funcall-foreach 'init
))
992 (expect (mock (downcase "bar"))
993 (stub anything-get-sources
=> '(((init .
(lambda () (upcase "foo"))))
994 ((init .
(lambda () (downcase "bar"))))))
995 (anything-funcall-foreach 'init
))
996 (expect (not-called anything-funcall-with-source
)
997 (stub anything-get-sources
=> '(((init .
(lambda () (upcase "foo"))))))
998 (anything-funcall-foreach 'not-found
))
999 ;; TODO anything-select-with-digit-shortcut test
1000 (desc "anything-get-cached-candidates")
1001 (expect '("cached" "version")
1002 (let ((anything-candidate-cache '(("test" "cached" "version"))))
1003 (anything-get-cached-candidates '((name .
"test")
1004 (candidates "new")))))
1006 (let ((anything-candidate-cache '(("other" "cached" "version"))))
1007 (anything-get-cached-candidates '((name .
"test")
1008 (candidates "new")))))
1009 (expect '(("test" "new")
1010 ("other" "cached" "version"))
1011 (let ((anything-candidate-cache '(("other" "cached" "version"))))
1012 (anything-get-cached-candidates '((name .
"test")
1013 (candidates "new")))
1014 anything-candidate-cache
))
1015 (expect '(("other" "cached" "version"))
1016 (let ((anything-candidate-cache '(("other" "cached" "version"))))
1017 (anything-get-cached-candidates '((name .
"test")
1020 anything-candidate-cache
))
1021 ;; TODO when candidates == process
1022 ;; TODO anything-output-filter
1023 (desc "candidate-number-limit attribute")
1025 (let ((anything-pattern "")
1026 (anything-candidate-number-limit 20))
1027 (anything-compute-matches '((name .
"FOO") (candidates "a" "b" "c")
1028 (candidate-number-limit .
2) (volatile)))))
1030 (let ((anything-pattern "[abc]")
1031 (anything-candidate-number-limit 20))
1032 (anything-compute-matches '((name .
"FOO") (candidates "a" "b" "c")
1033 (candidate-number-limit .
2) (volatile)))))
1034 (expect '("a" "b" "c" "d")
1035 (let ((anything-pattern "[abcd]")
1036 (anything-candidate-number-limit 2))
1037 (anything-compute-matches '((name .
"FOO") (candidates "a" "b" "c" "d")
1038 (candidate-number-limit) (volatile)))))
1039 (expect '(("TEST" ("a" "b" "c")))
1040 (let ((anything-candidate-number-limit 2))
1041 (anything-test-candidates
1044 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
1045 (insert "a\nb\nc\nd\n"))))
1046 (candidates . anything-candidates-in-buffer
)
1048 (candidate-number-limit .
3)
1050 (expect '(("TEST" ("a" "b" "c")))
1051 (let ((anything-candidate-number-limit 2))
1052 (anything-test-candidates
1055 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
1056 (insert "a\nb\nc\nd\n"))))
1057 (candidates . anything-candidates-in-buffer
)
1059 (candidate-number-limit .
3)
1062 (desc "multiple init")
1065 (anything-test-candidates
1067 (init (lambda () (setq a
1))
1068 (lambda () (setq b
2))))))
1072 (anything-test-candidates
1074 (init (lambda () (setq a
1))))))
1076 (desc "multiple cleanup")
1079 (anything-test-candidates
1081 (cleanup (lambda () (setq a
1))
1082 (lambda () (setq b
2))))))
1084 (desc "anything-mklist")
1086 (anything-mklist 1))
1088 (anything-mklist '(2)))
1089 (expect '((lambda ()))
1090 (anything-mklist (lambda ())))
1091 (desc "anything-before-initialize-hook")
1093 (let ((anything-before-initialize-hook '((lambda () (setq v
'called
))))
1095 (anything-initial-setup)
1097 (desc "anything-after-initialize-hook")
1099 (let ((anything-before-initialize-hook
1100 '((lambda () (setq v
'(a)))))
1101 (anything-after-initialize-hook
1102 '((lambda () (setq v
(cons 'b v
)))))
1104 (anything-initial-setup)
1107 (let ((anything-after-initialize-hook
1108 '((lambda () (setq v
(buffer-size (get-buffer anything-buffer
))))))
1110 (anything-initial-setup)
1112 (desc "get-line attribute")
1113 (expect '(("TEST" ("FOO+")))
1114 (anything-test-candidates
1117 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
1118 (insert "foo+\nbar+\nbaz+\n"))))
1119 (candidates-in-buffer)
1120 (get-line .
(lambda (s e
) (upcase (buffer-substring-no-properties s e
))))))
1122 (desc "with-anything-restore-variables")
1125 (anything-restored-variables '(a b
)))
1126 (with-anything-restore-variables
1129 (desc "anything-cleanup-hook")
1131 (let ((anything-cleanup-hook
1132 '((lambda () (setq v
'called
))))
1136 (desc "with-anything-display-same-window")
1138 (save-window-excursion
1139 (delete-other-windows)
1142 (let ((buf (get-buffer-create " tmp"))
1143 (win (selected-window)))
1144 (with-anything-display-same-window
1145 (display-buffer buf
)
1146 (eq win
(get-buffer-window buf
))))))
1148 (save-window-excursion
1149 (delete-other-windows)
1152 (let ((buf (get-buffer-create " tmp"))
1153 (win (selected-window)))
1154 (with-anything-display-same-window
1156 (eq win
(get-buffer-window buf
))))))
1158 (save-window-excursion
1159 (delete-other-windows)
1162 (let ((buf (get-buffer-create " tmp"))
1163 (win (selected-window)))
1164 (with-anything-display-same-window
1165 (switch-to-buffer buf
)
1166 (eq win
(get-buffer-window buf
))))))
1168 (save-window-excursion
1169 (delete-other-windows)
1170 (let ((buf (get-buffer-create " tmp"))
1171 (win (selected-window)))
1172 (with-anything-display-same-window
1173 (display-buffer buf
)
1174 (eq win
(get-buffer-window buf
))))))
1176 (save-window-excursion
1177 (delete-other-windows)
1178 (let ((buf (get-buffer-create " tmp"))
1179 (win (selected-window)))
1180 (with-anything-display-same-window
1182 (eq win
(get-buffer-window buf
))))))
1183 (desc "search-from-end attribute")
1184 (expect '(("TEST" ("baz+" "bar+" "foo+")))
1185 (anything-test-candidates
1188 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
1189 (insert "foo+\nbar+\nbaz+\n"))))
1190 (candidates-in-buffer)
1191 (search-from-end)))))
1192 (expect '(("TEST" ("baz+" "bar+" "foo+")))
1193 (anything-test-candidates
1196 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
1197 (insert "foo+\nbar+\nbaz+\n"))))
1198 (candidates-in-buffer)
1201 (expect '(("TEST" ("baz+" "bar+")))
1202 (anything-test-candidates
1205 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
1206 (insert "foo+\nbar+\nbaz+\n"))))
1207 (candidates-in-buffer)
1209 (candidate-number-limit .
2)))))
1210 (expect '(("TEST" ("baz+" "bar+")))
1211 (anything-test-candidates
1214 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
1215 (insert "foo+\nbar+\nbaz+\n"))))
1216 (candidates-in-buffer)
1218 (candidate-number-limit .
2)))
1220 (expect '(("a" ("c2" "c1")))
1221 (anything-test-candidates
1224 (with-current-buffer (anything-candidate-buffer 'global
)
1225 (insert "c1\nc2\n"))))
1227 (candidates-in-buffer)))))
1228 ;; BUG remain empty string, but the pattern is rare case.
1229 (expect '(("a" ("c" "b" "a" "")))
1230 (anything-test-candidates
1233 (with-current-buffer (anything-candidate-buffer 'global
)
1234 (insert "a\nb\nc\n"))))
1236 (candidates-in-buffer)))
1238 (desc "header-name attribute")
1239 (expect "original is transformed"
1240 (anything-test-update '(((name .
"original")
1244 (format "%s is transformed" name
)))))
1246 (with-current-buffer (anything-buffer-get)
1248 (overlay-get (car (overlays-at (1+(point-min)))) 'display
)))
1249 (desc "volatile and match attribute")
1250 ;; candidates function is called once per `anything-process-delayed-sources'
1253 (anything-test-candidates '(((name .
"test")
1254 (candidates .
(lambda () (incf v
) '("ok")))
1256 (match identity identity identity
)))
1259 (desc "accept-empty attribute")
1261 (anything-test-candidates
1262 '(((name .
"test") (candidates "") (action . identity
))))
1263 (anything-execute-selection-action))
1265 (anything-test-candidates
1266 '(((name .
"test") (candidates "") (action . identity
) (accept-empty))))
1267 (anything-execute-selection-action))
1268 (desc "anything-tick-hash")
1270 (with-current-buffer (get-buffer-create " *00create+*")
1271 (puthash " *00create+*/xxx" 1 anything-tick-hash
)
1272 (kill-buffer (current-buffer)))
1273 (gethash " *00create+*/xxx" anything-tick-hash
))
1274 (desc "anything-execute-action-at-once-if-once")
1276 (let ((anything-execute-action-at-once-if-one t
))
1277 (anything '(((name .
"one test1")
1279 (action . upcase
))))))
1281 (let ((anything-execute-action-at-once-if-one t
))
1282 (anything '(((name .
"one test2")
1283 (candidates "hoge" "any")
1287 (expect (mock (read-string "word: " nil
))
1288 (let ((anything-execute-action-at-once-if-one t
))
1289 (anything '(((name .
"one test3")
1290 (candidates "hoge" "foo" "bar")
1291 (action . identity
)))
1293 (desc "anything-quit-if-no-candidate")
1295 (let ((anything-quit-if-no-candidate t
))
1296 (anything '(((name .
"zero test1") (candidates) (action . upcase
))))))
1298 (let (v (anything-quit-if-no-candidate (lambda () (setq v
'called
))))
1299 (anything '(((name .
"zero test2") (candidates) (action . upcase
))))
1301 (desc "real-to-display attribute")
1302 (expect '(("test" (("DDD" .
"ddd"))))
1303 (anything-test-candidates '(((name .
"test")
1305 (real-to-display . upcase
)
1306 (action . identity
)))))
1307 (expect '(("test" (("DDD" .
"ddd"))))
1308 (anything-test-candidates '(((name .
"test")
1309 (candidates ("ignored" .
"ddd"))
1310 (real-to-display . upcase
)
1311 (action . identity
)))))
1312 (expect '(("Commands" (("xxxhoge" .
"hoge") ("xxxboke" .
"boke"))))
1313 (anything-test-candidates '(((name .
"Commands")
1316 (real-to-display .
(lambda (x) (concat "xxx" x
)))
1317 (action . identity
)))
1319 (expect "test\nDDD\n"
1320 (anything-test-update '(((name .
"test")
1322 (real-to-display . upcase
)
1323 (action . identity
)))
1325 (with-current-buffer (anything-buffer-get) (buffer-string)))
1326 (desc "real-to-display and candidate-transformer attribute")
1327 (expect '(("test" (("DDD" .
"ddd"))))
1328 (anything-test-candidates
1331 (candidate-transformer (lambda (cands) (mapcar (lambda (c) (cons "X" c
)) cands
)))
1332 (real-to-display . upcase
)
1333 (action . identity
)))))
1334 (expect "test\nDDD\n"
1335 (anything-test-update
1338 (candidate-transformer (lambda (cands) (mapcar (lambda (c) (cons "X" c
)) cands
)))
1339 (real-to-display . upcase
)
1340 (action . identity
)))
1342 (with-current-buffer (anything-buffer-get) (buffer-string)))
1343 (desc "real-to-display and candidates-in-buffer")
1344 (expect '(("test" (("A" .
"a") ("B" .
"b"))))
1345 (anything-test-candidates
1348 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
1350 (insert "a\nb\n"))))
1351 (candidates-in-buffer)
1352 (real-to-display . upcase
)
1353 (action . identity
)))))
1354 (expect "test\nA\nB\n"
1359 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
1361 (insert "a\nb\n"))))
1362 (candidates-in-buffer)
1363 (real-to-display . upcase
)
1364 (action . identity
))))
1365 (with-current-buffer (anything-buffer-get) (buffer-string)))
1366 (desc "Symbols are acceptable as candidate.")
1367 (expect '(("test" (sym "str")))
1368 (anything-test-candidates
1370 (candidates sym
"str")))))
1371 (expect '(("test" ((sym . realsym
) ("str" .
"realstr"))))
1372 (anything-test-candidates
1374 (candidates (sym . realsym
) ("str" .
"realstr"))))))
1375 (expect '(("test" (sym)))
1376 (anything-test-candidates
1378 (candidates sym
"str")))
1380 (expect '(("test" ("str")))
1381 (anything-test-candidates
1383 (candidates sym
"str")))
1385 (expect '(("test" ((sym . realsym
))))
1386 (anything-test-candidates
1388 (candidates (sym . realsym
) ("str" .
"realstr"))))
1390 (expect '(("test" (("str" .
"realstr"))))
1391 (anything-test-candidates
1393 (candidates (sym . realsym
) ("str" .
"realstr"))))
1395 (desc "multiple transformers")
1396 (expect '(("test" ("<FOO>")))
1397 (anything-test-candidates
1400 (candidate-transformer
1402 (anything-compose (list cands
)
1403 (list (lambda (c) (mapcar 'upcase c
))
1404 (lambda (c) (list (concat "<" (car c
) ">")))))))))))
1406 (anything-composed-funcall-with-source
1408 (list (lambda (c) (mapcar 'upcase c
))
1409 (lambda (c) (list (concat "<" (car c
) ">"))))
1412 (expect '(("test" ("<FOO>")))
1413 (anything-test-candidates
1416 (candidate-transformer
1417 (lambda (c) (mapcar 'upcase c
))
1418 (lambda (c) (list (concat "<" (car c
) ">"))))))))
1419 (expect '(("test" ("<BAR>")))
1420 (anything-test-candidates
1423 (filtered-candidate-transformer
1424 (lambda (c s
) (mapcar 'upcase c
))
1425 (lambda (c s
) (list (concat "<" (car c
) ">"))))))))
1426 (expect '(("find-file" . find-file
)
1427 ("view-file" . view-file
))
1429 (stub anything-get-current-source
1430 => '((name .
"test")
1436 (list (lambda (a s
) (push '("view-file" . view-file
) a
))
1437 (lambda (a s
) (push '("find-file" . find-file
) a
))))))))
1438 (anything-get-action))
1439 (expect '(("find-file" . find-file
)
1440 ("view-file" . view-file
))
1442 (stub anything-get-current-source
1443 => '((name .
"test")
1446 (lambda (a s
) (push '("view-file" . view-file
) a
))
1447 (lambda (a s
) (push '("find-file" . find-file
) a
)))))
1448 (anything-get-action))
1449 (desc "define-anything-type-attribute")
1450 (expect '((file (action . find-file
)))
1451 (let (anything-type-attributes)
1452 (define-anything-type-attribute 'file
'((action . find-file
)))
1453 anything-type-attributes
))
1454 (expect '((file (action . find-file
)))
1455 (let ((anything-type-attributes '((file (action . view-file
)))))
1456 (define-anything-type-attribute 'file
'((action . find-file
)))
1457 anything-type-attributes
))
1458 (expect '((file (action . find-file
))
1459 (buffer (action . switch-to-buffer
)))
1460 (let (anything-type-attributes)
1461 (define-anything-type-attribute 'buffer
'((action . switch-to-buffer
)))
1462 (define-anything-type-attribute 'file
'((action . find-file
)))
1463 anything-type-attributes
))
1464 (desc "anything-approximate-candidate-number")
1467 (let ((anything-buffer (current-buffer)))
1468 (anything-approximate-candidate-number))))
1471 (let ((anything-buffer (current-buffer)))
1474 (anything-approximate-candidate-number))))
1477 (let ((anything-buffer (current-buffer)))
1481 (<= 2 (anything-approximate-candidate-number)))))
1484 (let ((anything-buffer (current-buffer)))
1486 (propertize "multi\nline\n" 'anything-multiline t
))
1487 (anything-approximate-candidate-number))))
1490 (let ((anything-buffer (current-buffer))
1491 (anything-candidate-separator "-----"))
1493 (propertize "multi\nline1\n" 'anything-multiline t
)
1495 (propertize "multi\nline2\n" 'anything-multiline t
))
1496 (<= 2 (anything-approximate-candidate-number)))))
1497 (desc "delayed-init attribute")
1500 (anything-test-candidates '(((name .
"test")
1501 (delayed-init .
(lambda () (incf value
)))
1503 (requires-pattern .
2)))
1508 (anything-test-candidates '(((name .
"test")
1509 (delayed-init .
(lambda () (incf value
)))
1511 (requires-pattern .
2)))
1516 (anything-test-candidates '(((name .
"test")
1517 (delayed-init (lambda () (incf value
))
1518 (lambda () (incf value
)))
1520 (requires-pattern .
2)))
1526 (anything-test-candidates '(((name .
"test")
1528 .
(lambda () (setq value
1529 (eq anything-current-buffer
(current-buffer)))))
1531 (requires-pattern .
2)))
1534 (desc "pattern-transformer attribute")
1535 (expect '(("test2" ("foo")) ("test3" ("bar")))
1536 (anything-test-candidates '(((name .
"test1")
1537 (candidates "foo" "bar"))
1539 (pattern-transformer .
(lambda (pat) (substring pat
1)))
1540 (candidates "foo" "bar"))
1542 (pattern-transformer .
(lambda (pat) "bar"))
1543 (candidates "foo" "bar")))
1545 (expect '(("test2" ("foo")) ("test3" ("bar")))
1546 (anything-test-candidates '(((name .
"test1")
1547 (candidates "foo" "bar"))
1549 (pattern-transformer (lambda (pat) (substring pat
1)))
1550 (candidates "foo" "bar"))
1552 (pattern-transformer (lambda (pat) "bar"))
1553 (candidates "foo" "bar")))
1555 (expect '(("test2" ("foo")) ("test3" ("bar")))
1556 (anything-test-candidates '(((name .
"test1")
1558 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
1559 (insert "foo\nbar\n"))))
1560 (candidates-in-buffer))
1562 (pattern-transformer .
(lambda (pat) (substring pat
1)))
1564 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
1565 (insert "foo\nbar\n"))))
1566 (candidates-in-buffer))
1568 (pattern-transformer .
(lambda (pat) "bar"))
1570 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
1571 (insert "foo\nbar\n"))))
1572 (candidates-in-buffer)))
1574 (desc "anything-recent-push")
1575 (expect '("foo" "bar" "baz")
1576 (let ((lst '("bar" "baz")))
1577 (anything-recent-push "foo" 'lst
)))
1578 (expect '("foo" "bar" "baz")
1579 (let ((lst '("foo" "bar" "baz")))
1580 (anything-recent-push "foo" 'lst
)))
1581 (expect '("foo" "bar" "baz")
1582 (let ((lst '("bar" "foo" "baz")))
1583 (anything-recent-push "foo" 'lst
)))
1584 (desc "anything-require-at-least-version")
1586 (anything-require-at-least-version "1.1"))
1588 (anything-require-at-least-version "1.200"))
1590 (anything-require-at-least-version
1591 (and (string-match "1\.\\([0-9]+\\)" anything-version
)
1592 (match-string 0 anything-version
))))
1594 (anything-require-at-least-version "1.999"))
1596 (anything-require-at-least-version "1.2000"))
1597 (desc "anything-once")
1600 (anything-test-candidates
1602 (init .
(lambda () (incf i
))))
1604 (init .
(lambda () (incf i
))))))
1608 (anything-test-candidates
1610 (init .
(lambda () (anything-once (lambda () (incf i
))))))
1612 (init .
(lambda () (anything-once (lambda () (incf i
))))))))
1616 (flet ((init1 () (anything-once (lambda () (incf i
)))))
1617 (anything-test-candidates
1623 (desc "anything-marked-candidates")
1624 (expect '("mark3" "mark1")
1625 (let* ((source '((name .
"mark test")))
1626 (anything-marked-candidates
1627 `((,source .
"mark1")
1628 (((name .
"other")) .
"mark2")
1629 (,source .
"mark3"))))
1630 (stub anything-buffer-get
=> (current-buffer))
1631 (stub anything-get-current-source
=> source
)
1632 (anything-marked-candidates)))
1633 (expect '("current")
1634 (let* ((source '((name .
"mark test")))
1635 (anything-marked-candidates nil
))
1636 (stub anything-get-current-source
=> source
)
1637 (stub anything-get-selection
=> "current")
1638 (anything-marked-candidates)))
1639 (desc "anything-marked-candidates with coerce")
1640 (expect '(mark3 mark1
)
1641 (let* ((source '((name .
"mark test")
1643 (anything-marked-candidates
1644 `((,source .
"mark1")
1645 (((name .
"other")) .
"mark2")
1646 (,source .
"mark3"))))
1647 (stub anything-buffer-get
=> (current-buffer))
1648 (stub anything-get-current-source
=> source
)
1649 (anything-marked-candidates)))
1650 (desc "anything-let")
1651 (expect '(1 10000 nil
)
1655 (anything-buffer (exps-tmpbuf)))
1656 (anything-let ((a 1)
1659 (anything-create-anything-buffer))
1660 (with-current-buffer anything-buffer
1666 (anything-buffer (exps-tmpbuf)))
1667 (anything-let ((a 1)
1670 (anything-create-anything-buffer))
1671 (with-current-buffer anything-buffer
1672 (and (assq 'a
(buffer-local-variables))
1673 (assq 'b
(buffer-local-variables))
1674 (assq 'c
(buffer-local-variables))))))
1679 (anything-buffer (exps-tmpbuf)))
1680 (anything-let ((a 1)
1684 (desc "anything-let*")
1689 (anything-buffer (exps-tmpbuf)))
1690 (anything-let* ((a 1)
1693 (anything-create-anything-buffer))
1694 (with-current-buffer anything-buffer
1700 (anything-buffer (exps-tmpbuf)))
1701 (anything-let* ((a 1)
1704 (anything-create-anything-buffer))
1705 (with-current-buffer anything-buffer
1706 (and (assq 'a
(buffer-local-variables))
1707 (assq 'b
(buffer-local-variables))
1708 (assq 'c
(buffer-local-variables))))))
1713 (anything-buffer (exps-tmpbuf)))
1714 (anything-let* ((a 1)
1718 (desc "anything with keyword")
1719 (expect (mock (anything-internal 'test-source
"input" "prompt: " nil
"preselect" "*test*" nil
))
1720 (anything :sources
'test-source
1724 :preselect
"preselect"
1727 (expect (mock (anything-internal 'test-source nil nil nil nil
"*test*" nil
))
1728 (anything :sources
'test-source
1730 :candidate-number-limit
20))
1731 (expect (mock (anything-internal 'test-source nil nil nil nil
"*test*" nil
))
1732 (anything 'test-source nil nil nil nil
"*test*" nil
))
1733 (desc "anything-log-eval-internal")
1734 (expect (mock (anything-log "%S = %S" '(+ 1 2) 3))
1735 (anything-log-eval-internal '((+ 1 2))))
1736 (expect (mock (anything-log "%S = ERROR!" 'unDeFined
))
1737 (anything-log-eval-internal '(unDeFined)))
1739 (desc "anything-output-filter--collect-candidates")
1740 (expect '("a" "b" "")
1741 (split-string "a\nb\n" "\n"))
1743 (anything-output-filter--collect-candidates
1744 '("a" "b" "") (cons 'incomplete-line
"")))
1746 (split-string "a\nb" "\n"))
1748 (anything-output-filter--collect-candidates
1749 '("a" "b") (cons 'incomplete-line
"")))
1750 (expect '(incomplete-line .
"b")
1751 (let ((incomplete-line-info (cons 'incomplete-line
"")))
1752 (anything-output-filter--collect-candidates
1753 '("a" "b") incomplete-line-info
)
1754 incomplete-line-info
))
1755 (expect '("" "c" "")
1756 (split-string "\nc\n" "\n"))
1759 (let ((incomplete-line-info (cons 'incomplete-line
"")))
1760 (anything-output-filter--collect-candidates
1761 '("a" "b") incomplete-line-info
)
1762 (anything-output-filter--collect-candidates
1763 '("" "c" "") incomplete-line-info
)))
1764 (desc "coerce attribute")
1766 (anything :sources
'(((name .
"test")
1767 (candidates "string")
1768 (action . identity
)))
1769 :execute-action-at-once-if-one t
))
1771 (anything :sources
'(((name .
"test")
1772 (candidates "symbol")
1774 (action . identity
)))
1775 :execute-action-at-once-if-one t
))
1777 (anything :sources
'(((name .
"test")
1778 (candidates ("display" .
"real"))
1780 (action . identity
)))
1781 :execute-action-at-once-if-one t
))
1783 (anything :sources
'(((name .
"test")
1785 (candidate-transformer
1786 (lambda (c) '(("display" .
"real"))))
1788 (action . identity
)))
1789 :execute-action-at-once-if-one t
))
1791 (anything :sources
'(((name .
"test")
1793 (filtered-candidate-transformer
1794 (lambda (c s
) '(("display" .
"real"))))
1796 (action . identity
)))
1797 :execute-action-at-once-if-one t
))
1799 (anything :sources
'(((name .
"test")
1800 (candidates "dummy")
1801 (display-to-real (lambda (disp) "real"))
1803 (action . identity
)))
1804 :execute-action-at-once-if-one t
))
1805 (desc "anything-next-point-in-list")
1807 (anything-next-point-in-list 5 '(10 20) nil
))
1809 (anything-next-point-in-list 15 '(10 20) nil
))
1811 (anything-next-point-in-list 25 '(10 20) nil
))
1813 (anything-next-point-in-list 5 '(10 20) t
))
1815 (anything-next-point-in-list 15 '(10 20) t
))
1817 (anything-next-point-in-list 25 '(10 20) t
))
1819 (anything-next-point-in-list 5 '() nil
))
1821 (anything-next-point-in-list 5 '() t
))
1823 (anything-next-point-in-list 5 '(10) nil
))
1825 (anything-next-point-in-list 15 '(10) t
))
1827 (anything-next-point-in-list 10 '(10 20) nil
))
1829 (anything-next-point-in-list 20 '(10 20) t
))
1831 (anything-next-point-in-list 30 '(10 20 30) t
))