diff options
| author | Simen Heggestøyl | 2019-05-31 19:06:37 +0200 |
|---|---|---|
| committer | Simen Heggestøyl | 2019-05-31 19:07:48 +0200 |
| commit | 12f530a7358aefe32134eeec3bc20ce58305e473 (patch) | |
| tree | 3363e6aff6de9e9f347a2ffa9be6c14dc439b716 /test | |
| parent | c3748b13765a193fcff7f75b9d1ba99b24fa3509 (diff) | |
| download | emacs-12f530a7358aefe32134eeec3bc20ce58305e473.tar.gz emacs-12f530a7358aefe32134eeec3bc20ce58305e473.zip | |
Use lexical-binding in autoinsert.el and add tests
* lisp/autoinsert.el: Use lexical-binding.
Remove redundant :group args.
(auto-insert): Simplify.
* test/lisp/autoinsert-tests.el: New file with tests for
autoinsert.el.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/autoinsert-tests.el | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/test/lisp/autoinsert-tests.el b/test/lisp/autoinsert-tests.el new file mode 100644 index 00000000000..a7b0547633b --- /dev/null +++ b/test/lisp/autoinsert-tests.el | |||
| @@ -0,0 +1,104 @@ | |||
| 1 | ;;; autoinsert-tests.el --- Tests for autoinsert.el -*- lexical-binding: t; -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2019 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Simen Heggestøyl <simenheg@gmail.com> | ||
| 6 | ;; Keywords: | ||
| 7 | |||
| 8 | ;; This file is part of GNU Emacs. | ||
| 9 | |||
| 10 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 11 | ;; it under the terms of the GNU General Public License as published by | ||
| 12 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 13 | ;; (at your option) any later version. | ||
| 14 | |||
| 15 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 18 | ;; GNU General Public License for more details. | ||
| 19 | |||
| 20 | ;; You should have received a copy of the GNU General Public License | ||
| 21 | ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. | ||
| 22 | |||
| 23 | ;;; Commentary: | ||
| 24 | |||
| 25 | ;; | ||
| 26 | |||
| 27 | ;;; Code: | ||
| 28 | |||
| 29 | (require 'autoinsert) | ||
| 30 | (require 'ert) | ||
| 31 | |||
| 32 | (ert-deftest autoinsert-tests-auto-insert-skeleton () | ||
| 33 | (let ((auto-insert-alist '((text-mode nil "f" _ "oo"))) | ||
| 34 | (auto-insert-query nil)) | ||
| 35 | (with-temp-buffer | ||
| 36 | (text-mode) | ||
| 37 | (auto-insert) | ||
| 38 | (should (equal (buffer-string) "foo")) | ||
| 39 | (should (equal (point) (+ (point-min) 1)))))) | ||
| 40 | |||
| 41 | (ert-deftest autoinsert-tests-auto-insert-file () | ||
| 42 | (let ((temp-file (make-temp-file "autoinsert-tests" nil nil "foo"))) | ||
| 43 | (unwind-protect | ||
| 44 | (let ((auto-insert-alist `((text-mode . ,temp-file))) | ||
| 45 | (auto-insert-query nil)) | ||
| 46 | (with-temp-buffer | ||
| 47 | (text-mode) | ||
| 48 | (auto-insert) | ||
| 49 | (should (equal (buffer-string) "foo")))) | ||
| 50 | (when (file-exists-p temp-file) | ||
| 51 | (delete-file temp-file))))) | ||
| 52 | |||
| 53 | (ert-deftest autoinsert-tests-auto-insert-function () | ||
| 54 | (let ((auto-insert-alist '((text-mode . (lambda () (insert "foo"))))) | ||
| 55 | (auto-insert-query nil)) | ||
| 56 | (with-temp-buffer | ||
| 57 | (text-mode) | ||
| 58 | (auto-insert) | ||
| 59 | (should (equal (buffer-string) "foo"))))) | ||
| 60 | |||
| 61 | (ert-deftest autoinsert-tests-auto-insert-vector () | ||
| 62 | (let ((auto-insert-alist '((text-mode . [(nil "f" _ "bar") | ||
| 63 | (lambda () (insert "oo"))]))) | ||
| 64 | (auto-insert-query nil)) | ||
| 65 | (with-temp-buffer | ||
| 66 | (text-mode) | ||
| 67 | (auto-insert) | ||
| 68 | (should (equal (buffer-string) "foobar"))))) | ||
| 69 | |||
| 70 | (ert-deftest autoinsert-tests-auto-insert-regexp-match () | ||
| 71 | (let ((auto-insert-alist '(("foobar" nil "1st") | ||
| 72 | ("fo+bar" nil "2nd") | ||
| 73 | ("fo*bar" nil "3rd"))) | ||
| 74 | (auto-insert-query nil)) | ||
| 75 | (with-temp-buffer | ||
| 76 | (setq-local buffer-file-name "fooobar") | ||
| 77 | (auto-insert) | ||
| 78 | (should (equal (buffer-string) "2nd"))))) | ||
| 79 | |||
| 80 | (ert-deftest autoinsert-tests-define-auto-insert-before () | ||
| 81 | (let ((auto-insert-alist | ||
| 82 | (list (cons 'text-mode '(lambda () (insert "foo"))))) | ||
| 83 | (auto-insert-query nil)) | ||
| 84 | (define-auto-insert 'text-mode | ||
| 85 | '(lambda () (insert "bar"))) | ||
| 86 | (with-temp-buffer | ||
| 87 | (text-mode) | ||
| 88 | (auto-insert) | ||
| 89 | (should (equal (buffer-string) "barfoo"))))) | ||
| 90 | |||
| 91 | (ert-deftest autoinsert-tests-define-auto-insert-after () | ||
| 92 | (let ((auto-insert-alist | ||
| 93 | (list (cons 'text-mode '(lambda () (insert "foo"))))) | ||
| 94 | (auto-insert-query nil)) | ||
| 95 | (define-auto-insert 'text-mode | ||
| 96 | '(lambda () (insert "bar")) | ||
| 97 | t) | ||
| 98 | (with-temp-buffer | ||
| 99 | (text-mode) | ||
| 100 | (auto-insert) | ||
| 101 | (should (equal (buffer-string) "foobar"))))) | ||
| 102 | |||
| 103 | (provide 'autoinsert-tests) | ||
| 104 | ;;; autoinsert-tests.el ends here | ||