emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Test 'command-completion-using-modes-p' (bug#50228)


From: Johannes Maier
Subject: [PATCH] Test 'command-completion-using-modes-p' (bug#50228)
Date: Sat, 28 Aug 2021 22:51:48 +0200

After discovering bug#50228 and asking about tests Lars Ingebrigtsen
replied that "there really should be tests in this area".  I tried
writing some, but these are my first steps with ERT, and Emacs' codebase
in general, so I'm still having a couple of questions:

* There are two assertions in each of the two tests, one positive and
  one negative.  Do you prefer one `ert-deftest' per scenario/branch (or
  even a single one for all cases)?

* The pattern "call with-temp-buffer, maybe enable a mode, then check
  whether a command is applicable" repeats itself.  Is creating small
  helper functions/macros generally advised for such small tests?

There are some more branches/cases that could be tested (maybe the
conditions for multiple modes warrant a test for
`command-completion-with-modes-p' instead), but I feel like I need to
get a better grasp of Elisp and the codebase beforehand, and answers to
these questions would be a first step.

TIA,
Johannes

>From 0f0acc143f4f3c80baf73b01290c6b64b9cccedf Mon Sep 17 00:00:00 2001
From: Johannes Maier <johannes.maier@mailbox.org>
Date: Sat, 28 Aug 2021 22:29:31 +0200
Subject: [PATCH] Add tests for 'command-completion-using-modes-p' (bug#50228)

* test/lisp/simple-tests.el: Add tests for
'command-completion-using-modes-p'.
---
 test/lisp/simple-tests.el | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el
index 3ece61290b..7dd3e3dd83 100644
--- a/test/lisp/simple-tests.el
+++ b/test/lisp/simple-tests.el
@@ -971,5 +971,34 @@ test-undo-region
     ;;(should (= (length (delq nil (undo-make-selective-list 5 9))) 0))
     (should (= (length (delq nil (undo-make-selective-list 6 9))) 0))))
 
+(ert-deftest command-completion-using-modes-p-single-major-mode ()
+  "A command that is applicable for one major mode only should be
+filtered out by `command-completion-using-modes-p' if that
+mode (or a derivation thereof) is not active, and accepted
+otherwise."
+  (cl-flet ((cmd (lambda ()
+                   (interactive nil emacs-lisp-mode))))
+    (with-temp-buffer
+      (let ((included (command-completion-using-modes-p #'cmd 
(current-buffer))))
+        (should-not included)))
+    (with-temp-buffer
+      (emacs-lisp-mode)
+      (let ((included (command-completion-using-modes-p #'cmd 
(current-buffer))))
+        (should included)))))
+
+(ert-deftest command-completion-using-modes-p-multiple-modes ()
+  "A command that is applicable for more than one mode should be
+filtered out by `command-completion-using-modes-p' if none of the
+modes are active, and accepted otherwise.  See bug#50228."
+  (cl-flet ((cmd (lambda ()
+                   (interactive nil emacs-lisp-mode line-number-mode))))
+    (with-temp-buffer
+      (let ((included (command-completion-using-modes-p #'cmd 
(current-buffer))))
+        (should-not included)))
+    (with-temp-buffer
+      (line-number-mode)
+      (let ((included (command-completion-using-modes-p #'cmd 
(current-buffer))))
+        (should included)))))
+
 (provide 'simple-test)
 ;;; simple-test.el ends here
-- 
2.32.0


reply via email to

[Prev in Thread] Current Thread [Next in Thread]