Make sure we're inside the let bindings
[emacs.git] / test / automated / elisp-mode-tests.el
blobbfecfe7dc6bd751ee6b2aa2165af17ea79887d13
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/>.
22 ;;; Code:
24 (require 'ert)
26 (defun elisp--test-completions ()
27 (let ((data (elisp-completion-at-point)))
28 (all-completions (buffer-substring (nth 0 data) (nth 1 data))
29 (nth 2 data)
30 (plist-get (nthcdr 3 data) :predicate))))
32 (ert-deftest elisp-completes-functions ()
33 (with-temp-buffer
34 (emacs-lisp-mode)
35 (insert "(ba")
36 (let ((comps (elisp--test-completions)))
37 (should (member "backup-buffer" comps))
38 (should-not (member "backup-inhibited" comps)))))
40 (ert-deftest elisp-completes-variables ()
41 (with-temp-buffer
42 (emacs-lisp-mode)
43 (insert "(foo ba")
44 (let ((comps (elisp--test-completions)))
45 (should (member "backup-inhibited" comps))
46 (should-not (member "backup-buffer" comps)))))
48 (ert-deftest elisp-completes-anything-quoted ()
49 (dolist (text '("`(foo ba" "(foo 'ba"
50 "`(,foo ba" "`,(foo `ba"
51 "'(foo (ba"))
52 (with-temp-buffer
53 (emacs-lisp-mode)
54 (insert text)
55 (let ((comps (elisp--test-completions)))
56 (should (member "backup-inhibited" comps))
57 (should (member "backup-buffer" comps))
58 (should (member "backup" comps))))))
60 (ert-deftest elisp-completes-variables-unquoted ()
61 (dolist (text '("`(foo ,ba" "`(,(foo ba" "`(,ba"))
62 (with-temp-buffer
63 (emacs-lisp-mode)
64 (insert text)
65 (let ((comps (elisp--test-completions)))
66 (should (member "backup-inhibited" comps))
67 (should-not (member "backup-buffer" comps))))))
69 (ert-deftest elisp-completes-functions-in-special-macros ()
70 (dolist (text '("(declare-function ba" "(cl-callf2 ba"))
71 (with-temp-buffer
72 (emacs-lisp-mode)
73 (insert text)
74 (let ((comps (elisp--test-completions)))
75 (should (member "backup-buffer" comps))
76 (should-not (member "backup-inhibited" comps))))))
78 (ert-deftest elisp-completes-local-variables ()
79 (with-temp-buffer
80 (emacs-lisp-mode)
81 (insert "(let ((bar 1) baz) (foo ba")
82 (let ((comps (elisp--test-completions)))
83 (should (member "backup-inhibited" comps))
84 (should (member "bar" comps))
85 (should (member "baz" comps)))))
87 (ert-deftest elisp-completest-variables-in-let-bindings ()
88 (dolist (text '("(let (ba" "(let* ((ba"))
89 (with-temp-buffer
90 (emacs-lisp-mode)
91 (insert text)
92 (let ((comps (elisp--test-completions)))
93 (should (member "backup-inhibited" comps))
94 (should-not (member "backup-buffer" comps))))))
96 (ert-deftest elisp-completes-functions-after-let-bindings ()
97 (with-temp-buffer
98 (emacs-lisp-mode)
99 (insert "(let ((bar 1) (baz 2)) (ba")
100 (let ((comps (elisp--test-completions)))
101 (should (member "backup-buffer" comps))
102 (should-not (member "backup-inhibited" comps)))))
104 (provide 'elisp-mode-tests)
105 ;;; elisp-mode-tests.el ends here