diff options
| author | Noam Postavsky | 2017-07-19 22:06:02 -0400 |
|---|---|---|
| committer | Noam Postavsky | 2017-08-15 21:22:41 -0400 |
| commit | 3305dec5387021791eb09a93df5ab784b2297dc8 (patch) | |
| tree | 73d881b5dc8beee32d4c6d23e3f1f7913b016f89 | |
| parent | 55c9238189795448075e2d4af93a7b29a505f23c (diff) | |
| download | emacs-3305dec5387021791eb09a93df5ab784b2297dc8.tar.gz emacs-3305dec5387021791eb09a93df5ab784b2297dc8.zip | |
Add tests for previous commit
* test/lisp/progmodes/elisp-mode-tests.el
(elisp-mode-tests--face-propertized-string): New function.
(elisp--highlight-function-argument-indexed)
(elisp--highlight-function-argument-keyed-1)
(elisp--highlight-function-argument-keyed-2): New tests.
| -rw-r--r-- | test/lisp/progmodes/elisp-mode-tests.el | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/test/lisp/progmodes/elisp-mode-tests.el b/test/lisp/progmodes/elisp-mode-tests.el index ee0837f2c4c..675aa31a79f 100644 --- a/test/lisp/progmodes/elisp-mode-tests.el +++ b/test/lisp/progmodes/elisp-mode-tests.el | |||
| @@ -24,6 +24,7 @@ | |||
| 24 | 24 | ||
| 25 | (require 'ert) | 25 | (require 'ert) |
| 26 | (require 'xref) | 26 | (require 'xref) |
| 27 | (eval-when-compile (require 'cl-lib)) | ||
| 27 | 28 | ||
| 28 | ;;; Completion | 29 | ;;; Completion |
| 29 | 30 | ||
| @@ -180,6 +181,61 @@ | |||
| 180 | (call-interactively #'eval-last-sexp) | 181 | (call-interactively #'eval-last-sexp) |
| 181 | (should (equal (current-message) "66 (#o102, #x42, ?B)")))))) | 182 | (should (equal (current-message) "66 (#o102, #x42, ?B)")))))) |
| 182 | 183 | ||
| 184 | ;;; eldoc | ||
| 185 | |||
| 186 | (defun elisp-mode-tests--face-propertized-string (string) | ||
| 187 | "Return substring of STRING with a non-nil `face' property." | ||
| 188 | (let* ((start (next-single-property-change 0 'face string)) | ||
| 189 | (end (and start (next-single-property-change start 'face string)))) | ||
| 190 | (and end | ||
| 191 | (substring string start end)))) | ||
| 192 | |||
| 193 | (ert-deftest elisp--highlight-function-argument-indexed () | ||
| 194 | (dotimes (i 3) | ||
| 195 | (should | ||
| 196 | (equal (elisp-mode-tests--face-propertized-string | ||
| 197 | (elisp--highlight-function-argument 'foo "(A B C)" (1+ i) "foo: ")) | ||
| 198 | (propertize (nth i '("A" "B" "C")) | ||
| 199 | 'face 'eldoc-highlight-function-argument))))) | ||
| 200 | |||
| 201 | (ert-deftest elisp--highlight-function-argument-keyed-1 () | ||
| 202 | (with-temp-buffer | ||
| 203 | (emacs-lisp-mode) | ||
| 204 | (insert "(foo prompt bar :b 2)") | ||
| 205 | (goto-char (1+ (point-min))) | ||
| 206 | (cl-flet ((bold-arg (i) | ||
| 207 | (elisp-mode-tests--face-propertized-string | ||
| 208 | (elisp--highlight-function-argument | ||
| 209 | 'foo "(PROMPT LST &key A B C)" i "foo: ")))) | ||
| 210 | (should-not (bold-arg 0)) | ||
| 211 | (progn (forward-sexp) (forward-char)) | ||
| 212 | (should (equal (bold-arg 1) "PROMPT")) | ||
| 213 | (progn (forward-sexp) (forward-char)) | ||
| 214 | (should (equal (bold-arg 2) "LST")) | ||
| 215 | ;; Both `:b' and `2' should highlight the `B' arg. | ||
| 216 | (progn (forward-sexp) (forward-char)) | ||
| 217 | (should (equal (bold-arg 3) "B")) | ||
| 218 | (progn (forward-sexp) (forward-char)) | ||
| 219 | (should (equal (bold-arg 4) "B"))))) | ||
| 220 | |||
| 221 | (ert-deftest elisp--highlight-function-argument-keyed-2 () | ||
| 222 | (with-temp-buffer | ||
| 223 | (emacs-lisp-mode) | ||
| 224 | (insert "(foo :b :a 1)") | ||
| 225 | (goto-char (1+ (point-min))) | ||
| 226 | (cl-flet ((bold-arg (i) | ||
| 227 | (elisp-mode-tests--face-propertized-string | ||
| 228 | (elisp--highlight-function-argument | ||
| 229 | 'foo "(X &key A B C)" i "foo: ")))) | ||
| 230 | (should-not (bold-arg 0)) | ||
| 231 | ;; The `:b' specifies positional arg `X'. | ||
| 232 | (progn (forward-sexp) (forward-char)) | ||
| 233 | (should (equal (bold-arg 1) "X")) | ||
| 234 | (progn (forward-sexp) (forward-char)) | ||
| 235 | (should (equal (bold-arg 2) "A")) | ||
| 236 | (progn (forward-sexp) (forward-char)) | ||
| 237 | (should (equal (bold-arg 3) "A"))))) | ||
| 238 | |||
| 183 | ;;; xref | 239 | ;;; xref |
| 184 | 240 | ||
| 185 | (defun xref-elisp-test-descr-to-target (xref) | 241 | (defun xref-elisp-test-descr-to-target (xref) |