(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)
(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)
(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"
(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 ()
'("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))
(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)
(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)))
(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-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"
(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"))
(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))