1 ;;; elisp-mode-tests.el --- Tests for emacs-lisp-mode -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2015 Free Software Foundation, Inc.
5 ;; Author: Dmitry Gutov <dgutov@yandex.ru>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
29 (defun elisp--test-completions ()
30 (let ((data (elisp-completion-at-point)))
31 (all-completions (buffer-substring (nth 0 data
) (nth 1 data
))
33 (plist-get (nthcdr 3 data
) :predicate
))))
35 (ert-deftest elisp-completes-functions
()
39 (let ((comps (elisp--test-completions)))
40 (should (member "backup-buffer" comps
))
41 (should-not (member "backup-inhibited" comps
)))))
43 (ert-deftest elisp-completes-variables
()
47 (let ((comps (elisp--test-completions)))
48 (should (member "backup-inhibited" comps
))
49 (should-not (member "backup-buffer" comps
)))))
51 (ert-deftest elisp-completes-anything-quoted
()
52 (dolist (text '("`(foo ba" "(foo 'ba"
53 "`(,foo ba" "`,(foo `ba"
58 (let ((comps (elisp--test-completions)))
59 (should (member "backup-inhibited" comps
))
60 (should (member "backup-buffer" comps
))
61 (should (member "backup" comps
))))))
63 (ert-deftest elisp-completes-variables-unquoted
()
64 (dolist (text '("`(foo ,ba" "`(,(foo ba" "`(,ba"))
68 (let ((comps (elisp--test-completions)))
69 (should (member "backup-inhibited" comps
))
70 (should-not (member "backup-buffer" comps
))))))
72 (ert-deftest elisp-completes-functions-in-special-macros
()
73 (dolist (text '("(declare-function ba" "(cl-callf2 ba"))
77 (let ((comps (elisp--test-completions)))
78 (should (member "backup-buffer" comps
))
79 (should-not (member "backup-inhibited" comps
))))))
81 (ert-deftest elisp-completes-functions-after-hash-quote
()
82 (ert-deftest elisp-completes-functions-after-let-bindings
()
86 (let ((comps (elisp--test-completions)))
87 (should (member "backup-buffer" comps
))
88 (should-not (member "backup-inhibited" comps
))))))
90 (ert-deftest elisp-completes-local-variables
()
93 (insert "(let ((bar 1) baz) (foo ba")
94 (let ((comps (elisp--test-completions)))
95 (should (member "backup-inhibited" comps
))
96 (should (member "bar" comps
))
97 (should (member "baz" comps
)))))
99 (ert-deftest elisp-completest-variables-in-let-bindings
()
100 (dolist (text '("(let (ba" "(let* ((ba"))
104 (let ((comps (elisp--test-completions)))
105 (should (member "backup-inhibited" comps
))
106 (should-not (member "backup-buffer" comps
))))))
108 (ert-deftest elisp-completes-functions-after-let-bindings
()
111 (insert "(let ((bar 1) (baz 2)) (ba")
112 (let ((comps (elisp--test-completions)))
113 (should (member "backup-buffer" comps
))
114 (should-not (member "backup-inhibited" comps
)))))
118 (ert-deftest elisp-xref-finds-both-function-and-variable
()
119 ;; "system-name" is both: a variable and a function
120 (let ((defs (elisp-xref-find 'definitions
"system-name")))
121 (should (= (length defs
) 2))
122 (should (string= (xref--xref-description (nth 0 defs
))
123 "(defun system-name)"))
124 (should (string= (xref--xref-description (nth 1 defs
))
125 "(defvar system-name)")))
126 ;; It's a minor mode, but the variable is defined in buffer.c
127 (let ((defs (elisp-xref-find 'definitions
"abbrev-mode")))
128 (should (= (length defs
) 2))))
130 (ert-deftest elisp-xref-finds-only-function-for-minor-mode
()
131 ;; Both variable and function are defined in the same place.
132 (let ((defs (elisp-xref-find 'definitions
"visible-mode")))
133 (should (= (length defs
) 1))
134 (should (string= (xref--xref-description (nth 0 defs
))
135 "(defun visible-mode)"))))
137 (provide 'elisp-mode-tests
)
138 ;;; elisp-mode-tests.el ends here