2017-06-14 20:26:17 +02:00
|
|
|
;; -*- no-byte-compile: t; -*-
|
|
|
|
;;; core/test/autoload-buffers.el
|
|
|
|
|
2017-12-31 11:45:02 -05:00
|
|
|
(defmacro with-temp-buffers!! (buffer-args &rest body)
|
2017-06-14 20:26:17 +02:00
|
|
|
(declare (indent defun))
|
|
|
|
(let (buffers)
|
|
|
|
(dolist (bsym buffer-args)
|
|
|
|
(push `(,bsym (get-buffer-create ,(symbol-name bsym)))
|
|
|
|
buffers))
|
2017-12-31 11:45:02 -05:00
|
|
|
`(cl-flet ((buffer-list
|
|
|
|
(lambda ()
|
|
|
|
(cl-remove-if-not #'buffer-live-p (list ,@(reverse (mapcar #'car buffers)))))))
|
2018-01-03 14:10:45 -05:00
|
|
|
(let* ((split-width-threshold 0)
|
|
|
|
(window-min-width 0)
|
|
|
|
persp-mode
|
2017-12-31 11:45:02 -05:00
|
|
|
,@buffers)
|
|
|
|
,@body
|
2018-01-03 14:10:45 -05:00
|
|
|
(let (kill-buffer-query-functions kill-buffer-hook)
|
|
|
|
(mapc #'kill-buffer (buffer-list)))))))
|
2017-06-14 20:26:17 +02:00
|
|
|
|
|
|
|
;;
|
|
|
|
(def-test! get-buffers
|
2017-12-31 11:45:02 -05:00
|
|
|
(with-temp-buffers!! (a b c)
|
2017-06-27 01:49:04 +02:00
|
|
|
(should (cl-every #'buffer-live-p (buffer-list)))
|
|
|
|
(should (equal (buffer-list) (list a b c)))
|
2017-06-14 20:26:17 +02:00
|
|
|
(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))))
|
2017-12-31 11:45:02 -05:00
|
|
|
(projectile-mode +1)
|
2017-06-14 20:26:17 +02:00
|
|
|
(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
|
2017-06-27 01:49:04 +02:00
|
|
|
(let ((buffers (doom-project-buffer-list)))
|
2017-06-14 20:26:17 +02:00
|
|
|
(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
|
2017-06-27 01:49:04 +02:00
|
|
|
(let ((buffers (doom-project-buffer-list)))
|
2017-12-31 11:45:02 -05:00
|
|
|
(should (cl-every (lambda (x) (memq x buffers)) (list a b c)))))
|
|
|
|
(projectile-mode -1)))
|
2017-06-14 20:26:17 +02:00
|
|
|
|
2017-06-27 01:49:04 +02:00
|
|
|
(def-test! real-buffers
|
|
|
|
(let (doom-real-buffer-functions)
|
2017-12-31 11:45:02 -05:00
|
|
|
(with-temp-buffers!! (a b c d)
|
2018-01-03 19:59:48 -05:00
|
|
|
(with-current-buffer a
|
|
|
|
(setq-local buffer-file-name "x"))
|
|
|
|
(with-current-buffer b
|
|
|
|
(setq-local doom-real-buffer-p t))
|
2017-06-27 01:49:04 +02:00
|
|
|
(with-current-buffer c
|
|
|
|
(rename-buffer "*C*"))
|
|
|
|
(should (doom-real-buffer-p a))
|
|
|
|
(should (doom-real-buffer-p b))
|
|
|
|
(should-not (doom-real-buffer-p c))
|
|
|
|
(should-not (doom-real-buffer-p d))
|
|
|
|
(let ((buffers (doom-real-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)))))))
|
2017-06-14 20:26:17 +02:00
|
|
|
|
2017-06-27 01:49:04 +02:00
|
|
|
;; `doom-visible-windows'
|
|
|
|
;; `doom-visible-buffers'
|
|
|
|
;; `doom-buried-buffers'
|
|
|
|
(def-test! visible-buffers-and-windows
|
2017-12-31 11:45:02 -05:00
|
|
|
(with-temp-buffers!! (a b c d)
|
2017-06-14 20:26:17 +02:00
|
|
|
(switch-to-buffer a)
|
|
|
|
(should (eq (current-buffer) a))
|
|
|
|
(should (eq (selected-window) (get-buffer-window a)))
|
2017-08-06 16:30:53 +02:00
|
|
|
(split-window nil 1)
|
2017-06-27 01:49:04 +02:00
|
|
|
(switch-to-buffer b)
|
2017-06-14 20:26:17 +02:00
|
|
|
(should (eq (current-buffer) b))
|
2017-06-27 01:49:04 +02:00
|
|
|
(should (eq (selected-window) (get-buffer-window b)))
|
|
|
|
(should (cl-intersection (list a b) (doom-visible-buffers)))
|
|
|
|
(should (cl-intersection (list c d) (doom-buried-buffers)))
|
|
|
|
(should (cl-intersection (mapcar #'get-buffer-window (list a b))
|
|
|
|
(doom-visible-windows)))))
|
2017-06-14 20:26:17 +02:00
|
|
|
|
2017-06-27 01:49:04 +02:00
|
|
|
;; `doom-matching-buffers'
|
2017-06-14 20:26:17 +02:00
|
|
|
(def-test! matching-buffers
|
2017-12-31 11:45:02 -05:00
|
|
|
(with-temp-buffers!! (a b c)
|
2017-06-14 20:26:17 +02:00
|
|
|
(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)))
|
2017-06-27 01:49:04 +02:00
|
|
|
(should (equal buffers (doom-matching-buffers "^[ac]$"))))))
|
2017-06-14 20:26:17 +02:00
|
|
|
|
2017-06-27 01:49:04 +02:00
|
|
|
;; `doom-buffers-in-mode'
|
2017-06-14 20:26:17 +02:00
|
|
|
(def-test! buffers-in-mode
|
2017-12-31 11:45:02 -05:00
|
|
|
(with-temp-buffers!! (a b c d e)
|
2017-06-14 20:26:17 +02:00
|
|
|
(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))))))
|
2017-06-27 01:49:04 +02:00
|
|
|
|
2018-01-03 14:10:45 -05:00
|
|
|
;; `doom-fallback-buffer'
|
|
|
|
(def-test! fallback-buffer
|
|
|
|
(let ((fallback (doom-fallback-buffer)))
|
|
|
|
(should (buffer-live-p fallback))
|
|
|
|
(should (equal (buffer-name fallback) doom-fallback-buffer))))
|
2017-06-27 01:49:04 +02:00
|
|
|
|
|
|
|
;; `doom--cycle-real-buffers'
|
|
|
|
(def-test! kill-buffer-then-show-real-buffer
|
2017-12-31 11:45:02 -05:00
|
|
|
(with-temp-buffers!! (a b c d)
|
2018-01-03 14:10:45 -05:00
|
|
|
(let-advice!! ((kill-this-buffer :around doom*switch-to-fallback-buffer-maybe))
|
|
|
|
(dolist (buf (list a b d))
|
|
|
|
(with-current-buffer buf
|
|
|
|
(setq-local buffer-file-name "x")))
|
|
|
|
(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)))
|
2018-01-03 19:59:48 -05:00
|
|
|
(kill-this-buffer)
|
|
|
|
(should-not (eq (current-buffer) a))
|
|
|
|
(should-not (buffer-live-p a))
|
2018-01-03 14:10:45 -05:00
|
|
|
;; eventually end up in the fallback buffer
|
|
|
|
(let ((fallback (doom-fallback-buffer)))
|
|
|
|
(while (not (eq (current-buffer) fallback))
|
|
|
|
(should (doom-real-buffer-p))
|
|
|
|
(kill-this-buffer))
|
|
|
|
(should (eq (current-buffer) fallback))))))
|
|
|
|
|
|
|
|
;; `doom-kill-buffer-and-windows'
|
|
|
|
(def-test! kill-buffer-and-windows
|
|
|
|
(with-temp-buffers!! (a b)
|
|
|
|
(switch-to-buffer a) (split-window-horizontally)
|
|
|
|
(switch-to-buffer b) (split-window-horizontally)
|
2017-06-27 01:49:04 +02:00
|
|
|
(switch-to-buffer a)
|
2018-01-03 14:10:45 -05:00
|
|
|
|
|
|
|
(should (= (length (doom-visible-windows)) 3))
|
|
|
|
(should (= (length (doom-buffer-list)) 2))
|
|
|
|
|
|
|
|
(doom-kill-buffer-and-windows a)
|
|
|
|
(should-not (buffer-live-p a))
|
|
|
|
(should (= (length (doom-visible-windows)) 1))))
|
2017-06-27 01:49:04 +02:00
|
|
|
|
|
|
|
;; TODO doom/kill-all-buffers
|
|
|
|
;; TODO doom/kill-other-buffers
|
|
|
|
;; TODO doom/kill-matching-buffers
|
2017-12-30 00:59:44 -05:00
|
|
|
;; TODO doom/cleanup-session
|