blob: 4dbbb71006e1585022783f2335339fe89c593f05 (
plain)
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
|
;;; test-undead-buffers--kill-other-window-buffer.el --- Tests for cj/kill-other-window-buffer -*- lexical-binding: t; -*-
;;; Commentary:
;; `cj/kill-other-window-buffer' kills (or buries, for `cj/undead-buffer-list'
;; buffers) the buffer shown in the other window, leaving that window and the
;; split intact -- the window then shows whatever bury/kill surfaces next.
;; Sibling of `cj/kill-other-window' (which deletes the other window); the
;; distinguishing trait here is that the split is preserved.
;;; Code:
(require 'ert)
(require 'cl-lib)
(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(add-to-list 'load-path (expand-file-name "tests" user-emacs-directory))
(require 'undead-buffers)
(ert-deftest test-undead-buffers-kill-other-window-buffer-keeps-the-window ()
"Normal: kills the other window's (non-undead) buffer but keeps the window
and the split -- the current window is left untouched."
(let ((other (generate-new-buffer "test-kill-other-window-buffer"))
(orig (copy-sequence cj/undead-buffer-list)))
(unwind-protect
(save-window-excursion
(delete-other-windows)
(split-window-right)
(let* ((win-a (selected-window))
(buf-a (window-buffer win-a))
(win-b (next-window win-a)))
(set-window-buffer win-b other)
(select-window win-a)
(cj/kill-other-window-buffer)
(should (window-live-p win-b))
(should-not (buffer-live-p other))
(should (eq (window-buffer win-a) buf-a))))
(setq cj/undead-buffer-list orig)
(when (buffer-live-p other) (kill-buffer other)))))
(ert-deftest test-undead-buffers-kill-other-window-buffer-buries-undead ()
"Boundary: an undead buffer in the other window is buried, not killed --
still alive, no longer shown there; the window stays."
(let ((other (generate-new-buffer "test-kill-other-undead"))
(orig (copy-sequence cj/undead-buffer-list)))
(unwind-protect
(save-window-excursion
(add-to-list 'cj/undead-buffer-list (buffer-name other))
(delete-other-windows)
(split-window-right)
(let* ((win-a (selected-window))
(win-b (next-window win-a)))
(set-window-buffer win-b other)
(select-window win-a)
(cj/kill-other-window-buffer)
(should (window-live-p win-b))
(should (buffer-live-p other))
(should-not (eq (window-buffer win-b) other))))
(setq cj/undead-buffer-list orig)
(when (buffer-live-p other) (kill-buffer other)))))
(ert-deftest test-undead-buffers-kill-other-window-buffer-errors-with-one-window ()
"Error: with only one window there is no other window to act on."
(save-window-excursion
(delete-other-windows)
(should-error (cj/kill-other-window-buffer) :type 'user-error)))
(ert-deftest test-undead-buffers-kill-other-window-buffer-bound-under-c-semicolon-b ()
"Normal: reachable via C-; b K."
(require 'custom-buffer-file)
(should (eq (keymap-lookup cj/buffer-and-file-map "K")
#'cj/kill-other-window-buffer)))
(provide 'test-undead-buffers--kill-other-window-buffer)
;;; test-undead-buffers--kill-other-window-buffer.el ends here
|