1 ;;; bindings.el --- tests for variable bindings
3 ;; Copyright (C) 2012 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software: you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22 (defvar binding-test-buffer-A
(get-buffer-create "A"))
23 (defvar binding-test-buffer-B
(get-buffer-create "B"))
25 (defvar binding-test-always-local
'always
)
26 (make-variable-buffer-local 'binding-test-always-local
)
28 (defvar binding-test-some-local
'some
)
29 (with-current-buffer binding-test-buffer-A
30 (set (make-local-variable 'binding-test-some-local
) 'local
))
32 (ert-deftest binding-test-manual
()
33 "A test case from the elisp manual."
35 (set-buffer binding-test-buffer-A
)
36 (let ((binding-test-some-local 'something-else
))
37 (should (eq binding-test-some-local
'something-else
))
38 (set-buffer binding-test-buffer-B
)
39 (should (eq binding-test-some-local
'some
)))
40 (should (eq binding-test-some-local
'some
))
41 (set-buffer binding-test-buffer-A
)
42 (should (eq binding-test-some-local
'local
))))
44 (ert-deftest binding-test-setq-default
()
45 "Test that a setq-default has no effect when there is a local binding."
47 (set-buffer binding-test-buffer-B
)
48 ;; This variable is not local in this buffer.
49 (let ((binding-test-some-local 'something-else
))
50 (setq-default binding-test-some-local
'new-default
))
51 (should (eq binding-test-some-local
'some
))))
53 (ert-deftest binding-test-makunbound
()
54 "Tests of makunbound, from the manual."
56 (set-buffer binding-test-buffer-B
)
57 (should (boundp 'binding-test-some-local
))
58 (let ((binding-test-some-local 'outer
))
59 (let ((binding-test-some-local 'inner
))
60 (makunbound 'binding-test-some-local
)
61 (should (not (boundp 'binding-test-some-local
))))
62 (should (and (boundp 'binding-test-some-local
)
63 (eq binding-test-some-local
'outer
))))))
65 (ert-deftest binding-test-defvar-bool
()
67 (let ((display-hourglass 5))
68 (should (eq display-hourglass t
))))
70 (ert-deftest binding-test-defvar-int
()
72 (should-error (setq gc-cons-threshold
5.0) :type
'wrong-type-argument
))
74 (ert-deftest binding-test-set-constant-t
()
75 "Test setting the constant t"
76 (should-error (setq t
'bob
) :type
'setting-constant
))
78 (ert-deftest binding-test-set-constant-nil
()
79 "Test setting the constant nil"
80 (should-error (setq nil
'bob
) :type
'setting-constant
))
82 (ert-deftest binding-test-set-constant-keyword
()
83 "Test setting a keyword constant"
84 (should-error (setq :keyword
'bob
) :type
'setting-constant
))
86 (ert-deftest binding-test-set-constant-nil
()
87 "Test setting a keyword to itself"
88 (should (setq :keyword
:keyword
)))
90 ;; More tests to write -
91 ;; kill-local-variable
92 ;; defconst; can modify
93 ;; defvar and defconst modify the local binding [ doesn't matter for us ]
94 ;; various kinds of special internal forwarding objects
95 ;; a couple examples in manual, not enough
99 ;;; bindings.el ends here