|
| 1 | +;;; copilot-overlay-tests.el --- overlay command detection tests -*- lexical-binding: t; -*- |
| 2 | + |
| 3 | +(require 'cl-lib) |
| 4 | +(require 'ert) |
| 5 | + |
| 6 | +(unless (require 'f nil 'noerror) |
| 7 | + (defun f-join (&rest segments) |
| 8 | + (let ((path (or (car segments) ""))) |
| 9 | + (dolist (segment (cdr segments) path) |
| 10 | + (setq path (expand-file-name segment path))) |
| 11 | + path)) |
| 12 | + (provide 'f)) |
| 13 | + |
| 14 | +(unless (featurep 'editorconfig) |
| 15 | + (defvar editorconfig-indentation-alist nil) |
| 16 | + (provide 'editorconfig)) |
| 17 | + |
| 18 | +(unless (featurep 'track-changes) |
| 19 | + (provide 'track-changes)) |
| 20 | + |
| 21 | +(defconst copilot-test--root |
| 22 | + (file-name-directory (directory-file-name (file-name-directory load-file-name))) |
| 23 | + "Root directory of copilot.el tests.") |
| 24 | + |
| 25 | +(load-file (expand-file-name "copilot.el" copilot-test--root)) |
| 26 | +(require 'copilot) |
| 27 | + |
| 28 | +(ert-deftest copilot-post-command-honors-key-binding-ignore () |
| 29 | + "copilot--post-command keeps the overlay when the key binding is ignored." |
| 30 | + (with-temp-buffer |
| 31 | + (let* ((copilot-clear-overlay-ignore-commands '(universal-argument-more)) |
| 32 | + (copilot-idle-delay nil) |
| 33 | + (copilot--overlay (make-overlay (point) (point))) |
| 34 | + (copilot--post-command-timer nil) |
| 35 | + (this-command 'self-insert-command) |
| 36 | + (real-this-command 'self-insert-command) |
| 37 | + (cleared nil)) |
| 38 | + (cl-letf (((symbol-function 'this-command-keys-vector) (lambda () [?])) |
| 39 | + ((symbol-function 'key-binding) (lambda (&rest _) 'universal-argument-more)) |
| 40 | + ((symbol-function 'copilot-clear-overlay) |
| 41 | + (lambda (&optional _) (setq cleared t))) |
| 42 | + ((symbol-function 'copilot--self-insert) (lambda (&rest _) nil))) |
| 43 | + (copilot--post-command) |
| 44 | + (should-not cleared))))) |
| 45 | + |
| 46 | +(ert-deftest copilot-post-command-clears-when-not-ignored () |
| 47 | + "copilot--post-command clears overlay for non-ignored prefixes." |
| 48 | + (with-temp-buffer |
| 49 | + (let* ((copilot-clear-overlay-ignore-commands nil) |
| 50 | + (copilot-idle-delay nil) |
| 51 | + (copilot--overlay (make-overlay (point) (point))) |
| 52 | + (copilot--post-command-timer nil) |
| 53 | + (this-command 'self-insert-command) |
| 54 | + (real-this-command 'self-insert-command) |
| 55 | + (cleared nil)) |
| 56 | + (cl-letf (((symbol-function 'this-command-keys-vector) (lambda () [?])) |
| 57 | + ((symbol-function 'key-binding) (lambda (&rest _) 'universal-argument-more)) |
| 58 | + ((symbol-function 'copilot-clear-overlay) |
| 59 | + (lambda (&optional _) (setq cleared t))) |
| 60 | + ((symbol-function 'copilot--self-insert) (lambda (&rest _) nil))) |
| 61 | + (copilot--post-command) |
| 62 | + (should cleared))))) |
| 63 | + |
| 64 | +(provide 'copilot-overlay-tests) |
| 65 | + |
| 66 | +;;; copilot-overlay-tests.el ends here |
0 commit comments