summaryrefslogtreecommitdiff
path: root/test/lisp/emacs-lisp
diff options
context:
space:
mode:
authorRichard Hansen <rhansen@rhansen.org>2022-12-17 18:51:33 -0500
committerEli Zaretskii <eliz@gnu.org>2022-12-24 09:14:23 +0200
commit286c48137f69fa96b80d197da90c69a42df604a3 (patch)
tree424c7049a3b32a421b755230d40d3a0d19424f01 /test/lisp/emacs-lisp
parent823c49cea851158bc4db5ab133ecd9bf3d0791d7 (diff)
downloademacs-286c48137f69fa96b80d197da90c69a42df604a3.tar.gz
emacs-286c48137f69fa96b80d197da90c69a42df604a3.tar.bz2
emacs-286c48137f69fa96b80d197da90c69a42df604a3.zip
ert-x: Move window selection logic to its own macro
* lisp/emacs-lisp/ert-x.el (ert-with-buffer-selected): New macro to temporarily display a buffer in a selected window and evaluate a body. (ert-with-test-buffer-selected): Use the new macro. * test/lisp/whitespace-tests.el (ert-test-with-buffer-selected/current) (ert-test-with-buffer-selected/selected) (ert-test-with-buffer-selected/nil-buffer) (ert-test-with-buffer-selected/modification-hooks) (ert-test-with-buffer-selected/read-only) (ert-test-with-buffer-selected/return-value): Add tests. (Bug#60189)
Diffstat (limited to 'test/lisp/emacs-lisp')
-rw-r--r--test/lisp/emacs-lisp/ert-x-tests.el34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/ert-x-tests.el b/test/lisp/emacs-lisp/ert-x-tests.el
index f14d54cd9f7..1cfd218592a 100644
--- a/test/lisp/emacs-lisp/ert-x-tests.el
+++ b/test/lisp/emacs-lisp/ert-x-tests.el
@@ -82,6 +82,40 @@
(should-not (buffer-live-p buffer-1))
(should (buffer-live-p buffer-2))))))
+(ert-deftest ert-test-with-buffer-selected/current ()
+ (let ((origbuf (current-buffer)))
+ (ert-with-test-buffer ()
+ (let ((buf (current-buffer)))
+ (should (not (eq buf origbuf)))
+ (with-current-buffer origbuf
+ (ert-with-buffer-selected buf
+ (should (eq (current-buffer) buf))))))))
+
+(ert-deftest ert-test-with-buffer-selected/selected ()
+ (ert-with-test-buffer ()
+ (ert-with-buffer-selected (current-buffer)
+ (should (eq (window-buffer) (current-buffer))))))
+
+(ert-deftest ert-test-with-buffer-selected/nil-buffer ()
+ (ert-with-test-buffer ()
+ (let ((buf (current-buffer)))
+ (ert-with-buffer-selected nil
+ (should (eq (window-buffer) buf))))))
+
+(ert-deftest ert-test-with-buffer-selected/modification-hooks ()
+ (ert-with-test-buffer ()
+ (ert-with-buffer-selected (current-buffer)
+ (should (null inhibit-modification-hooks)))))
+
+(ert-deftest ert-test-with-buffer-selected/read-only ()
+ (ert-with-test-buffer ()
+ (ert-with-buffer-selected (current-buffer)
+ (should (null inhibit-read-only))
+ (should (null buffer-read-only)))))
+
+(ert-deftest ert-test-with-buffer-selected/return-value ()
+ (should (equal (ert-with-buffer-selected nil "foo") "foo")))
+
(ert-deftest ert-test-with-test-buffer-selected/selected ()
(ert-with-test-buffer-selected ()
(should (eq (window-buffer) (current-buffer)))))