diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/emacs-lisp/lisp-mode-tests.el | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/lisp-mode-tests.el b/test/lisp/emacs-lisp/lisp-mode-tests.el new file mode 100644 index 00000000000..2801f23df63 --- /dev/null +++ b/test/lisp/emacs-lisp/lisp-mode-tests.el | |||
| @@ -0,0 +1,94 @@ | |||
| 1 | ;;; lisp-mode-tests.el --- Test Lisp editing commands -*- lexical-binding: t; -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2017 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 6 | ;; it under the terms of the GNU General Public License as published by | ||
| 7 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 8 | ;; (at your option) any later version. | ||
| 9 | |||
| 10 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 11 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | ;; GNU General Public License for more details. | ||
| 14 | |||
| 15 | ;; You should have received a copy of the GNU General Public License | ||
| 16 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | ||
| 17 | |||
| 18 | ;;; Code: | ||
| 19 | |||
| 20 | (require 'ert) | ||
| 21 | (require 'cl-lib) | ||
| 22 | (require 'lisp-mode) | ||
| 23 | |||
| 24 | (ert-deftest indent-sexp () | ||
| 25 | "Test basics of \\[indent-sexp]." | ||
| 26 | (with-temp-buffer | ||
| 27 | (insert "\ | ||
| 28 | \(a | ||
| 29 | (prog1 | ||
| 30 | (prog1 | ||
| 31 | 1 | ||
| 32 | 2) | ||
| 33 | 2) | ||
| 34 | (1 | ||
| 35 | \"string | ||
| 36 | noindent\" (\"string2 | ||
| 37 | noindent\" 3 | ||
| 38 | 4) | ||
| 39 | 2) ; comment | ||
| 40 | ;; comment | ||
| 41 | b)") | ||
| 42 | (goto-char (point-min)) | ||
| 43 | (let ((indent-tabs-mode nil) | ||
| 44 | (correct (buffer-string))) | ||
| 45 | (dolist (mode '(fundamental-mode emacs-lisp-mode)) | ||
| 46 | (funcall mode) | ||
| 47 | (indent-sexp) | ||
| 48 | ;; Don't mess up correctly indented code. | ||
| 49 | (should (string= (buffer-string) correct)) | ||
| 50 | ;; Correctly add indentation. | ||
| 51 | (save-excursion | ||
| 52 | (while (not (eobp)) | ||
| 53 | (delete-horizontal-space) | ||
| 54 | (forward-line))) | ||
| 55 | (indent-sexp) | ||
| 56 | (should (equal (buffer-string) correct)) | ||
| 57 | ;; Correctly remove indentation. | ||
| 58 | (save-excursion | ||
| 59 | (let ((n 0)) | ||
| 60 | (while (not (eobp)) | ||
| 61 | (unless (looking-at "noindent") | ||
| 62 | (insert (make-string n ?\s))) | ||
| 63 | (cl-incf n) | ||
| 64 | (forward-line)))) | ||
| 65 | (indent-sexp) | ||
| 66 | (should (equal (buffer-string) correct)))))) | ||
| 67 | |||
| 68 | (ert-deftest indent-subsexp () | ||
| 69 | "Make sure calling `indent-sexp' inside a sexp works." | ||
| 70 | (with-temp-buffer | ||
| 71 | (insert "\ | ||
| 72 | \(d1 xx | ||
| 73 | (d2 yy | ||
| 74 | zz) | ||
| 75 | 11)") | ||
| 76 | (let ((correct (buffer-string))) | ||
| 77 | (search-backward "d2") | ||
| 78 | (up-list -1) | ||
| 79 | (indent-sexp) | ||
| 80 | (should (equal (buffer-string) correct))))) | ||
| 81 | |||
| 82 | (ert-deftest indent-sexp-in-string () | ||
| 83 | "Make sure calling `indent-sexp' inside a string works." | ||
| 84 | ;; See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=21343. | ||
| 85 | (with-temp-buffer | ||
| 86 | (emacs-lisp-mode) | ||
| 87 | (insert "\";\"") | ||
| 88 | (let ((correct (buffer-string))) | ||
| 89 | (search-backward ";") | ||
| 90 | (indent-sexp) | ||
| 91 | (should (equal (buffer-string) correct))))) | ||
| 92 | |||
| 93 | (provide 'lisp-mode-tests) | ||
| 94 | ;;; lisp-mode-tests.el ends here | ||