unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
blob aa0699435e4eaf599010c86853f945dbe1de0a6c 30171 bytes (raw)
name: test/lisp/ibuffer-tests.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
 
;;; ibuffer-tests.el --- Test suite. -*- lexical-binding: t -*-

;; Copyright (C) 2015-2016 Free Software Foundation, Inc.

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.

;;; Code:
(require 'ert)
(require 'ibuffer)

(ert-deftest ibuffer-autoload ()
  "Tests to see whether ibuffer has been autoloaded"
  (skip-unless (not (featurep 'ibuf-ext)))
  (should
   (fboundp 'ibuffer-mark-unsaved-buffers))
  (should
   (autoloadp
    (symbol-function
     'ibuffer-mark-unsaved-buffers))))

;; Test Filter Inclusion
(let* (test-buffer-list  ; accumulated buffers to clean up
       ;; Utility functions without polluting the environment
       (set-buffer-mode
        (lambda (buffer mode)
          "Set BUFFER's major mode to MODE, a mode function, or fundamental."
          (with-current-buffer buffer
            (funcall (or mode #'fundamental-mode)))))
       (set-buffer-contents
        (lambda (buffer size include-content)
          "Add exactly SIZE bytes to BUFFER, including INCLUDE-CONTENT."
          (when (or size include-content)
            (let* ((unit "\n")
                   (chunk "ccccccccccccccccccccccccccccccc\n")
                   (chunk-size (length chunk))
                   (size (if (and size include-content (stringp include-content))
                             (- size (length include-content))
                           size)))
              (unless (or (null size) (> size 0))
                (error "size argument must be nil or positive"))
              (with-current-buffer buffer
                (when include-content
                  (insert include-content))
                (when size
                  (dotimes (_ (floor size chunk-size))
                    (insert chunk))
                  (dotimes (_ (mod size chunk-size))
                    (insert unit)))
                ;; prevent query on cleanup
                (set-buffer-modified-p nil))))))
       (create-file-buffer
        (lambda (prefix &rest args-plist)
          "Create a file and buffer with designated properties.
        PREFIX is a string giving the beginning of the name, and ARGS-PLIST
        is a series of keyword-value pairs, with allowed keywords
        :suffix STRING, :size NUMBER, :mode MODE-FUNC, :include-content STRING.  
        Returns the created buffer."
          (let* ((suffix  (plist-get args-plist :suffix))
                 (size    (plist-get args-plist :size))
                 (include (plist-get args-plist :include-content))
                 (mode    (plist-get args-plist :mode))
                 (file    (make-temp-file prefix nil suffix))
                 (buf     (find-file-noselect file t)))
            (push buf test-buffer-list) ; record for cleanup
            (funcall set-buffer-mode buf mode)
            (funcall set-buffer-contents buf size include)
            buf)))
       (create-non-file-buffer
        (lambda (prefix &rest args-plist)
          "Create a file and buffer with designated properties.
        PREFIX is a string giving the beginning of the name, and ARGS-PLIST
        is a series of keyword-value pairs, with allowed keywords
        :size NUMBER, :mode MODE-FUNC, :include-content STRING.
        Returns the created buffer."
          (let* ((size    (plist-get args-plist :size))
                 (include (plist-get args-plist :include-content))
                 (mode    (plist-get args-plist :mode))
                 (buf     (generate-new-buffer prefix)))
            (push buf test-buffer-list) ; record for cleanup
            (funcall set-buffer-mode buf mode)
            (funcall set-buffer-contents buf size include)
            buf)))
       (clean-up
        (lambda ()
          "Restore all emacs state modified during the tests"
          (while test-buffer-list       ; created temporary buffers
            (let ((buf (pop test-buffer-list)))
              (with-current-buffer buf (bury-buffer)) ; ensure not selected
              (kill-buffer buf))))))
  ;; Tests
  (ert-deftest ibuffer-filter-inclusion-1 ()
    "Tests inclusion using basic filter combinators with a single buffer."
    (skip-unless (featurep 'ibuf-ext))
    (unwind-protect
        (let ((buf
               (funcall create-file-buffer "ibuf-test-1" :size 100
                        :include-content "One ring to rule them all\n")))
          (should (ibuffer-included-in-filters-p buf '((size-gt . 99))))
          (should (ibuffer-included-in-filters-p buf '((size-lt . 101))))
          (should (ibuffer-included-in-filters-p
                   buf '((mode . fundamental-mode))))
          (should (ibuffer-included-in-filters-p
                   buf '((content . "ring to rule them all"))))
          (should (ibuffer-included-in-filters-p
                   buf '((and (content . "ring to rule them all")))))
          (should (ibuffer-included-in-filters-p
                   buf '((and (and (content . "ring to rule them all"))))))
          (should (ibuffer-included-in-filters-p
                   buf '((and (and (and (content . "ring to rule them all")))))))
          (should (ibuffer-included-in-filters-p
                   buf '((or (content . "ring to rule them all")))))
          (should (ibuffer-included-in-filters-p
                   buf '((not (not (content . "ring to rule them all"))))))
          (should (ibuffer-included-in-filters-p
                   buf '((and (size-gt . 99)
                              (content . "ring to rule them all")
                              (mode . fundamental-mode)
                              (filename-base . "\\`ibuf-test-1")))))
          (should (ibuffer-included-in-filters-p
                   buf '((not (or (not (size-gt . 99))
                                  (not (content . "ring to rule them all"))
                                  (not (mode . fundamental-mode))
                                  (not (filename-base . "\\`ibuf-test-1")))))))
          (should (ibuffer-included-in-filters-p
                   buf '((and (or (size-gt . 99) (size-lt . 10))
                              (and (content . "ring.*all")
                                   (content . "rule")
                                   (content . "them all")
                                   (content . "One"))
                              (not (mode . text-mode))
                              (filename-base . "\\`ibuf-test-1"))))))
      (funcall clean-up)))
  
  (ert-deftest ibuffer-filter-inclusion-2 ()
    "Tests inclusion of basic filters in combination on a single buffer."
    (skip-unless (featurep 'ibuf-ext))
    (unwind-protect
        (let ((buf
               (funcall create-file-buffer "ibuf-test-2" :size 200
                        :mode #'text-mode
                        :include-content "and in the darkness find them\n")))
          (message "--> %s" buf)
          (should (ibuffer-included-in-filters-p buf '((size-gt . 199))))
          (should (ibuffer-included-in-filters-p buf '((size-lt . 201))))
          (should (ibuffer-included-in-filters-p buf '((not size-gt . 200))))
          (should (ibuffer-included-in-filters-p buf '((not (size-gt . 200)))))
          (should (ibuffer-included-in-filters-p
                   buf '((and (size-gt . 199) (size-lt . 201)))))
          (should (ibuffer-included-in-filters-p
                   buf '((or (size-gt . 199) (size-gt . 201)))))
          (should (ibuffer-included-in-filters-p
                   buf '((or (size-gt . 201) (size-gt . 199)))))
          (should (ibuffer-included-in-filters-p
                   buf '((size-gt . 199) (mode . text-mode)
                         (content . "darkness find them"))))
          (should (ibuffer-included-in-filters-p
                   buf '((and (size-gt . 199) (mode . text-mode)
                              (content . "darkness find them")))))
          (should (ibuffer-included-in-filters-p
                   buf '((not (or (not (size-gt . 199)) (not (mode . text-mode))
                                  (not (content . "darkness find them")))))))
          (should (ibuffer-included-in-filters-p
                   buf '((or (size-gt . 200) (content . "darkness find them")
                             (derived-mode . emacs-lisp-mode)))))
          (should-not (ibuffer-included-in-filters-p
                       buf '((or (size-gt . 200) (content . "rule them all")
                                 (derived-mode . emacs-lisp-mode)))))
          (message "--> %s" buf))
      (funcall clean-up)))

  (ert-deftest ibuffer-filter-inclusion-3 ()
    "Tests inclusion with filename filters on specified buffers."
    (skip-unless (featurep 'ibuf-ext))
    (unwind-protect
        (let* ((bufA
                (funcall create-file-buffer "ibuf-test-3.a" :size 50
                         :mode #'text-mode
                         :include-content "...but a multitude of drops?\n"))
               (bufB
                (funcall create-non-file-buffer "ibuf-test-3.b" :size 50
                         :mode #'text-mode
                         :include-content "...but a multitude of drops?\n"))
               (dirA (with-current-buffer bufA default-directory))
               (dirB (with-current-buffer bufB default-directory)))
          (should (ibuffer-included-in-filters-p
                   bufA '((filename-base . "ibuf-test-3"))))
          (should (ibuffer-included-in-filters-p
                   bufA '((filename-root . "ibuf-test-3"))))
          (should (ibuffer-included-in-filters-p
                   bufA '((filename-base . "test-3\\.a"))))
          (should (ibuffer-included-in-filters-p
                   bufA '((filename-extension . "a"))))
          (should (ibuffer-included-in-filters-p
                   bufA (list (cons 'filename-directory dirA))))
          (should-not (ibuffer-included-in-filters-p
                       bufB '((filename-base . "ibuf-test-3"))))
          (should-not (ibuffer-included-in-filters-p
                       bufB '((filename-root . "ibuf-test-3"))))
          (should-not (ibuffer-included-in-filters-p
                       bufB '((filename-extension . "b"))))
          (should-not (ibuffer-included-in-filters-p
                       bufB (list (cons 'filename-directory dirB))))
          (should (ibuffer-included-in-filters-p
                   bufA '((name . "ibuf-test-3"))))
          (should (ibuffer-included-in-filters-p
                   bufB '((name . "ibuf-test-3")))))
      (funcall clean-up)))

  (ert-deftest ibuffer-filter-inclusion-4 ()
    "Tests inclusion with various filters on a single buffer."
    (skip-unless (featurep 'ibuf-ext))
    (unwind-protect
        (let ((buf
               (funcall create-file-buffer "ibuf-test-4"
                        :mode #'emacs-lisp-mode :suffix ".el"
                        :include-content "(message \"--%s--\" 'emacs-rocks)\n")))
          (should (ibuffer-included-in-filters-p
                   buf '((filename-extension . "el"))))
          (should (ibuffer-included-in-filters-p
                   buf '((derived-mode . prog-mode))))
          (should (ibuffer-included-in-filters-p
                   buf '((used-mode . emacs-lisp-mode))))
          (should (ibuffer-included-in-filters-p
                   buf '((mode . emacs-lisp-mode))))
          (with-current-buffer buf (set-buffer-modified-p t))
          (should (ibuffer-included-in-filters-p buf '((modified))))
          (with-current-buffer buf (set-buffer-modified-p nil))
          (should (ibuffer-included-in-filters-p buf '((not modified))))
          (should (ibuffer-included-in-filters-p
                   buf '((and (filename-extension . "el")
                              (derived-mode . prog-mode)
                              (not modified)))))
          (should (ibuffer-included-in-filters-p
                   buf '((or (filename-extension . "tex")
                             (derived-mode . prog-mode)
                             (modified)))))
          (should (ibuffer-included-in-filters-p
                   buf '((filename-extension . "el")
                         (derived-mode . prog-mode)
                         (not modified)))))
      (funcall clean-up)))

  (ert-deftest ibuffer-filter-inclusion-5 ()
    "Tests inclusion with various filters on a single buffer."
    (skip-unless (featurep 'ibuf-ext))
    (unwind-protect
        (let ((buf
               (funcall create-non-file-buffer "ibuf-test-5.el"
                        :mode #'emacs-lisp-mode 
                        :include-content
                        "(message \"--%s--\" \"It really does!\")\n")))
          (should-not (ibuffer-included-in-filters-p
                       buf '((filename-extension . "el"))))
          (should (ibuffer-included-in-filters-p
                   buf '((size-gt . 18))))
          (should (ibuffer-included-in-filters-p
                   buf '((predicate . (lambda ()
                                        (> (- (point-max) (point-min)) 18))))))
          (should (ibuffer-included-in-filters-p
                   buf '((and (mode . emacs-lisp-mode)
                              (or (starred-name)
                                  (size-gt . 18))
                              (and (not (size-gt . 100))
                                   (content . "[Ii]t  *really does!")
                                   (or (name . "test-5")
                                       (not (filename . "test-5")))))))))
      (funcall clean-up)))

  (ert-deftest ibuffer-filter-inclusion-6 ()
    "Tests inclusion using saved filters and DeMorgan's laws."
    (skip-unless (featurep 'ibuf-ext))
    (unwind-protect
        (let ((buf
               (funcall create-non-file-buffer "*ibuf-test-6*" :size 65
                        :mode #'text-mode))
              (buf2
               (funcall create-file-buffer "ibuf-test-6a" :suffix ".html"
                        :mode #'html-mode
                        :include-content
                        "<HTML><BODY><H1>Hello, World!</H1></BODY></HTML>")))
          (should (ibuffer-included-in-filters-p buf '((starred-name))))
          (should-not (ibuffer-included-in-filters-p
                       buf '((saved . "text document"))))
          (should (ibuffer-included-in-filters-p buf2 '((saved . "web"))))
          (should (ibuffer-included-in-filters-p
                   buf2 '((not (and (not (derived-mode . sgml-mode))
                                    (not (derived-mode . css-mode))
                                    (not (mode         . javascript-mode))
                                    (not (mode         . js2-mode))
                                    (not (mode         . scss-mode))
                                    (not (derived-mode . haml-mode))
                                    (not (mode         . sass-mode)))))))
          (should (ibuffer-included-in-filters-p
                   buf '((and (starred-name)
                              (or (size-gt . 50) (filename . "foo"))))))
          (should (ibuffer-included-in-filters-p
                   buf '((not (or (not starred-name)
                                  (and (size-lt . 51)
                                       (not (filename . "foo")))))))))
      (funcall clean-up)))

  (ert-deftest ibuffer-filter-inclusion-7 ()
    "Tests inclusion with various filters on a single buffer."
    (skip-unless (featurep 'ibuf-ext))
    (unwind-protect
        (let ((buf
               (funcall create-non-file-buffer "ibuf-test-7"
                        :mode #'artist-mode)))
          (should (ibuffer-included-in-filters-p
                   buf '((not (starred-name)))))
          (should (ibuffer-included-in-filters-p
                   buf '((not starred-name))))
          (should (ibuffer-included-in-filters-p
                   buf '((not (not (not starred-name))))))
          (should (ibuffer-included-in-filters-p
                   buf '((not (modified)))))
          (should (ibuffer-included-in-filters-p
                   buf '((not modified))))
          (should (ibuffer-included-in-filters-p
                   buf '((not (not (not modified)))))))
      (funcall clean-up)))

  (ert-deftest ibuffer-filter-inclusion-8 ()
    "Tests inclusion with various filters on a single buffer."
    (skip-unless (featurep 'ibuf-ext))
    (unwind-protect
        (let ((buf
               (funcall create-non-file-buffer "ibuf-test-8"
                        :mode #'artist-mode)))
          (should (ibuffer-included-in-filters-p
                   buf '((and (not (starred-name))
                              (name . "test-8")
                              (not (size-gt . 100))
                              (mode . picture-mode))))))
      (funcall clean-up))))

;; Test Filter Combination and Decomposition
(let* (ibuffer-to-kill       ; if non-nil, kill this buffer at cleanup
       (ibuffer-already 'check) ; existing ibuffer buffer to use but not kill
       ;; Utility functions without polluting the environment
       (get-test-ibuffer
        (lambda ()
          "Returns a test ibuffer-mode buffer, creating one if necessary.
        If a new buffer is created, it is named  \"*Test-Ibuffer*\" and is
        saved to `ibuffer-to-kill' for later cleanup."
          (when (eq ibuffer-already 'check)
            (setq ibuffer-already
                  (catch 'found-buf
                    (dolist (buf (buffer-list) nil)
                      (when (with-current-buffer buf
                              (derived-mode-p 'ibuffer-mode))
                        (throw 'found-buf buf))))))
          (or ibuffer-already
              ibuffer-to-kill
              (let ((test-ibuf-name "*Test-Ibuffer*"))
                (ibuffer nil test-ibuf-name nil t)
                (setq ibuffer-to-kill (get-buffer test-ibuf-name))))))
       (clean-up
        (lambda ()
          "Restore all emacs state modified during the tests"
          (when ibuffer-to-kill         ; created ibuffer 
            (with-current-buffer ibuffer-to-kill
              (set-buffer-modified-p nil)
              (bury-buffer))
            (kill-buffer ibuffer-to-kill)
            (setq ibuffer-to-kill nil))
          (when (and ibuffer-already (not (eq ibuffer-already 'check)))
            ;; restore existing ibuffer state
            (ibuffer-update nil t)))))
  ;; Tests
  (ert-deftest ibuffer-decompose-filter ()
    "Tests `ibuffer-decompose-filter' for and, or, not, and saved."
    (skip-unless (featurep 'ibuf-ext))
    (unwind-protect
        (let ((ibuf (funcall get-test-ibuffer)))
          (with-current-buffer ibuf
            (let ((ibuffer-filtering-qualifiers nil)
                  (ibuffer-filter-groups nil)
                  (filters '((size-gt . 100) (not (starred-name))
                             (name . "foo"))))
              (progn
                (push (cons 'or filters) ibuffer-filtering-qualifiers)
                (ibuffer-decompose-filter)
                (should (equal filters ibuffer-filtering-qualifiers))
                (setq ibuffer-filtering-qualifiers nil))
              (progn
                (push (cons 'and filters) ibuffer-filtering-qualifiers)
                (ibuffer-decompose-filter)
                (should (equal filters ibuffer-filtering-qualifiers))
                (setq ibuffer-filtering-qualifiers nil))
              (progn
                (push (list 'not (car filters)) ibuffer-filtering-qualifiers)
                (ibuffer-decompose-filter)
                (should (equal (list (car filters))
                               ibuffer-filtering-qualifiers))
                (setq ibuffer-filtering-qualifiers nil))
              (progn
                (push (cons 'not (car filters)) ibuffer-filtering-qualifiers)
                (ibuffer-decompose-filter)
                (should (equal (list (car filters))
                               ibuffer-filtering-qualifiers))
                (setq ibuffer-filtering-qualifiers nil))
              (let ((gnus (assoc "gnus" ibuffer-saved-filters)))
                (push '(saved . "gnus") ibuffer-filtering-qualifiers)
                (ibuffer-decompose-filter)
                (should (equal (cdr gnus) ibuffer-filtering-qualifiers))
                (ibuffer-decompose-filter)
                (should (equal (cdr (cadr gnus)) ibuffer-filtering-qualifiers))
                (setq ibuffer-filtering-qualifiers nil))
              (when (not (assoc "__unknown__" ibuffer-saved-filters))
                (push '(saved . "__uknown__") ibuffer-filtering-qualifiers)
                (should-error (ibuffer-decompose-filter) :type 'error)
                (setq ibuffer-filtering-qualifiers nil))
              (progn
                (push (car filters) ibuffer-filtering-qualifiers)
                (should-error (ibuffer-decompose-filter) :type 'error)
                (setq ibuffer-filtering-qualifiers nil)))))
      (funcall clean-up)))

  (ert-deftest ibuffer-and-filter ()
    "Tests `ibuffer-and-filter' in an Ibuffer buffer."
    (skip-unless (featurep 'ibuf-ext))
    (unwind-protect
        (let ((ibuf (funcall get-test-ibuffer)))
          (with-current-buffer ibuf
            (let ((ibuffer-filtering-qualifiers nil)
                  (ibuffer-filter-groups nil)
                  (filters [(size-gt . 100) (not (starred-name))]))
              (should-error (ibuffer-and-filter) :type 'error)
              (progn
                (push (aref filters 1) ibuffer-filtering-qualifiers)
                (should-error (ibuffer-and-filter) :type 'error))
              (should (progn
                        (push (aref filters 0) ibuffer-filtering-qualifiers)
                        (ibuffer-and-filter)
                        (and (equal (list 'and (aref filters 0) (aref filters 1))
                                    (car ibuffer-filtering-qualifiers))
                             (null (cdr ibuffer-filtering-qualifiers)))))
              (should (progn
                        (ibuffer-and-filter 'decompose)
                        (and (equal (aref filters 0)
                                    (pop ibuffer-filtering-qualifiers))
                             (equal (aref filters 1)
                                    (pop ibuffer-filtering-qualifiers))
                             (null ibuffer-filtering-qualifiers)))))))
      (funcall clean-up)))
  
  (ert-deftest ibuffer-or-filter ()
    "Tests `ibuffer-or-filter' in an Ibuffer buffer."
    (skip-unless (featurep 'ibuf-ext))
    (unwind-protect
        (let ((ibuf (funcall get-test-ibuffer)))
          (with-current-buffer ibuf
            (let ((ibuffer-filtering-qualifiers nil)
                  (ibuffer-filter-groups nil)
                  (filters [(size-gt . 100) (not (starred-name))]))
              (should-error (ibuffer-or-filter) :type 'error)
              (progn
                (push (aref filters 1) ibuffer-filtering-qualifiers)
                (should-error (ibuffer-or-filter) :type 'error))
              (should (progn
                        (push (aref filters 0) ibuffer-filtering-qualifiers)
                        (ibuffer-or-filter)
                        (and (equal (list 'or (aref filters 0) (aref filters 1))
                                    (car ibuffer-filtering-qualifiers))
                             (null (cdr ibuffer-filtering-qualifiers)))))
              (should (progn
                        (ibuffer-or-filter 'decompose)
                        (and (equal (aref filters 0)
                                    (pop ibuffer-filtering-qualifiers))
                             (equal (aref filters 1)
                                    (pop ibuffer-filtering-qualifiers))
                             (null ibuffer-filtering-qualifiers)))))))
      (funcall clean-up))))

(ert-deftest ibuffer-save-filters ()
  "Tests that `ibuffer-save-filters' saves in the proper format."
  (skip-unless (featurep 'ibuf-ext))
  (let ((ibuffer-save-with-custom nil)
        (ibuffer-saved-filters nil)
        (test1 '((mode . org-mode)
                 (or (size-gt . 10000)
                     (and (not (starred-name))
                          (filename-directory . "\<org\>")))))
        (test2 '((or (mode . emacs-lisp-mode) (filename-extension . "elc?")
                     (and (starred-name) (name . "elisp"))
                     (mode . lisp-interaction-mode))))
        (test3 '((size-lt . 100) (derived-mode . prog-mode)
                 (or (filename-root . "scratch")
                     (filename-root . "bonz")
                     (filename-root . "temp")))))
    (ibuffer-save-filters "test1" test1)
    (should (equal (car ibuffer-saved-filters) (cons "test1" test1)))
    (ibuffer-save-filters "test2" test2)
    (should (equal (car ibuffer-saved-filters) (cons "test2" test2)))
    (should (equal (cadr ibuffer-saved-filters) (cons "test1" test1)))
    (ibuffer-save-filters "test3" test3)
    (should (equal (car ibuffer-saved-filters) (cons "test3" test3)))
    (should (equal (cadr ibuffer-saved-filters) (cons "test2" test2)))
    (should (equal (car (cddr ibuffer-saved-filters)) (cons "test1" test1)))
    (should (equal (cdr (assoc "test1" ibuffer-saved-filters)) test1))
    (should (equal (cdr (assoc "test2" ibuffer-saved-filters)) test2))
    (should (equal (cdr (assoc "test3" ibuffer-saved-filters)) test3))))

(ert-deftest ibuffer-format-qualifier ()
  "Tests string recommendation of filter from `ibuffer-format-qualifier'."
  (skip-unless (featurep 'ibuf-ext))
  (let ((test1 '(mode . org-mode))
        (test2 '(size-lt . 100))
        (test3 '(derived-mode . prog-mode))
        (test4 '(or (size-gt . 10000)
                    (and (not (starred-name))
                         (filename-directory . "\\<org\\>"))))
        (test5 '(or (filename-root . "scratch")
                    (filename-root . "bonz")
                    (filename-root . "temp")))
        (test6 '(or (mode . emacs-lisp-mode) (filename-extension . "elc?")
                    (and (starred-name) (name . "elisp"))
                    (mode . lisp-interaction-mode)))
        (description (lambda (q)
                       (cadr (assq q ibuffer-filtering-alist))))
        (tag (lambda (&rest args )
               (concat " [" (apply #'concat args) "]"))))
    (should (equal (ibuffer-format-qualifier test1)
                   (funcall tag (funcall description 'mode)
                            ": " "org-mode")))
    (should (equal (ibuffer-format-qualifier test2)
                   (funcall tag (funcall description 'size-lt)
                            ": " "100")))
    (should (equal (ibuffer-format-qualifier test3)
                   (funcall tag (funcall description 'derived-mode)
                            ": " "prog-mode")))
    (should (equal (ibuffer-format-qualifier test4)
                   (funcall tag "OR"
                            (funcall tag (funcall description 'size-gt)
                                     ": " (format "%s" 10000))
                            (funcall tag "AND"
                                     (funcall tag "NOT"
                                              (funcall tag
                                                       (funcall description
                                                                'starred-name)
                                                       ": " "nil"))
                                     (funcall tag
                                              (funcall description 'filename-directory)
                                              ": " "\\<org\\>")))))
    (should (equal (ibuffer-format-qualifier test5)
                   (funcall tag "OR"
                            (funcall tag (funcall description 'filename-root)
                                     ": "  "scratch")
                            (funcall tag (funcall description 'filename-root)
                                     ": " "bonz")
                            (funcall tag (funcall description 'filename-root)
                                     ": " "temp"))))
    (should (equal (ibuffer-format-qualifier test6)
                   (funcall tag "OR"
                            (funcall tag (funcall description 'mode)
                                     ": " "emacs-lisp-mode")
                            (funcall tag (funcall description 'filename-extension)
                                     ": " "elc?")
                            (funcall tag "AND"
                                     (funcall tag
                                              (funcall description 'starred-name)
                                              ": " "nil")
                                     (funcall tag
                                              (funcall description 'name)
                                              ": " "elisp"))
                            (funcall tag (funcall description 'mode)
                                     ": " "lisp-interaction-mode"))))))

(ert-deftest ibuffer-unary-operand ()
  "Tests `ibuffer-unary-operand': (not cell) or (not . cell) -> cell."
  (skip-unless (featurep 'ibuf-ext))
  (should (equal (ibuffer-unary-operand '(not . (mode "foo")))
                 '(mode "foo")))
  (should (equal (ibuffer-unary-operand '(not (mode "foo")))
                 '(mode "foo")))
  (should (equal (ibuffer-unary-operand '(not "cdr"))
                 '("cdr")))
  (should (equal (ibuffer-unary-operand '(not)) nil))
  (should (equal (ibuffer-unary-operand '(not . a)) 'a)))


(provide 'ibuffer-tests)
;; ibuffer-tests.el ends here

debug log:

solving aa06994 ...
found aa06994 in https://yhetil.org/emacs-devel/CAPum5Fg42OK=6BTYmdyN4S+SpciRdfWUaLBPoEF671E5o6aSnw@mail.gmail.com/ ||
	https://yhetil.org/emacs-devel/CAPum5FgZYM0ik+cATxdQeNwWz2eGgVEp8f8=D6UynJzMqmVX5A@mail.gmail.com/
found de281c0 in https://git.savannah.gnu.org/cgit/emacs.git
preparing index
index prepared:
100644 de281c03735700b469f280332a44b6f066232e60	test/lisp/ibuffer-tests.el

applying [1/1] https://yhetil.org/emacs-devel/CAPum5Fg42OK=6BTYmdyN4S+SpciRdfWUaLBPoEF671E5o6aSnw@mail.gmail.com/
diff --git a/test/lisp/ibuffer-tests.el b/test/lisp/ibuffer-tests.el
index de281c0..aa06994 100644

1:54: trailing whitespace.
        :suffix STRING, :size NUMBER, :mode MODE-FUNC, :include-content STRING.  
1:131: trailing whitespace.
  
1:247: trailing whitespace.
                        :mode #'emacs-lisp-mode 
1:359: trailing whitespace.
          (when ibuffer-to-kill         ; created ibuffer 
1:445: trailing whitespace.
  
Checking patch test/lisp/ibuffer-tests.el...
Applied patch test/lisp/ibuffer-tests.el cleanly.
warning: 5 lines add whitespace errors.

skipping https://yhetil.org/emacs-devel/CAPum5FgZYM0ik+cATxdQeNwWz2eGgVEp8f8=D6UynJzMqmVX5A@mail.gmail.com/ for aa06994
index at:
100644 aa0699435e4eaf599010c86853f945dbe1de0a6c	test/lisp/ibuffer-tests.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).