diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2022-09-25 16:15:16 -0400 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2022-09-25 16:15:16 -0400 |
commit | 650c20f1ca4e07591a727e1cfcc74b3363d15985 (patch) | |
tree | 85d11f6437cde22f410c25e0e5f71a3131ebd07d /test/lisp/repeat-tests.el | |
parent | 8869332684c2302b5ba1ead4568bbc7ba1c0183e (diff) | |
parent | 4b85ae6a24380fb67a3315eaec9233f17a872473 (diff) | |
download | emacs-650c20f1ca4e07591a727e1cfcc74b3363d15985.tar.gz emacs-650c20f1ca4e07591a727e1cfcc74b3363d15985.tar.bz2 emacs-650c20f1ca4e07591a727e1cfcc74b3363d15985.zip |
Merge 'master' into noverlay
Diffstat (limited to 'test/lisp/repeat-tests.el')
-rw-r--r-- | test/lisp/repeat-tests.el | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/test/lisp/repeat-tests.el b/test/lisp/repeat-tests.el new file mode 100644 index 00000000000..1382d003599 --- /dev/null +++ b/test/lisp/repeat-tests.el @@ -0,0 +1,141 @@ +;;; repeat-tests.el --- Tests for repeat.el -*- lexical-binding: t; -*- + +;; Copyright (C) 2021-2022 Free Software Foundation, Inc. + +;; Author: Juri Linkov <juri@linkov.net> + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +;;; Code: + +(require 'ert) +(require 'repeat) + +(defvar repeat-tests-calls nil) + +(defun repeat-tests-call-a (&optional arg) + (interactive "p") + (push `(,arg a) repeat-tests-calls)) + +(defun repeat-tests-call-b (&optional arg) + (interactive "p") + (push `(,arg b) repeat-tests-calls)) + +(defvar-keymap repeat-tests-map + :doc "Keymap for keys that initiate repeating sequences." + "C-x w a" 'repeat-tests-call-a + "C-M-a" 'repeat-tests-call-a + "C-M-z" 'repeat-tests-call-a) + +(defvar-keymap repeat-tests-repeat-map + :doc "Keymap for repeating sequences." + "a" 'repeat-tests-call-a + "b" 'repeat-tests-call-b) +(put 'repeat-tests-call-a 'repeat-map 'repeat-tests-repeat-map) +(put 'repeat-tests-call-b 'repeat-map repeat-tests-repeat-map) + +(defmacro with-repeat-mode (&rest body) + "Create environment for testing `repeat-mode'." + `(unwind-protect + (progn + (repeat-mode +1) + (with-temp-buffer + (save-window-excursion + ;; `execute-kbd-macro' applied to window only + (set-window-buffer nil (current-buffer)) + (use-local-map repeat-tests-map) + ,@body))) + (repeat-mode -1))) + +(defun repeat-tests--check (keys calls inserted) + (setq repeat-tests-calls nil) + (delete-region (point-min) (point-max)) + (execute-kbd-macro (kbd keys)) + (should (equal (nreverse repeat-tests-calls) calls)) + ;; Check for self-inserting keys + (should (equal (buffer-string) inserted))) + +(ert-deftest repeat-tests-check-key () + (with-repeat-mode + (let ((repeat-echo-function 'ignore)) + (let ((repeat-check-key t)) + (repeat-tests--check + "C-x w a b a c" + '((1 a) (1 b) (1 a)) "c") + (repeat-tests--check + "M-C-a b a c" + '((1 a) (1 b) (1 a)) "c") + (repeat-tests--check + "M-C-z b a c" + '((1 a)) "bac") + (unwind-protect + (progn + (put 'repeat-tests-call-a 'repeat-check-key 'no) + (repeat-tests--check + "M-C-z b a c" + '((1 a) (1 b) (1 a)) "c")) + (put 'repeat-tests-call-a 'repeat-check-key nil))) + (let ((repeat-check-key nil)) + (repeat-tests--check + "M-C-z b a c" + '((1 a) (1 b) (1 a)) "c") + (unwind-protect + (progn + (put 'repeat-tests-call-a 'repeat-check-key t) + (repeat-tests--check + "M-C-z b a c" + '((1 a)) "bac")) + (put 'repeat-tests-call-a 'repeat-check-key nil)))))) + +(ert-deftest repeat-tests-exit-key () + (with-repeat-mode + (let ((repeat-echo-function 'ignore)) + (let ((repeat-exit-key nil)) + (repeat-tests--check + "C-x w a b a b RET c" + '((1 a) (1 b) (1 a) (1 b)) "\nc")) + (let ((repeat-exit-key [return])) + (repeat-tests--check + "C-x w a b a b <return> c" + '((1 a) (1 b) (1 a) (1 b)) "c"))))) + +(ert-deftest repeat-tests-keep-prefix () + (with-repeat-mode + (let ((repeat-echo-function 'ignore)) + (repeat-tests--check + "C-x w a b a b c" + '((1 a) (1 b) (1 a) (1 b)) "c") + (let ((repeat-keep-prefix nil)) + (repeat-tests--check + "C-2 C-x w a b a b c" + '((2 a) (1 b) (1 a) (1 b)) "c") + (repeat-tests--check + "C-2 C-x w a C-3 c" + '((2 a)) "ccc")) + ;; TODO: fix and uncomment + ;; (let ((repeat-keep-prefix t)) + ;; (repeat-tests--check + ;; "C-2 C-x w a b a b c" + ;; '((2 a) (2 b) (2 a) (2 b)) "c") + ;; (repeat-tests--check + ;; "C-2 C-x w a C-1 C-2 b a C-3 C-4 b c" + ;; '((2 a) (12 b) (12 a) (34 b)) "c")) + ))) + +;; TODO: :tags '(:expensive-test) for repeat-exit-timeout + +(provide 'repeat-tests) +;;; repeat-tests.el ends here |