diff options
| author | Aaron S. Hawley | 2016-02-26 16:18:58 +1030 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2016-02-26 16:18:58 +1030 |
| commit | 22994735af588be9c2d6d438155b73328aaa0cf3 (patch) | |
| tree | df224335ab4c17525dbe768e51deeedae9fb22c3 | |
| parent | 10b040814eaf72775c26ff3df9aa3719798e6429 (diff) | |
| download | emacs-22994735af588be9c2d6d438155b73328aaa0cf3.tar.gz emacs-22994735af588be9c2d6d438155b73328aaa0cf3.zip | |
Add forward-sexp (and related) tests
* test/lisp/emacs-lisp/lisp-tests.el: New file for testing
forward-sexp and related functions (bug#22800).
| -rw-r--r-- | test/lisp/emacs-lisp/lisp-tests.el | 211 |
1 files changed, 211 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/lisp-tests.el b/test/lisp/emacs-lisp/lisp-tests.el new file mode 100644 index 00000000000..4fe20f06e9d --- /dev/null +++ b/test/lisp/emacs-lisp/lisp-tests.el | |||
| @@ -0,0 +1,211 @@ | |||
| 1 | ;;; lisp-tests.el --- Test Lisp editing commands -*- lexical-binding: t; -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2013-2016 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Aaron S. Hawley <aaron.s.hawley@gmail.com> | ||
| 6 | ;; Keywords: internal | ||
| 7 | |||
| 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. | ||
| 12 | |||
| 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. | ||
| 17 | |||
| 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/>. | ||
| 20 | |||
| 21 | ;;; Commentary: | ||
| 22 | |||
| 23 | ;; Testing of `forward-sexp' and related functions. | ||
| 24 | |||
| 25 | ;;; Code: | ||
| 26 | |||
| 27 | (require 'ert) | ||
| 28 | (require 'python) | ||
| 29 | |||
| 30 | (ert-deftest lisp-forward-sexp-1-empty-parens () | ||
| 31 | "Test basics of \\[forward-sexp]." | ||
| 32 | (with-temp-buffer | ||
| 33 | (insert "()") | ||
| 34 | (goto-char (point-min)) | ||
| 35 | (should (null | ||
| 36 | (forward-sexp 1))))) | ||
| 37 | |||
| 38 | (ert-deftest lisp-forward-sexp-1-error-mismatch () | ||
| 39 | "Test basics of \\[forward-sexp]." | ||
| 40 | (with-temp-buffer | ||
| 41 | (insert "(") | ||
| 42 | (goto-char (point-min)) | ||
| 43 | (should-error | ||
| 44 | (forward-sexp 1)))) | ||
| 45 | |||
| 46 | (ert-deftest lisp-backward-sexp-1-empty-parens () | ||
| 47 | "Test basics of \\[backward-sexp]." | ||
| 48 | (with-temp-buffer | ||
| 49 | (insert "()") | ||
| 50 | (should (null | ||
| 51 | (forward-sexp -1))))) | ||
| 52 | |||
| 53 | (ert-deftest lisp-backward-sexp-1-error-mismatch () | ||
| 54 | "Test mismatched parens with \\[backward-sexp]." | ||
| 55 | (with-temp-buffer | ||
| 56 | (insert "(") | ||
| 57 | (should-error | ||
| 58 | (forward-sexp -1)))) | ||
| 59 | |||
| 60 | (ert-deftest lisp-forward-sexp-1-eobp () | ||
| 61 | "Test \\[forward-sexp] at `eobp'." | ||
| 62 | (with-temp-buffer | ||
| 63 | (insert "()") | ||
| 64 | (should (null ;; (should-error ;; No, per #13994 | ||
| 65 | (forward-sexp 1))))) | ||
| 66 | |||
| 67 | (ert-deftest lisp-backward-sexp-1-eobp () | ||
| 68 | "Test \\[backward-sexp] at `bobp'." | ||
| 69 | (with-temp-buffer | ||
| 70 | (insert "()") | ||
| 71 | (goto-char (point-min)) | ||
| 72 | (should (null ;; (should-error ;; No, per #13994 | ||
| 73 | (forward-sexp -1))))) | ||
| 74 | |||
| 75 | (ert-deftest lisp-forward-sexp-2-eobp () | ||
| 76 | "Test \\[forward-sexp] beyond `eobp'." | ||
| 77 | (with-temp-buffer | ||
| 78 | (insert "()") | ||
| 79 | (goto-char (point-min)) | ||
| 80 | (should (null ;; (should-error ;; No, per #13994 | ||
| 81 | (forward-sexp 2))) | ||
| 82 | (should (eobp)))) | ||
| 83 | |||
| 84 | (ert-deftest lisp-backward-sexp-2-bobp () | ||
| 85 | "Test \\[backward-sexp] beyond `bobp'." | ||
| 86 | (with-temp-buffer | ||
| 87 | (insert "()") | ||
| 88 | (should (null ;; (should-error ;; No, per #13994 | ||
| 89 | (forward-sexp -2))) | ||
| 90 | (should (bobp)))) | ||
| 91 | |||
| 92 | (ert-deftest lisp-forward-sexp-2-eobp-and-subsequent () | ||
| 93 | "Test \\[forward-sexp] beyond `eobp' and again." | ||
| 94 | (with-temp-buffer | ||
| 95 | (insert "()") | ||
| 96 | (goto-char (point-min)) | ||
| 97 | (should (null ;; (should-error ;; No, per #13994 | ||
| 98 | (forward-sexp 2))) | ||
| 99 | (should (eobp)) | ||
| 100 | (should (null ;; (should-error ;; No, per #13994 | ||
| 101 | (forward-sexp 1))))) | ||
| 102 | |||
| 103 | (ert-deftest lisp-backward-sexp-2-bobp-and-subsequent () | ||
| 104 | "Test \\[backward-sexp] ahead of `bobp' and again." | ||
| 105 | (with-temp-buffer | ||
| 106 | (insert "()") | ||
| 107 | (should (null ;; (should-error ;; No, per #13994 | ||
| 108 | (forward-sexp -2))) | ||
| 109 | (should (bobp)) | ||
| 110 | (should (null ;; (should-error ;; No, per #13994 | ||
| 111 | (forward-sexp -1))))) | ||
| 112 | |||
| 113 | (ert-deftest lisp-delete-pair-parens () | ||
| 114 | "Test \\[delete-pair] with parens." | ||
| 115 | (with-temp-buffer | ||
| 116 | (insert "(foo)") | ||
| 117 | (goto-char (point-min)) | ||
| 118 | (delete-pair) | ||
| 119 | (should (string-equal "foo" (buffer-string))))) | ||
| 120 | |||
| 121 | (ert-deftest lisp-delete-pair-quotation-marks () | ||
| 122 | "Test \\[delete-pair] with quotation marks." | ||
| 123 | (with-temp-buffer | ||
| 124 | (insert "\"foo\"") | ||
| 125 | (goto-char (point-min)) | ||
| 126 | (delete-pair) | ||
| 127 | (should (string-equal "foo" (buffer-string))))) | ||
| 128 | |||
| 129 | (ert-deftest lisp-delete-pair-quotes-in-text-mode () | ||
| 130 | "Test \\[delete-pair] against string in Text Mode for #15014." | ||
| 131 | (with-temp-buffer | ||
| 132 | (text-mode) | ||
| 133 | (insert "\"foo\"") | ||
| 134 | (goto-char (point-min)) | ||
| 135 | (delete-pair) | ||
| 136 | (should (string-equal "fo\"" (buffer-string))))) | ||
| 137 | |||
| 138 | (ert-deftest lisp-delete-pair-quotes-text-mode-syntax-table () | ||
| 139 | "Test \\[delete-pair] with modified Text Mode syntax for #15014." | ||
| 140 | (with-temp-buffer | ||
| 141 | (text-mode) | ||
| 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) | ||
| 146 | (insert "\"foo\"") | ||
| 147 | (goto-char (point-min)) | ||
| 148 | (delete-pair) | ||
| 149 | (should (string-equal "foo" (buffer-string))))))) | ||
| 150 | |||
| 151 | (ert-deftest lisp-forward-sexp-elisp-inside-symbol () | ||
| 152 | "Test \\[forward-sexp] on symbol in Emacs Lisp Mode for #20492." | ||
| 153 | (with-temp-buffer | ||
| 154 | (emacs-lisp-mode) | ||
| 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 "-")) | ||
| 160 | (forward-sexp) | ||
| 161 | (should (looking-at " ")))) | ||
| 162 | |||
| 163 | (ert-deftest lisp-forward-sexp-elisp-quoted-symbol () | ||
| 164 | "Test \\[forward-sexp] on symbol in Emacs Lisp Mode for #20492." | ||
| 165 | (with-temp-buffer | ||
| 166 | (emacs-lisp-mode) | ||
| 167 | (insert "`hide-ifdef-env'.") | ||
| 168 | (goto-char (point-min)) | ||
| 169 | (re-search-forward "hide" nil t) ;; (forward-char 5) | ||
| 170 | (should (= ?- (char-after))) | ||
| 171 | (forward-sexp) | ||
| 172 | (should (= ?. (char-before))))) | ||
| 173 | |||
| 174 | (ert-deftest lisp-forward-sexp-python-triple-quoted-string () | ||
| 175 | "Test \\[forward-sexp] on Python doc strings for #11321." | ||
| 176 | (with-temp-buffer | ||
| 177 | (insert "\"\"\"Triple-quoted string\"\"\"") | ||
| 178 | (goto-char (point-min)) | ||
| 179 | (let ((python-indent-guess-indent-offset nil)) | ||
| 180 | (python-mode)) | ||
| 181 | (forward-sexp) | ||
| 182 | (should (eobp)))) | ||
| 183 | |||
| 184 | (ert-deftest lisp-forward-sexp-python-triple-quotes-string () | ||
| 185 | "Test \\[forward-sexp] on Python doc strings for #11321." | ||
| 186 | (with-temp-buffer | ||
| 187 | (insert "'''Triple-quoted string'''") | ||
| 188 | (goto-char (point-min)) | ||
| 189 | (let ((python-indent-guess-indent-offset nil)) | ||
| 190 | (python-mode)) | ||
| 191 | (forward-sexp) | ||
| 192 | (should (eobp)))) | ||
| 193 | |||
| 194 | (ert-deftest lisp-forward-sexp-emacs-lisp-semi-char-error () | ||
| 195 | "Test \\[forward-sexp] on expression with unquoted semicolon per #4030." | ||
| 196 | (with-temp-buffer | ||
| 197 | (emacs-lisp-mode) | ||
| 198 | (insert "(insert ?;)") | ||
| 199 | (goto-char (point-min)) | ||
| 200 | (should-error (forward-sexp)))) ;; FIXME: Shouldn't be an error. | ||
| 201 | |||
| 202 | (ert-deftest lisp-forward-sexp-emacs-lisp-quote-char () | ||
| 203 | "Test \\[forward-sexp] on expression with unquoted quote per #4030." | ||
| 204 | (with-temp-buffer | ||
| 205 | (emacs-lisp-mode) | ||
| 206 | (insert "(insert ?\")") | ||
| 207 | (goto-char (point-min)) | ||
| 208 | (should-error (forward-sexp)))) ;; FIXME: Shouldn't be an error. | ||
| 209 | |||
| 210 | (provide 'lisp-tests) | ||
| 211 | ;;; lisp-tests.el ends here | ||