Rewrite buffer tests; refactor doom-kill-buffer
This commit is contained in:
parent
7b5d2063f8
commit
4d487c3e0f
2 changed files with 113 additions and 53 deletions
|
@ -1,36 +1,91 @@
|
|||
;;; test/core/autoload/test-buffers.el
|
||||
|
||||
(defmacro with-temp-buffers! (buffer-args &rest body)
|
||||
(declare (indent defun))
|
||||
(let (buffers)
|
||||
(dolist (bsym buffer-args)
|
||||
(push `(,bsym (get-buffer-create ,(symbol-name bsym)))
|
||||
buffers))
|
||||
`(let* (,@buffers
|
||||
(buffer-list (list ,@(reverse (mapcar #'car buffers)))))
|
||||
,@body
|
||||
(mapc #'kill-buffer buffer-list))))
|
||||
|
||||
(def-test-group! core/autoload/buffers
|
||||
(ert-deftest get-buffers ()
|
||||
(let ((a (get-buffer-create "*a*"))
|
||||
(b (get-buffer-create "*b*"))
|
||||
(c (get-buffer-create "*c*"))
|
||||
(buffers (doom-buffer-list)))
|
||||
(should buffers)
|
||||
(should (cl-every 'bufferp buffers))
|
||||
(should (cl-every (lambda (b) (memq b buffers)) (list a b c)))))
|
||||
(with-temp-buffers! (a b c)
|
||||
(should (cl-every #'buffer-live-p buffer-list))
|
||||
(should (equal buffer-list (list a b c)))
|
||||
(dolist (buf (list (cons a doom-emacs-dir)
|
||||
(cons b doom-emacs-dir)
|
||||
(cons c "/tmp/")))
|
||||
(with-current-buffer (car buf)
|
||||
(setq-local default-directory (cdr buf))))
|
||||
(with-current-buffer a
|
||||
;; should produce all buffers
|
||||
(let ((buffers (doom-buffer-list)))
|
||||
(should (cl-every (lambda (x) (memq x buffers)) (list a b c))))
|
||||
;; should produce only project buffers
|
||||
(let ((buffers (doom-buffer-list t)))
|
||||
(should (cl-every (lambda (x) (memq x buffers)) (list a b)))
|
||||
(should-not (memq c buffers))))
|
||||
;; If no project is available, just get all buffers
|
||||
(with-current-buffer c
|
||||
(let ((buffers (doom-buffer-list t)))
|
||||
(should (cl-every (lambda (x) (memq x buffers)) (list a b c)))))))
|
||||
|
||||
(ert-deftest get-real-buffers ()
|
||||
(with-temp-buffers! (a b c d)
|
||||
(with-current-buffer c
|
||||
(rename-buffer "*C*"))
|
||||
(with-current-buffer d
|
||||
(doom-popup-mode +1))
|
||||
(let ((buffers (doom-real-buffers-list buffer-list)))
|
||||
(should (= (length buffers) 2))
|
||||
(should (cl-every (lambda (x) (memq x buffers)) (list a b)))
|
||||
(should (cl-notany (lambda (x) (memq x buffers)) (list c d))))))
|
||||
|
||||
(ert-deftest kill-buffers ()
|
||||
(with-temp-buffers! (a b)
|
||||
(doom-kill-buffer a)
|
||||
(should-not (buffer-live-p a))
|
||||
;; modified buffer
|
||||
(with-current-buffer b
|
||||
(set-buffer-modified-p t))
|
||||
(doom-kill-buffer b t)
|
||||
(should-not (buffer-live-p a))))
|
||||
|
||||
(ert-deftest kill-buffer-then-show-real-buffer ()
|
||||
(with-temp-buffers! (a b c)
|
||||
(should (cl-every #'buffer-live-p buffer-list))
|
||||
(switch-to-buffer a)
|
||||
(should (eq (current-buffer) a))
|
||||
(should (eq (selected-window) (get-buffer-window a)))
|
||||
(should (doom-kill-buffer a))
|
||||
(should (eq (current-buffer) b))
|
||||
(should (doom-kill-buffer))
|
||||
(should (eq (current-buffer) c))
|
||||
(doom/kill-this-buffer)
|
||||
(should (eq (current-buffer) (doom-fallback-buffer)))))
|
||||
|
||||
(ert-deftest matching-buffers ()
|
||||
(let ((a (get-buffer-create "*a*"))
|
||||
(b (get-buffer-create "*b*"))
|
||||
(c (get-buffer-create "*c*"))
|
||||
(buffers (doom-matching-buffers "^\\*[ac]\\*$")))
|
||||
(should (= 2 (length buffers)))
|
||||
(should (cl-every 'bufferp buffers))
|
||||
(should (cl-every (lambda (b) (memq b buffers)) (list a c)))))
|
||||
(with-temp-buffers! (a b c)
|
||||
(let ((buffers (doom-matching-buffers "^[ac]$")))
|
||||
(should (= 2 (length buffers)))
|
||||
(should (cl-every #'bufferp buffers))
|
||||
(should (cl-every (lambda (x) (memq x buffers)) (list a c)))
|
||||
(should (equal (reverse buffers) (doom-matching-buffers "^[ac]$" buffer-list))))))
|
||||
|
||||
(ert-deftest buffers-in-mode ()
|
||||
(dolist (name (list "*a*" "*b*"))
|
||||
(with-current-buffer (get-buffer-create name)
|
||||
(emacs-lisp-mode)))
|
||||
(dolist (name (list "*c*" "*d*" "*e*"))
|
||||
(with-current-buffer (get-buffer-create name)
|
||||
(text-mode)))
|
||||
(let ((el-buffers (doom-buffers-in-mode 'emacs-lisp-mode))
|
||||
(txt-buffers (doom-buffers-in-mode 'text-mode)))
|
||||
(should (cl-every 'bufferp (append el-buffers txt-buffers)))
|
||||
(should (= 2 (length el-buffers)))
|
||||
(should (= 3 (length txt-buffers)))))
|
||||
|
||||
;; TODO
|
||||
)
|
||||
(with-temp-buffers! (a b c d e)
|
||||
(dolist (buf (list a b))
|
||||
(with-current-buffer buf
|
||||
(emacs-lisp-mode)))
|
||||
(dolist (buf (list c d e))
|
||||
(with-current-buffer buf
|
||||
(text-mode)))
|
||||
(let ((el-buffers (doom-buffers-in-mode 'emacs-lisp-mode))
|
||||
(txt-buffers (doom-buffers-in-mode 'text-mode)))
|
||||
(should (cl-every #'buffer-live-p (append el-buffers txt-buffers)))
|
||||
(should (= 2 (length el-buffers)))
|
||||
(should (= 3 (length txt-buffers)))))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue