]> git.eshelyaron.com Git - emacs.git/commitdiff
; completion-preview-tests.el: Deduplicate some test code
authorEshel Yaron <me@eshelyaron.com>
Mon, 24 Jun 2024 14:58:49 +0000 (16:58 +0200)
committerEshel Yaron <me@eshelyaron.com>
Mon, 24 Jun 2024 14:58:49 +0000 (16:58 +0200)
* test/lisp/completion-preview-tests.el
(completion-preview-tests--insert-and-preview): New function.
(completion-preview)
(completion-preview-multiple-matches)
(completion-preview-exact-match-only)
(completion-preview-function-capfs)
(completion-preview-non-exclusive-capfs)
(completion-preview-face-updates)
(completion-preview-capf-errors)
(completion-preview-complete)
(completion-preview-insert-calls-exit-function): Use it.

test/lisp/completion-preview-tests.el

index 5d1c09e95509c968a75f9c29cc60a30b9d306baf..b57d57ef79af8693b73f24045cc88d2dc5518e63 100644 (file)
@@ -48,24 +48,26 @@ instead."
                   (or end-face
                     'completion-preview))))))
 
+(defun completion-preview-tests--insert-and-preview (string)
+  "Insert STRING and update the completion preview."
+  (insert string)
+  (let ((this-command 'self-insert-command))
+    (completion-preview--post-command)))
+
 (ert-deftest completion-preview ()
   "Test Completion Preview mode."
   (with-temp-buffer
     (setq-local completion-at-point-functions
                 (list (completion-preview-tests--capf '("foobarbaz"))))
 
-    (insert "foo")
-    (let ((this-command 'self-insert-command))
-      (completion-preview--post-command))
+    (completion-preview-tests--insert-and-preview "foo")
 
     ;; Exact match
     (completion-preview-tests--check-preview "barbaz"
                                              'completion-preview-exact
                                              'completion-preview-exact)
 
-    (insert "v")
-    (let ((this-command 'self-insert-command))
-      (completion-preview--post-command))
+    (completion-preview-tests--insert-and-preview "v")
 
     ;; No match, no preview
     (completion-preview-tests--check-preview nil)
@@ -85,9 +87,7 @@ instead."
     (setq-local completion-at-point-functions
                 (list (completion-preview-tests--capf
                        '("foobar" "foobaz"))))
-    (insert "foo")
-    (let ((this-command 'self-insert-command))
-      (completion-preview--post-command))
+    (completion-preview-tests--insert-and-preview "foo")
 
     ;; Multiple matches, the preview shows the first one
     (completion-preview-tests--check-preview "bar" 'completion-preview-common)
@@ -104,17 +104,13 @@ instead."
                 (list (completion-preview-tests--capf
                        '("spam" "foobar" "foobaz")))
                 completion-preview-exact-match-only t)
-    (insert "foo")
-    (let ((this-command 'self-insert-command))
-      (completion-preview--post-command))
+    (completion-preview-tests--insert-and-preview "foo")
 
     ;; Multiple matches, so no preview
     (completion-preview-tests--check-preview nil)
 
     (delete-region (point-min) (point-max))
-    (insert "spa")
-    (let ((this-command 'self-insert-command))
-      (completion-preview--post-command))
+    (completion-preview-tests--insert-and-preview "spa")
 
     ;; Exact match
     (completion-preview-tests--check-preview "m"
@@ -129,9 +125,7 @@ instead."
                  (lambda () #'ignore)
                  (completion-preview-tests--capf
                   '("foobar" "foobaz"))))
-    (insert "foo")
-    (let ((this-command 'self-insert-command))
-      (completion-preview--post-command))
+    (completion-preview-tests--insert-and-preview "foo")
     (completion-preview-tests--check-preview "bar" 'completion-preview-common)))
 
 (ert-deftest completion-preview-non-exclusive-capfs ()
@@ -145,9 +139,7 @@ instead."
                   '("foobar" "foobaz") :exclusive 'no)
                  (completion-preview-tests--capf
                   '("foobarbaz"))))
-    (insert "foo")
-    (let ((this-command 'self-insert-command))
-      (completion-preview--post-command))
+    (completion-preview-tests--insert-and-preview "foo")
     (completion-preview-tests--check-preview "bar" 'completion-preview-common)
     (setq-local completion-preview-exact-match-only t)
     (let ((this-command 'self-insert-command))
@@ -163,13 +155,9 @@ instead."
                 (list
                  (completion-preview-tests--capf
                   '("foobarbaz" "food"))))
-    (insert "foo")
-    (let ((this-command 'self-insert-command))
-      (completion-preview--post-command))
+    (completion-preview-tests--insert-and-preview "foo")
     (completion-preview-tests--check-preview "d")
-    (insert "b")
-    (let ((this-command 'self-insert-command))
-      (completion-preview--post-command))
+    (completion-preview-tests--insert-and-preview "b")
     (completion-preview-tests--check-preview "arbaz"
                                              'completion-preview-exact
                                              'completion-preview-exact)
@@ -188,9 +176,7 @@ instead."
                  (lambda () (user-error "Bad"))
                  (completion-preview-tests--capf
                   '("foobarbaz"))))
-    (insert "foo")
-    (let ((this-command 'self-insert-command))
-      (completion-preview--post-command))
+    (completion-preview-tests--insert-and-preview "foo")
     (completion-preview-tests--check-preview "barbaz"
                                              'completion-preview-exact
                                              'completion-preview-exact)))
@@ -225,9 +211,7 @@ instead."
                     (lambda (&rest args)
                       (setq exit-fn-called t
                             exit-fn-args args)))))
-      (insert "foo")
-      (let ((this-command 'self-insert-command))
-        (completion-preview--post-command))
+      (completion-preview-tests--insert-and-preview "foo")
 
       (completion-preview-tests--check-preview "bar" 'completion-preview-common)
 
@@ -252,9 +236,7 @@ instead."
       ;; (completion-preview-active-mode -1)
 
       ;; Narrow further.
-      (insert "s")
-      (let ((this-command 'self-insert-command))
-        (completion-preview--post-command))
+      (completion-preview-tests--insert-and-preview "s")
 
       ;; The preview should indicate an exact match.
       (completion-preview-tests--check-preview "h"
@@ -296,9 +278,7 @@ instead."
                     (lambda (&rest args)
                       (setq exit-fn-called t
                             exit-fn-args args)))))
-      (insert "foo")
-      (let ((this-command 'self-insert-command))
-        (completion-preview--post-command))
+      (completion-preview-tests--insert-and-preview "foo")
       (completion-preview-tests--check-preview "bar" 'completion-preview-common)
       (completion-preview-insert)
       (should (string= (buffer-string) "foobar"))
@@ -313,9 +293,7 @@ instead."
                 (list
                  (completion-preview-tests--capf
                   '("foobar" "foobaz"))))
-    (insert "foo")
-    (let ((this-command 'self-insert-command))
-      (completion-preview--post-command))
+    (completion-preview-tests--insert-and-preview "foo")
     (should (eq completion-preview-cursor-type
                 (window-cursor-type nil)))
     (should (completion-preview--cursor-modified-p))