summaryrefslogtreecommitdiff
path: root/tests/test-undead-buffers-kill-buffer-or-bury-alive.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2025-10-22 12:27:05 -0500
committerCraig Jennings <c@cjennings.net>2025-10-22 12:27:05 -0500
commitc4e9232f297ffda4443477c589f29052178d2c87 (patch)
treef4c50c999bf18a57e08c439ad244b23b006d0730 /tests/test-undead-buffers-kill-buffer-or-bury-alive.el
parent2a543ea6a0fd018a24008fba514a6967c3f62cfb (diff)
feat: undead-buffers: Add `cj/make-buffer-undead` function and tests
Introduce a new function `cj/make-buffer-undead` that appends a buffer name to the `cj/undead-buffer-list`, preventing it from being killed. This comes along with a suite of tests to check various scenarios and edge cases for handling undead buffers. Additionally, add tests for related functions: `cj/kill-buffer-or-bury-alive`, `cj/kill-buffer-and-window`, and others to ensure they correctly manage buffers, particularly with undead-status considerations. Refactor `undead-buffer-list` naming for consistency and clarity in the module.
Diffstat (limited to 'tests/test-undead-buffers-kill-buffer-or-bury-alive.el')
-rw-r--r--tests/test-undead-buffers-kill-buffer-or-bury-alive.el138
1 files changed, 138 insertions, 0 deletions
diff --git a/tests/test-undead-buffers-kill-buffer-or-bury-alive.el b/tests/test-undead-buffers-kill-buffer-or-bury-alive.el
new file mode 100644
index 00000000..60b776e4
--- /dev/null
+++ b/tests/test-undead-buffers-kill-buffer-or-bury-alive.el
@@ -0,0 +1,138 @@
+;;; test-undead-buffers-kill-buffer-or-bury-alive.el --- Tests for cj/kill-buffer-or-bury-alive -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Tests for the cj/kill-buffer-or-bury-alive function from undead-buffers.el
+
+;;; Code:
+
+(require 'ert)
+(require 'undead-buffers)
+(require 'testutil-general)
+
+;;; Setup and Teardown
+
+(defun test-kill-buffer-or-bury-alive-setup ()
+ "Setup for kill-buffer-or-bury-alive tests."
+ (cj/create-test-base-dir))
+
+(defun test-kill-buffer-or-bury-alive-teardown ()
+ "Teardown for kill-buffer-or-bury-alive tests."
+ (cj/delete-test-base-dir))
+
+;;; Normal Cases
+
+(ert-deftest test-kill-buffer-or-bury-alive-regular-buffer-should-kill ()
+ "Killing a regular buffer not in undead list should kill it."
+ (test-kill-buffer-or-bury-alive-setup)
+ (unwind-protect
+ (let ((buf (generate-new-buffer "*test-regular*")))
+ (should (buffer-live-p buf))
+ (cj/kill-buffer-or-bury-alive buf)
+ (should-not (buffer-live-p buf)))
+ (test-kill-buffer-or-bury-alive-teardown)))
+
+(ert-deftest test-kill-buffer-or-bury-alive-undead-buffer-should-bury ()
+ "Killing an undead buffer should bury it instead."
+ (test-kill-buffer-or-bury-alive-setup)
+ (unwind-protect
+ (let ((orig (copy-sequence cj/undead-buffer-list))
+ (buf (generate-new-buffer "*test-undead*")))
+ (unwind-protect
+ (progn
+ (add-to-list 'cj/undead-buffer-list "*test-undead*")
+ (should (buffer-live-p buf))
+ (cj/kill-buffer-or-bury-alive buf)
+ (should (buffer-live-p buf)))
+ (setq cj/undead-buffer-list orig)
+ (when (buffer-live-p buf) (kill-buffer buf))))
+ (test-kill-buffer-or-bury-alive-teardown)))
+
+(ert-deftest test-kill-buffer-or-bury-alive-with-prefix-arg-should-add-to-undead-list ()
+ "Calling with prefix arg should add buffer to undead list."
+ (test-kill-buffer-or-bury-alive-setup)
+ (unwind-protect
+ (let ((orig (copy-sequence cj/undead-buffer-list))
+ (buf (generate-new-buffer "*test-prefix*")))
+ (unwind-protect
+ (progn
+ (with-current-buffer buf
+ (let ((current-prefix-arg '(4)))
+ (cj/kill-buffer-or-bury-alive buf)))
+ (should (member "*test-prefix*" cj/undead-buffer-list))
+ (should (buffer-live-p buf)))
+ (setq cj/undead-buffer-list orig)
+ (when (buffer-live-p buf) (kill-buffer buf))))
+ (test-kill-buffer-or-bury-alive-teardown)))
+
+(ert-deftest test-kill-buffer-or-bury-alive-scratch-buffer-should-bury ()
+ "The *scratch* buffer (in default list) should be buried."
+ (test-kill-buffer-or-bury-alive-setup)
+ (unwind-protect
+ (let ((scratch (get-buffer-create "*scratch*")))
+ (should (buffer-live-p scratch))
+ (cj/kill-buffer-or-bury-alive scratch)
+ (should (buffer-live-p scratch)))
+ (test-kill-buffer-or-bury-alive-teardown)))
+
+;;; Boundary Cases
+
+(ert-deftest test-kill-buffer-or-bury-alive-buffer-by-name-string-should-work ()
+ "Passing buffer name as string should work."
+ (test-kill-buffer-or-bury-alive-setup)
+ (unwind-protect
+ (let ((buf (generate-new-buffer "*test-string*")))
+ (should (buffer-live-p buf))
+ (cj/kill-buffer-or-bury-alive "*test-string*")
+ (should-not (buffer-live-p buf)))
+ (test-kill-buffer-or-bury-alive-teardown)))
+
+(ert-deftest test-kill-buffer-or-bury-alive-buffer-by-buffer-object-should-work ()
+ "Passing buffer object should work."
+ (test-kill-buffer-or-bury-alive-setup)
+ (unwind-protect
+ (let ((buf (generate-new-buffer "*test-object*")))
+ (should (buffer-live-p buf))
+ (cj/kill-buffer-or-bury-alive buf)
+ (should-not (buffer-live-p buf)))
+ (test-kill-buffer-or-bury-alive-teardown)))
+
+(ert-deftest test-kill-buffer-or-bury-alive-modified-undead-buffer-should-bury-without-prompt ()
+ "Modified undead buffer should be buried without save prompt."
+ (test-kill-buffer-or-bury-alive-setup)
+ (unwind-protect
+ (let ((orig (copy-sequence cj/undead-buffer-list))
+ (buf (generate-new-buffer "*test-modified*")))
+ (unwind-protect
+ (progn
+ (add-to-list 'cj/undead-buffer-list "*test-modified*")
+ (with-current-buffer buf
+ (insert "some text")
+ (set-buffer-modified-p t))
+ (cj/kill-buffer-or-bury-alive buf)
+ (should (buffer-live-p buf)))
+ (setq cj/undead-buffer-list orig)
+ (when (buffer-live-p buf)
+ (set-buffer-modified-p nil)
+ (kill-buffer buf))))
+ (test-kill-buffer-or-bury-alive-teardown)))
+
+;;; Error Cases
+
+(ert-deftest test-kill-buffer-or-bury-alive-nonexistent-buffer-should-error ()
+ "Passing a non-existent buffer name should error."
+ (test-kill-buffer-or-bury-alive-setup)
+ (unwind-protect
+ (should-error (cj/kill-buffer-or-bury-alive "*nonexistent-buffer-xyz*"))
+ (test-kill-buffer-or-bury-alive-teardown)))
+
+(ert-deftest test-kill-buffer-or-bury-alive-killed-buffer-object-should-error ()
+ "Passing a killed buffer object should error."
+ (test-kill-buffer-or-bury-alive-setup)
+ (unwind-protect
+ (let ((buf (generate-new-buffer "*test-killed*")))
+ (kill-buffer buf)
+ (should-error (cj/kill-buffer-or-bury-alive buf)))
+ (test-kill-buffer-or-bury-alive-teardown)))
+
+(provide 'test-undead-buffers-kill-buffer-or-bury-alive)
+;;; test-undead-buffers-kill-buffer-or-bury-alive.el ends here