aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorNoam Postavsky2017-03-05 00:16:13 -0500
committerNoam Postavsky2017-03-12 20:08:32 -0400
commit3ee3995d105ff02f0fac540757431d36cb45c6c7 (patch)
tree2ef4b94411b15cc051d264990a2a4ba441be86db /test
parent1b424533675341a2090b79a6ffc420ac6b179ce7 (diff)
downloademacs-3ee3995d105ff02f0fac540757431d36cb45c6c7.tar.gz
emacs-3ee3995d105ff02f0fac540757431d36cb45c6c7.zip
* lisp/emacs-lisp/lisp-mode.el (indent-sexp): Simplify.
* test/lisp/emacs-lisp/lisp-mode-tests.el (indent-sexp): (indent-subsexp, indent-sexp-in-string): New tests.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/emacs-lisp/lisp-mode-tests.el94
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
36noindent\" (\"string2
37noindent\" 3
384)
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