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-local-variables
()
84 (insert "(let ((bar 1) baz) (foo ba")
85 (let ((comps (elisp--test-completions)))
86 (should (member "backup-inhibited" comps
))
87 (should (member "bar" comps
))
88 (should (member "baz" comps
)))))
90 (ert-deftest elisp-completest-variables-in-let-bindings
()
91 (dolist (text '("(let (ba" "(let* ((ba"))
95 (let ((comps (elisp--test-completions)))
96 (should (member "backup-inhibited" comps
))
97 (should-not (member "backup-buffer" comps
))))))
99 (ert-deftest elisp-completes-functions-after-let-bindings
()
102 (insert "(let ((bar 1) (baz 2)) (ba")
103 (let ((comps (elisp--test-completions)))
104 (should (member "backup-buffer" comps
))
105 (should-not (member "backup-inhibited" comps
)))))
109 (ert-deftest elisp-xref-finds-both-function-and-variable
()
110 ;; "system-name" is both: a variable and a function
111 (let ((defs (elisp-xref-find 'definitions
"system-name")))
112 (should (= (length defs
) 2))
113 (should (string= (xref--xref-description (nth 0 defs
))
114 "(defun system-name)"))
115 (should (string= (xref--xref-description (nth 1 defs
))
116 "(defvar system-name)")))
117 ;; It's a minor mode, but the variable is defined in buffer.c
118 (let ((defs (elisp-xref-find 'definitions
"abbrev-mode")))
119 (should (= (length defs
) 2))))
121 (ert-deftest elisp-xref-finds-only-function-for-minor-mode
()
122 ;; Both variable and function are defined in the same place.
123 (let ((defs (elisp-xref-find 'definitions
"visible-mode")))
124 (should (= (length defs
) 1))
125 (should (string= (xref--xref-description (nth 0 defs
))
126 "(defun visible-mode)"))))
128 (provide 'elisp-mode-tests
)
129 ;;; elisp-mode-tests.el ends here