1 ;;; lisp-tests.el --- Test Lisp editing commands -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2013-2016 Free Software Foundation, Inc.
5 ;; Author: Aaron S. Hawley <aaron.s.hawley@gmail.com>
8 ;; GNU Emacs is free software: you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;; Testing of `forward-sexp' and related functions.
30 (ert-deftest lisp-forward-sexp-1-empty-parens ()
31 "Test basics of \\[forward-sexp]."
34 (goto-char (point-min))
38 (ert-deftest lisp-forward-sexp-1-error-mismatch ()
39 "Test basics of \\[forward-sexp]."
42 (goto-char (point-min))
46 (ert-deftest lisp-backward-sexp-1-empty-parens ()
47 "Test basics of \\[backward-sexp]."
53 (ert-deftest lisp-backward-sexp-1-error-mismatch ()
54 "Test mismatched parens with \\[backward-sexp]."
60 (ert-deftest lisp-forward-sexp-1-eobp ()
61 "Test \\[forward-sexp] at `eobp'."
64 (should (null ;; (should-error ;; No, per #13994
67 (ert-deftest lisp-backward-sexp-1-eobp ()
68 "Test \\[backward-sexp] at `bobp'."
71 (goto-char (point-min))
72 (should (null ;; (should-error ;; No, per #13994
75 (ert-deftest lisp-forward-sexp-2-eobp ()
76 "Test \\[forward-sexp] beyond `eobp'."
79 (goto-char (point-min))
80 (should (null ;; (should-error ;; No, per #13994
84 (ert-deftest lisp-backward-sexp-2-bobp ()
85 "Test \\[backward-sexp] beyond `bobp'."
88 (should (null ;; (should-error ;; No, per #13994
92 (ert-deftest lisp-forward-sexp-2-eobp-and-subsequent ()
93 "Test \\[forward-sexp] beyond `eobp' and again."
96 (goto-char (point-min))
97 (should (null ;; (should-error ;; No, per #13994
100 (should (null ;; (should-error ;; No, per #13994
103 (ert-deftest lisp-backward-sexp-2-bobp-and-subsequent ()
104 "Test \\[backward-sexp] ahead of `bobp' and again."
107 (should (null ;; (should-error ;; No, per #13994
110 (should (null ;; (should-error ;; No, per #13994
111 (forward-sexp -1)))))
113 (ert-deftest lisp-delete-pair-parens ()
114 "Test \\[delete-pair] with parens."
117 (goto-char (point-min))
119 (should (string-equal "foo" (buffer-string)))))
121 (ert-deftest lisp-delete-pair-quotation-marks ()
122 "Test \\[delete-pair] with quotation marks."
125 (goto-char (point-min))
127 (should (string-equal "foo" (buffer-string)))))
129 (ert-deftest lisp-delete-pair-quotes-in-text-mode ()
130 "Test \\[delete-pair] against string in Text Mode for #15014."
134 (goto-char (point-min))
136 (should (string-equal "fo\"" (buffer-string)))))
138 (ert-deftest lisp-delete-pair-quotes-text-mode-syntax-table ()
139 "Test \\[delete-pair] with modified Text Mode syntax for #15014."
142 (let ((st (copy-syntax-table text-mode-syntax-table)))
143 (with-syntax-table st
144 ;; (modify-syntax-entry ?\" "." text-mode-syntax-table)
145 (modify-syntax-entry ?\" "$" st)
147 (goto-char (point-min))
149 (should (string-equal "foo" (buffer-string)))))))
151 (ert-deftest lisp-forward-sexp-elisp-inside-symbol ()
152 "Test \\[forward-sexp] on symbol in Emacs Lisp Mode for #20492."
155 (insert "hide-ifdef-env ")
156 (insert (concat (number-sequence 32 126)))
157 (goto-char (point-min))
158 (re-search-forward "hide" nil t) ;; (forward-char 4)
159 (should (looking-at "-"))
161 (should (looking-at " "))))
163 (ert-deftest lisp-forward-sexp-elisp-quoted-symbol ()
164 "Test \\[forward-sexp] on symbol in Emacs Lisp Mode for #20492."
167 (insert "`hide-ifdef-env'.")
168 (goto-char (point-min))
169 (re-search-forward "hide" nil t) ;; (forward-char 5)
170 (should (= ?- (char-after)))
172 (should (= ?. (char-before)))))
174 (ert-deftest lisp-forward-sexp-python-triple-quoted-string ()
175 "Test \\[forward-sexp] on Python doc strings for #11321."
177 (insert "\"\"\"Triple-quoted string\"\"\"")
178 (goto-char (point-min))
179 (let ((python-indent-guess-indent-offset nil))
184 (ert-deftest lisp-forward-sexp-python-triple-quotes-string ()
185 "Test \\[forward-sexp] on Python doc strings for #11321."
187 (insert "'''Triple-quoted string'''")
188 (goto-char (point-min))
189 (let ((python-indent-guess-indent-offset nil))
194 (ert-deftest lisp-forward-sexp-emacs-lisp-semi-char-error ()
195 "Test \\[forward-sexp] on expression with unquoted semicolon per #4030."
198 (insert "(insert ?;)")
199 (goto-char (point-min))
200 (should-error (forward-sexp)))) ;; FIXME: Shouldn't be an error.
202 (ert-deftest lisp-forward-sexp-emacs-lisp-quote-char ()
203 "Test \\[forward-sexp] on expression with unquoted quote per #4030."
206 (insert "(insert ?\")")
207 (goto-char (point-min))
208 (should-error (forward-sexp)))) ;; FIXME: Shouldn't be an error.
210 (provide 'lisp-tests)
211 ;;; lisp-tests.el ends here