1 ;;; ibuffer-tests.el --- Test suite. -*- lexical-binding: t -*-
3 ;; Copyright (C) 2015-2017 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software: you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 (defvar ibuffer-filter-groups
)
27 (defvar ibuffer-filtering-alist
)
28 (defvar ibuffer-filtering-qualifiers
)
29 (defvar ibuffer-save-with-custom
)
30 (defvar ibuffer-saved-filter-groups
)
31 (defvar ibuffer-saved-filters
)
32 (declare-function ibuffer-format-qualifier
"ibuf-ext" (qualifier))
33 (declare-function ibuffer-unary-operand
"ibuf-ext" (filter))
35 (ert-deftest ibuffer-autoload
()
36 "Tests to see whether ibuffer has been autoloaded"
37 (skip-unless (not (featurep 'ibuf-ext
)))
39 (fboundp 'ibuffer-mark-unsaved-buffers
))
43 'ibuffer-mark-unsaved-buffers
))))
45 (ert-deftest ibuffer-test-Bug24997
()
46 "Test for http://debbugs.gnu.org/24997 ."
48 (let ((orig ibuffer-filtering-qualifiers
))
51 (setq ibuffer-filtering-qualifiers
53 (used-mode . lisp-interaction-mode
)))
54 (ibuffer-update nil t
)
55 (ignore-errors (ibuffer-decompose-filter))
56 (should (cdr ibuffer-filtering-qualifiers
)))
57 (setq ibuffer-filtering-qualifiers orig
)
58 (ibuffer-update nil t
))))
60 (ert-deftest ibuffer-test-Bug25000
()
61 "Test for http://debbugs.gnu.org/25000 ."
62 (let ((case-fold-search t
)
63 (buf1 (generate-new-buffer "ibuffer-test-Bug25000-buf1"))
64 (buf2 (generate-new-buffer "ibuffer-test-Bug25000-buf2")))
68 (ibuffer-unmark-all-marks)
69 (ibuffer-mark-by-name-regexp (buffer-name buf1
))
70 (ibuffer-change-marks ibuffer-marked-char ?L
)
71 (ibuffer-mark-by-name-regexp (buffer-name buf2
))
72 (ibuffer-change-marks ibuffer-marked-char ?l
)
73 (should-not (cdr (ibuffer-buffer-names-with-mark ?l
))))
74 (mapc (lambda (buf) (when (buffer-live-p buf
)
75 (kill-buffer buf
))) (list buf1 buf2
)))))
77 (ert-deftest ibuffer-save-filters
()
78 "Tests that `ibuffer-save-filters' saves in the proper format."
79 (skip-unless (featurep 'ibuf-ext
))
80 (let ((ibuffer-save-with-custom nil
)
81 (ibuffer-saved-filters nil
)
82 (test1 '((mode . org-mode
)
84 (and (not (starred-name))
85 (directory .
"\<org\>")))))
86 (test2 '((or (mode . emacs-lisp-mode
) (file-extension .
"elc?")
87 (and (starred-name) (name .
"elisp"))
88 (mode . lisp-interaction-mode
))))
89 (test3 '((size-lt .
100) (derived-mode . prog-mode
)
90 (or (filename .
"scratch")
92 (filename .
"temp")))))
93 (ibuffer-save-filters "test1" test1
)
94 (should (equal (car ibuffer-saved-filters
) (cons "test1" test1
)))
95 (ibuffer-save-filters "test2" test2
)
96 (should (equal (car ibuffer-saved-filters
) (cons "test2" test2
)))
97 (should (equal (cadr ibuffer-saved-filters
) (cons "test1" test1
)))
98 (ibuffer-save-filters "test3" test3
)
99 (should (equal (car ibuffer-saved-filters
) (cons "test3" test3
)))
100 (should (equal (cadr ibuffer-saved-filters
) (cons "test2" test2
)))
101 (should (equal (car (cddr ibuffer-saved-filters
)) (cons "test1" test1
)))
102 (should (equal (cdr (assoc "test1" ibuffer-saved-filters
)) test1
))
103 (should (equal (cdr (assoc "test2" ibuffer-saved-filters
)) test2
))
104 (should (equal (cdr (assoc "test3" ibuffer-saved-filters
)) test3
))))
106 (ert-deftest ibuffer-test-Bug25058
()
107 "Test for http://debbugs.gnu.org/25058 ."
109 (let ((orig-filters ibuffer-saved-filter-groups
)
110 (tmp-filters '(("saved-filters"
112 (used-mode . shell-mode
))
115 (used-mode . emacs-lisp-mode
)
116 (used-mode . lisp-interaction-mode
)))
118 (used-mode . dired-mode
))
121 (used-mode . help-mode
)
122 (used-mode . debugger-mode
)
123 (used-mode . Custom-mode
)
124 (used-mode . completion-list-mode
)
125 (name .
"\\`[*]Messages[*]\\'")))))))
128 (setq ibuffer-saved-filter-groups tmp-filters
)
129 (ibuffer-switch-to-saved-filter-groups "saved-filters")
130 (ibuffer-decompose-filter-group "Elisp")
131 (ibuffer-filter-disable)
132 (ibuffer-switch-to-saved-filter-groups "saved-filters")
133 (should (assoc "Elisp" (cdar ibuffer-saved-filter-groups
))))
134 (setq ibuffer-saved-filter-groups orig-filters
)
135 (ibuffer-awhen (get-buffer "*Ibuffer*")
136 (and (buffer-live-p it
) (kill-buffer it
))))))
139 (ert-deftest ibuffer-test-Bug25042
()
140 "Test for http://debbugs.gnu.org/25042 ."
142 (let ((filters ibuffer-filtering-qualifiers
))
145 (ignore-errors ; Mistyped `match-string' instead of `string-match'.
146 (setq ibuffer-filtering-qualifiers nil
)
147 (ibuffer-filter-by-predicate '(match-string "foo" (buffer-name))))
148 (should-not ibuffer-filtering-qualifiers
))
149 (setq ibuffer-filtering-qualifiers filters
))))
151 ;; Test Filter Inclusion
152 (let* (test-buffer-list ; accumulated buffers to clean up
153 ;; Utility functions without polluting the environment
155 (lambda (buffer mode
)
156 "Set BUFFER's major mode to MODE, a mode function, or fundamental."
157 (with-current-buffer buffer
158 (funcall (or mode
#'fundamental-mode
)))))
160 (lambda (buffer size include-content
)
161 "Add exactly SIZE bytes to BUFFER, including INCLUDE-CONTENT."
162 (when (or size include-content
)
164 (chunk "ccccccccccccccccccccccccccccccc\n")
165 (chunk-size (length chunk
))
166 (size (if (and size include-content
(stringp include-content
))
167 (- size
(length include-content
))
169 (unless (or (null size
) (> size
0))
170 (error "size argument must be nil or positive"))
171 (with-current-buffer buffer
172 (when include-content
173 (insert include-content
))
175 (dotimes (_ (floor size chunk-size
))
177 (dotimes (_ (mod size chunk-size
))
179 ;; prevent query on cleanup
180 (set-buffer-modified-p nil
))))))
182 (lambda (prefix &rest args-plist
)
183 "Create a file and buffer with designated properties.
184 PREFIX is a string giving the beginning of the name, and ARGS-PLIST
185 is a series of keyword-value pairs, with allowed keywords
186 :suffix STRING, :size NUMBER, :mode MODE-FUNC, :include-content STRING.
187 Returns the created buffer."
188 (let* ((suffix (plist-get args-plist
:suffix
))
189 (size (plist-get args-plist
:size
))
190 (include (plist-get args-plist
:include-content
))
191 (mode (plist-get args-plist
:mode
))
192 (file (make-temp-file prefix nil suffix
))
193 (buf (find-file-noselect file t
)))
194 (push buf test-buffer-list
) ; record for cleanup
195 (funcall set-buffer-mode buf mode
)
196 (funcall set-buffer-contents buf size include
)
198 (create-non-file-buffer
199 (lambda (prefix &rest args-plist
)
200 "Create a non-file and buffer with designated properties.
201 PREFIX is a string giving the beginning of the name, and ARGS-PLIST
202 is a series of keyword-value pairs, with allowed keywords
203 :size NUMBER, :mode MODE-FUNC, :include-content STRING.
204 Returns the created buffer."
205 (let* ((size (plist-get args-plist
:size
))
206 (include (plist-get args-plist
:include-content
))
207 (mode (plist-get args-plist
:mode
))
208 (buf (generate-new-buffer prefix
)))
209 (push buf test-buffer-list
) ; record for cleanup
210 (funcall set-buffer-mode buf mode
)
211 (funcall set-buffer-contents buf size include
)
215 "Restore all emacs state modified during the tests"
216 (while test-buffer-list
; created temporary buffers
217 (let ((buf (pop test-buffer-list
)))
218 (with-current-buffer buf
(bury-buffer)) ; ensure not selected
219 (kill-buffer buf
))))))
221 (ert-deftest ibuffer-filter-inclusion-1
()
222 "Tests inclusion using basic filter combinators with a single buffer."
223 (skip-unless (featurep 'ibuf-ext
))
226 (funcall create-file-buffer
"ibuf-test-1" :size
100
227 :include-content
"One ring to rule them all\n")))
228 (should (ibuffer-included-in-filters-p buf
'((size-gt .
99))))
229 (should (ibuffer-included-in-filters-p buf
'((size-lt .
101))))
230 (should (ibuffer-included-in-filters-p
231 buf
'((mode . fundamental-mode
))))
232 (should (ibuffer-included-in-filters-p
233 buf
'((content .
"ring to rule them all"))))
234 (should (ibuffer-included-in-filters-p
235 buf
'((and (content .
"ring to rule them all")))))
236 (should (ibuffer-included-in-filters-p
237 buf
'((and (and (content .
"ring to rule them all"))))))
238 (should (ibuffer-included-in-filters-p
239 buf
'((and (and (and (content .
"ring to rule them all")))))))
240 (should (ibuffer-included-in-filters-p
241 buf
'((or (content .
"ring to rule them all")))))
242 (should (ibuffer-included-in-filters-p
243 buf
'((not (not (content .
"ring to rule them all"))))))
244 (should (ibuffer-included-in-filters-p
245 buf
'((and (size-gt .
99)
246 (content .
"ring to rule them all")
247 (mode . fundamental-mode
)
248 (basename .
"\\`ibuf-test-1")))))
249 (should (ibuffer-included-in-filters-p
250 buf
'((not (or (not (size-gt .
99))
251 (not (content .
"ring to rule them all"))
252 (not (mode . fundamental-mode
))
253 (not (basename .
"\\`ibuf-test-1")))))))
254 (should (ibuffer-included-in-filters-p
255 buf
'((and (or (size-gt .
99) (size-lt .
10))
256 (and (content .
"ring.*all")
258 (content .
"them all")
260 (not (mode . text-mode
))
261 (basename .
"\\`ibuf-test-1"))))))
264 (ert-deftest ibuffer-filter-inclusion-2
()
265 "Tests inclusion of basic filters in combination on a single buffer."
266 (skip-unless (featurep 'ibuf-ext
))
269 (funcall create-file-buffer
"ibuf-test-2" :size
200
271 :include-content
"and in the darkness find them\n")))
272 (should (ibuffer-included-in-filters-p buf
'((size-gt .
199))))
273 (should (ibuffer-included-in-filters-p buf
'((size-lt .
201))))
274 (should (ibuffer-included-in-filters-p buf
'((not size-gt .
200))))
275 (should (ibuffer-included-in-filters-p buf
'((not (size-gt .
200)))))
276 (should (ibuffer-included-in-filters-p
277 buf
'((and (size-gt .
199) (size-lt .
201)))))
278 (should (ibuffer-included-in-filters-p
279 buf
'((or (size-gt .
199) (size-gt .
201)))))
280 (should (ibuffer-included-in-filters-p
281 buf
'((or (size-gt .
201) (size-gt .
199)))))
282 (should (ibuffer-included-in-filters-p
283 buf
'((size-gt .
199) (mode . text-mode
)
284 (content .
"darkness find them"))))
285 (should (ibuffer-included-in-filters-p
286 buf
'((and (size-gt .
199) (mode . text-mode
)
287 (content .
"darkness find them")))))
288 (should (ibuffer-included-in-filters-p
289 buf
'((not (or (not (size-gt .
199)) (not (mode . text-mode
))
290 (not (content .
"darkness find them")))))))
291 (should (ibuffer-included-in-filters-p
292 buf
'((or (size-gt .
200) (content .
"darkness find them")
293 (derived-mode . emacs-lisp-mode
)))))
294 (should-not (ibuffer-included-in-filters-p
295 buf
'((or (size-gt .
200) (content .
"rule them all")
296 (derived-mode . emacs-lisp-mode
))))))
299 (ert-deftest ibuffer-filter-inclusion-3
()
300 "Tests inclusion with filename filters on specified buffers."
301 (skip-unless (featurep 'ibuf-ext
))
304 (funcall create-file-buffer
"ibuf-test-3.a" :size
50
306 :include-content
"...but a multitude of drops?\n"))
308 (funcall create-non-file-buffer
"ibuf-test-3.b" :size
50
310 :include-content
"...but a multitude of drops?\n"))
311 (dirA (with-current-buffer bufA default-directory
))
312 (dirB (with-current-buffer bufB default-directory
)))
313 (should (ibuffer-included-in-filters-p
314 bufA
'((basename .
"ibuf-test-3"))))
315 (should (ibuffer-included-in-filters-p
316 bufA
'((basename .
"test-3\\.a"))))
317 (should (ibuffer-included-in-filters-p
318 bufA
'((file-extension .
"a"))))
319 (should (ibuffer-included-in-filters-p
320 bufA
(list (cons 'directory dirA
))))
321 (should-not (ibuffer-included-in-filters-p
322 bufB
'((basename .
"ibuf-test-3"))))
323 (should-not (ibuffer-included-in-filters-p
324 bufB
'((file-extension .
"b"))))
325 (should (ibuffer-included-in-filters-p
326 bufB
(list (cons 'directory dirB
))))
327 (should (ibuffer-included-in-filters-p
328 bufA
'((name .
"ibuf-test-3"))))
329 (should (ibuffer-included-in-filters-p
330 bufB
'((name .
"ibuf-test-3")))))
333 (ert-deftest ibuffer-filter-inclusion-4
()
334 "Tests inclusion with various filters on a single buffer."
335 (skip-unless (featurep 'ibuf-ext
))
338 (funcall create-file-buffer
"ibuf-test-4"
339 :mode
#'emacs-lisp-mode
:suffix
".el"
340 :include-content
"(message \"--%s--\" 'emacs-rocks)\n")))
341 (should (ibuffer-included-in-filters-p
342 buf
'((file-extension .
"el"))))
343 (should (ibuffer-included-in-filters-p
344 buf
'((derived-mode . prog-mode
))))
345 (should (ibuffer-included-in-filters-p
346 buf
'((used-mode . emacs-lisp-mode
))))
347 (should (ibuffer-included-in-filters-p
348 buf
'((mode . emacs-lisp-mode
))))
349 (with-current-buffer buf
(set-buffer-modified-p t
))
350 (should (ibuffer-included-in-filters-p buf
'((modified))))
351 (with-current-buffer buf
(set-buffer-modified-p nil
))
352 (should (ibuffer-included-in-filters-p buf
'((not modified
))))
353 (should (ibuffer-included-in-filters-p
354 buf
'((and (file-extension .
"el")
355 (derived-mode . prog-mode
)
357 (should (ibuffer-included-in-filters-p
358 buf
'((or (file-extension .
"tex")
359 (derived-mode . prog-mode
)
361 (should (ibuffer-included-in-filters-p
362 buf
'((file-extension .
"el")
363 (derived-mode . prog-mode
)
367 (ert-deftest ibuffer-filter-inclusion-5
()
368 "Tests inclusion with various filters on a single buffer."
369 (skip-unless (featurep 'ibuf-ext
))
372 (funcall create-non-file-buffer
"ibuf-test-5.el"
373 :mode
#'emacs-lisp-mode
375 "(message \"--%s--\" \"It really does!\")\n")))
376 (should-not (ibuffer-included-in-filters-p
377 buf
'((file-extension .
"el"))))
378 (should (ibuffer-included-in-filters-p
379 buf
'((size-gt .
18))))
380 (should (ibuffer-included-in-filters-p
381 buf
'((predicate .
(lambda ()
382 (> (- (point-max) (point-min)) 18))))))
383 (should (ibuffer-included-in-filters-p
384 buf
'((and (mode . emacs-lisp-mode
)
387 (and (not (size-gt .
100))
388 (content .
"[Ii]t *really does!")
389 (or (name .
"test-5")
390 (not (filename .
"test-5")))))))))
393 (ert-deftest ibuffer-filter-inclusion-6
()
394 "Tests inclusion using saved filters and DeMorgan's laws."
395 (skip-unless (featurep 'ibuf-ext
))
398 (funcall create-non-file-buffer
"*ibuf-test-6*" :size
65
401 (funcall create-file-buffer
"ibuf-test-6a" :suffix
".html"
404 "<HTML><BODY><H1>Hello, World!</H1></BODY></HTML>")))
405 (should (ibuffer-included-in-filters-p buf
'((starred-name))))
406 (should-not (ibuffer-included-in-filters-p
407 buf
'((saved .
"text document"))))
408 (should (ibuffer-included-in-filters-p buf2
'((saved .
"web"))))
409 (should (ibuffer-included-in-filters-p
410 buf2
'((not (and (not (derived-mode . sgml-mode
))
411 (not (derived-mode . css-mode
))
412 (not (mode . javascript-mode
))
413 (not (mode . js2-mode
))
414 (not (mode . scss-mode
))
415 (not (derived-mode . haml-mode
))
416 (not (mode . sass-mode
)))))))
417 (should (ibuffer-included-in-filters-p
418 buf
'((and (starred-name)
419 (or (size-gt .
50) (filename .
"foo"))))))
420 (should (ibuffer-included-in-filters-p
421 buf
'((not (or (not starred-name
)
423 (not (filename .
"foo")))))))))
426 (ert-deftest ibuffer-filter-inclusion-7
()
427 "Tests inclusion with various filters on a single buffer."
428 (skip-unless (featurep 'ibuf-ext
))
431 (funcall create-non-file-buffer
"ibuf-test-7"
432 :mode
#'artist-mode
)))
433 (should (ibuffer-included-in-filters-p
434 buf
'((not (starred-name)))))
435 (should (ibuffer-included-in-filters-p
436 buf
'((not starred-name
))))
437 (should (ibuffer-included-in-filters-p
438 buf
'((not (not (not starred-name
))))))
439 (should (ibuffer-included-in-filters-p
440 buf
'((not (modified)))))
441 (should (ibuffer-included-in-filters-p
442 buf
'((not modified
))))
443 (should (ibuffer-included-in-filters-p
444 buf
'((not (not (not modified
)))))))
447 (ert-deftest ibuffer-filter-inclusion-8
()
448 "Tests inclusion with various filters."
449 (skip-unless (featurep 'ibuf-ext
))
452 (funcall create-non-file-buffer
"ibuf-test-8a"
453 :mode
#'artist-mode
))
454 (bufB (funcall create-non-file-buffer
"*ibuf-test-8b*" :size
32))
455 (bufC (funcall create-file-buffer
"ibuf-test8c" :suffix
"*"
457 (bufD (funcall create-file-buffer
"*ibuf-test8d" :size
128))
458 (bufE (funcall create-file-buffer
"*ibuf-test8e" :suffix
"*<2>"
460 (bufF (and (funcall create-non-file-buffer
"*ibuf-test8f*")
461 (funcall create-non-file-buffer
"*ibuf-test8f*"
463 (with-current-buffer bufA
(set-buffer-modified-p t
))
464 (should (ibuffer-included-in-filters-p
465 bufA
'((and (not starred-name
)
468 (not (size-gt .
100))
469 (mode . picture-mode
)))))
470 (with-current-buffer bufA
(set-buffer-modified-p nil
))
471 (should-not (ibuffer-included-in-filters-p
472 bufA
'((or (starred-name) (visiting-file) (modified)))))
473 (should (ibuffer-included-in-filters-p
474 bufB
'((and (starred-name)
477 (not visiting-file
)))))
478 (should (ibuffer-included-in-filters-p
479 bufC
'((and (not (starred-name))
481 (name .
"8c[^*]*\\*")
483 (should (ibuffer-included-in-filters-p
484 bufD
'((and (not (starred-name))
486 (name .
"\\`\\*.*test8d")
489 (should (ibuffer-included-in-filters-p
490 bufE
'((and (starred-name)
492 (name .
"8e.*?\\*<[[:digit:]]+>")
494 (should (ibuffer-included-in-filters-p
495 bufF
'((and (starred-name)
496 (not (visiting-file))
497 (name .
"8f\\*<[[:digit:]]>")
499 (funcall clean-up
))))
501 ;; Test Filter Combination and Decomposition
502 (let* (ibuffer-to-kill ; if non-nil, kill this buffer at cleanup
503 (ibuffer-already 'check
) ; existing ibuffer buffer to use but not kill
504 ;; Utility functions without polluting the environment
507 "Returns a test ibuffer-mode buffer, creating one if necessary.
508 If a new buffer is created, it is named \"*Test-Ibuffer*\" and is
509 saved to `ibuffer-to-kill' for later cleanup."
510 (when (eq ibuffer-already
'check
)
511 (setq ibuffer-already
513 (dolist (buf (buffer-list) nil
)
514 (when (with-current-buffer buf
515 (derived-mode-p 'ibuffer-mode
))
516 (throw 'found-buf buf
))))))
519 (let ((test-ibuf-name "*Test-Ibuffer*"))
520 (ibuffer nil test-ibuf-name nil t
)
521 (setq ibuffer-to-kill
(get-buffer test-ibuf-name
))))))
524 "Restore all emacs state modified during the tests"
525 (when ibuffer-to-kill
; created ibuffer
526 (with-current-buffer ibuffer-to-kill
527 (set-buffer-modified-p nil
)
529 (kill-buffer ibuffer-to-kill
)
530 (setq ibuffer-to-kill nil
))
531 (when (and ibuffer-already
(not (eq ibuffer-already
'check
)))
532 ;; restore existing ibuffer state
533 (ibuffer-update nil t
)))))
535 (ert-deftest ibuffer-decompose-filter
()
536 "Tests `ibuffer-decompose-filter' for and, or, not, and saved."
537 (skip-unless (featurep 'ibuf-ext
))
539 (let ((ibuf (funcall get-test-ibuffer
)))
540 (with-current-buffer ibuf
541 (let ((ibuffer-filtering-qualifiers nil
)
542 (ibuffer-filter-groups nil
)
543 (filters '((size-gt .
100) (not (starred-name))
546 (push (cons 'or filters
) ibuffer-filtering-qualifiers
)
547 (ibuffer-decompose-filter)
548 (should (equal filters ibuffer-filtering-qualifiers
))
549 (setq ibuffer-filtering-qualifiers nil
))
551 (push (cons 'and filters
) ibuffer-filtering-qualifiers
)
552 (ibuffer-decompose-filter)
553 (should (equal filters ibuffer-filtering-qualifiers
))
554 (setq ibuffer-filtering-qualifiers nil
))
556 (push (list 'not
(car filters
)) ibuffer-filtering-qualifiers
)
557 (ibuffer-decompose-filter)
558 (should (equal (list (car filters
))
559 ibuffer-filtering-qualifiers
))
560 (setq ibuffer-filtering-qualifiers nil
))
562 (push (cons 'not
(car filters
)) ibuffer-filtering-qualifiers
)
563 (ibuffer-decompose-filter)
564 (should (equal (list (car filters
))
565 ibuffer-filtering-qualifiers
))
566 (setq ibuffer-filtering-qualifiers nil
))
567 (let ((gnus (assoc "gnus" ibuffer-saved-filters
)))
568 (push '(saved .
"gnus") ibuffer-filtering-qualifiers
)
569 (ibuffer-decompose-filter)
570 (should (equal (cdr gnus
) ibuffer-filtering-qualifiers
))
571 (ibuffer-decompose-filter)
572 (should (equal (cdr (cadr gnus
)) ibuffer-filtering-qualifiers
))
573 (setq ibuffer-filtering-qualifiers nil
))
574 (when (not (assoc "__unknown__" ibuffer-saved-filters
))
575 (push '(saved .
"__uknown__") ibuffer-filtering-qualifiers
)
576 (should-error (ibuffer-decompose-filter) :type
'error
)
577 (setq ibuffer-filtering-qualifiers nil
))
579 (push (car filters
) ibuffer-filtering-qualifiers
)
580 (should-error (ibuffer-decompose-filter) :type
'error
)
581 (setq ibuffer-filtering-qualifiers nil
)))))
584 (ert-deftest ibuffer-and-filter
()
585 "Tests `ibuffer-and-filter' in an Ibuffer buffer."
586 (skip-unless (featurep 'ibuf-ext
))
588 (let ((ibuf (funcall get-test-ibuffer
)))
589 (with-current-buffer ibuf
590 (let ((ibuffer-filtering-qualifiers nil
)
591 (ibuffer-filter-groups nil
)
592 (filters [(size-gt .
100) (not (starred-name))
593 (filename .
"A") (mode . text-mode
)]))
594 (should-error (ibuffer-and-filter) :type
'error
)
596 (push (aref filters
1) ibuffer-filtering-qualifiers
)
597 (should-error (ibuffer-and-filter) :type
'error
))
599 (push (aref filters
0) ibuffer-filtering-qualifiers
)
601 (and (equal (list 'and
(aref filters
0) (aref filters
1))
602 (car ibuffer-filtering-qualifiers
))
603 (null (cdr ibuffer-filtering-qualifiers
)))))
605 (ibuffer-and-filter 'decompose
)
606 (and (equal (aref filters
0)
607 (pop ibuffer-filtering-qualifiers
))
608 (equal (aref filters
1)
609 (pop ibuffer-filtering-qualifiers
))
610 (null ibuffer-filtering-qualifiers
))))
612 (push (list 'and
(aref filters
2) (aref filters
3))
613 ibuffer-filtering-qualifiers
)
614 (push (list 'and
(aref filters
0) (aref filters
1))
615 ibuffer-filtering-qualifiers
)
617 (and (equal (list 'and
(aref filters
0) (aref filters
1)
618 (aref filters
2) (aref filters
3))
619 (car ibuffer-filtering-qualifiers
))
620 (null (cdr ibuffer-filtering-qualifiers
)))))
621 (pop ibuffer-filtering-qualifiers
)
623 (push (list 'or
(aref filters
2) (aref filters
3))
624 ibuffer-filtering-qualifiers
)
625 (push (list 'and
(aref filters
0) (aref filters
1))
626 ibuffer-filtering-qualifiers
)
628 (and (equal (list 'and
(aref filters
0) (aref filters
1)
629 (list 'or
(aref filters
2)
631 (car ibuffer-filtering-qualifiers
))
632 (null (cdr ibuffer-filtering-qualifiers
)))))
633 (pop ibuffer-filtering-qualifiers
)
635 (push (list 'and
(aref filters
2) (aref filters
3))
636 ibuffer-filtering-qualifiers
)
637 (push (list 'or
(aref filters
0) (aref filters
1))
638 ibuffer-filtering-qualifiers
)
640 (and (equal (list 'and
(list 'or
(aref filters
0)
642 (aref filters
2) (aref filters
3))
643 (car ibuffer-filtering-qualifiers
))
644 (null (cdr ibuffer-filtering-qualifiers
)))))
645 (pop ibuffer-filtering-qualifiers
)
647 (push (list 'or
(aref filters
2) (aref filters
3))
648 ibuffer-filtering-qualifiers
)
649 (push (list 'or
(aref filters
0) (aref filters
1))
650 ibuffer-filtering-qualifiers
)
652 (and (equal (list 'and
653 (list 'or
(aref filters
0)
655 (list 'or
(aref filters
2)
657 (car ibuffer-filtering-qualifiers
))
658 (null (cdr ibuffer-filtering-qualifiers
))))))))
661 (ert-deftest ibuffer-or-filter
()
662 "Tests `ibuffer-or-filter' in an Ibuffer buffer."
663 (skip-unless (featurep 'ibuf-ext
))
665 (let ((ibuf (funcall get-test-ibuffer
)))
666 (with-current-buffer ibuf
667 (let ((ibuffer-filtering-qualifiers nil
)
668 (ibuffer-filter-groups nil
)
669 (filters [(size-gt .
100) (not (starred-name))
670 (filename .
"A") (mode . text-mode
)]))
671 (should-error (ibuffer-or-filter) :type
'error
)
673 (push (aref filters
1) ibuffer-filtering-qualifiers
)
674 (should-error (ibuffer-or-filter) :type
'error
))
676 (push (aref filters
0) ibuffer-filtering-qualifiers
)
678 (and (equal (list 'or
(aref filters
0) (aref filters
1))
679 (car ibuffer-filtering-qualifiers
))
680 (null (cdr ibuffer-filtering-qualifiers
)))))
682 (ibuffer-or-filter 'decompose
)
683 (and (equal (aref filters
0)
684 (pop ibuffer-filtering-qualifiers
))
685 (equal (aref filters
1)
686 (pop ibuffer-filtering-qualifiers
))
687 (null ibuffer-filtering-qualifiers
))))
689 (push (list 'or
(aref filters
2) (aref filters
3))
690 ibuffer-filtering-qualifiers
)
691 (push (list 'or
(aref filters
0) (aref filters
1))
692 ibuffer-filtering-qualifiers
)
694 (and (equal (list 'or
(aref filters
0) (aref filters
1)
695 (aref filters
2) (aref filters
3))
696 (car ibuffer-filtering-qualifiers
))
697 (null (cdr ibuffer-filtering-qualifiers
)))))
698 (pop ibuffer-filtering-qualifiers
)
700 (push (list 'and
(aref filters
2) (aref filters
3))
701 ibuffer-filtering-qualifiers
)
702 (push (list 'or
(aref filters
0) (aref filters
1))
703 ibuffer-filtering-qualifiers
)
705 (and (equal (list 'or
(aref filters
0) (aref filters
1)
706 (list 'and
(aref filters
2)
708 (car ibuffer-filtering-qualifiers
))
709 (null (cdr ibuffer-filtering-qualifiers
)))))
710 (pop ibuffer-filtering-qualifiers
)
712 (push (list 'or
(aref filters
2) (aref filters
3))
713 ibuffer-filtering-qualifiers
)
714 (push (list 'and
(aref filters
0) (aref filters
1))
715 ibuffer-filtering-qualifiers
)
717 (and (equal (list 'or
(list 'and
(aref filters
0)
719 (aref filters
2) (aref filters
3))
720 (car ibuffer-filtering-qualifiers
))
721 (null (cdr ibuffer-filtering-qualifiers
)))))
722 (pop ibuffer-filtering-qualifiers
)
724 (push (list 'and
(aref filters
2) (aref filters
3))
725 ibuffer-filtering-qualifiers
)
726 (push (list 'and
(aref filters
0) (aref filters
1))
727 ibuffer-filtering-qualifiers
)
729 (and (equal (list 'or
730 (list 'and
(aref filters
0)
732 (list 'and
(aref filters
2)
734 (car ibuffer-filtering-qualifiers
))
735 (null (cdr ibuffer-filtering-qualifiers
))))))))
736 (funcall clean-up
))))
738 (ert-deftest ibuffer-format-qualifier
()
739 "Tests string recommendation of filter from `ibuffer-format-qualifier'."
740 (skip-unless (featurep 'ibuf-ext
))
741 (let ((test1 '(mode . org-mode
))
742 (test2 '(size-lt .
100))
743 (test3 '(derived-mode . prog-mode
))
744 (test4 '(or (size-gt .
10000)
745 (and (not (starred-name))
746 (directory .
"\\<org\\>"))))
747 (test5 '(or (filename .
"scratch")
749 (filename .
"temp")))
750 (test6 '(or (mode . emacs-lisp-mode
) (file-extension .
"elc?")
751 (and (starred-name) (name .
"elisp"))
752 (mode . lisp-interaction-mode
)))
753 (description (lambda (q)
754 (cadr (assq q ibuffer-filtering-alist
))))
755 (tag (lambda (&rest args
)
756 (concat " [" (apply #'concat args
) "]"))))
757 (should (equal (ibuffer-format-qualifier test1
)
758 (funcall tag
(funcall description
'mode
)
760 (should (equal (ibuffer-format-qualifier test2
)
761 (funcall tag
(funcall description
'size-lt
)
763 (should (equal (ibuffer-format-qualifier test3
)
764 (funcall tag
(funcall description
'derived-mode
)
766 (should (equal (ibuffer-format-qualifier test4
)
768 (funcall tag
(funcall description
'size-gt
)
769 ": " (format "%s" 10000))
777 (funcall description
'directory
)
778 ": " "\\<org\\>")))))
779 (should (equal (ibuffer-format-qualifier test5
)
781 (funcall tag
(funcall description
'filename
)
783 (funcall tag
(funcall description
'filename
)
785 (funcall tag
(funcall description
'filename
)
787 (should (equal (ibuffer-format-qualifier test6
)
789 (funcall tag
(funcall description
'mode
)
790 ": " "emacs-lisp-mode")
791 (funcall tag
(funcall description
'file-extension
)
795 (funcall description
'starred-name
)
798 (funcall description
'name
)
800 (funcall tag
(funcall description
'mode
)
801 ": " "lisp-interaction-mode"))))))
803 (ert-deftest ibuffer-unary-operand
()
804 "Tests `ibuffer-unary-operand': (not cell) or (not . cell) -> cell."
805 (skip-unless (featurep 'ibuf-ext
))
806 (should (equal (ibuffer-unary-operand '(not .
(mode "foo")))
808 (should (equal (ibuffer-unary-operand '(not (mode "foo")))
810 (should (equal (ibuffer-unary-operand '(not "cdr"))
812 (should (equal (ibuffer-unary-operand '(not)) nil
))
813 (should (equal (ibuffer-unary-operand '(not . a
)) 'a
)))
815 (provide 'ibuffer-tests
)
816 ;; ibuffer-tests.el ends here