aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Tromey2012-08-27 09:26:16 -0600
committerTom Tromey2012-08-27 09:26:16 -0600
commite7c4e870bb26dfc9d2de7b337609a793b35de3e2 (patch)
tree3dca44ee5e0ba79e1fd62d9093c870720897180a
parent09d7066e2291651805b7bfd5edbf45562766e122 (diff)
downloademacs-e7c4e870bb26dfc9d2de7b337609a793b35de3e2.tar.gz
emacs-e7c4e870bb26dfc9d2de7b337609a793b35de3e2.zip
add tests for variable bindings
-rw-r--r--test/automated/bindings.el99
1 files changed, 99 insertions, 0 deletions
diff --git a/test/automated/bindings.el b/test/automated/bindings.el
new file mode 100644
index 00000000000..4b88baeef40
--- /dev/null
+++ b/test/automated/bindings.el
@@ -0,0 +1,99 @@
1;;; bindings.el --- tests for variable bindings
2
3;; Copyright (C) 2012 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
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.
11
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.
16
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/>.
19
20;;; Code:
21
22(defvar binding-test-buffer-A (get-buffer-create "A"))
23(defvar binding-test-buffer-B (get-buffer-create "B"))
24
25(defvar binding-test-always-local 'always)
26(make-variable-buffer-local 'binding-test-always-local)
27
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))
31
32(ert-deftest binding-test-manual ()
33 "A test case from the elisp manual."
34 (save-excursion
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))))
43
44(ert-deftest binding-test-setq-default ()
45 "Test that a setq-default has no effect when there is a local binding."
46 (save-excursion
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))))
52
53(ert-deftest binding-test-makunbound ()
54 "Tests of makunbound, from the manual."
55 (save-excursion
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))))))
64
65(ert-deftest binding-test-defvar-bool ()
66 "Test DEFVAR_BOOL"
67 (let ((display-hourglass 5))
68 (should (eq display-hourglass t))))
69
70(ert-deftest binding-test-defvar-int ()
71 "Test DEFVAR_INT"
72 (should-error (setq gc-cons-threshold 5.0) :type 'wrong-type-argument))
73
74(ert-deftest binding-test-set-constant-t ()
75 "Test setting the constant t"
76 (should-error (setq t 'bob) :type 'setting-constant))
77
78(ert-deftest binding-test-set-constant-nil ()
79 "Test setting the constant nil"
80 (should-error (setq nil 'bob) :type 'setting-constant))
81
82(ert-deftest binding-test-set-constant-keyword ()
83 "Test setting a keyword constant"
84 (should-error (setq :keyword 'bob) :type 'setting-constant))
85
86(ert-deftest binding-test-set-constant-nil ()
87 "Test setting a keyword to itself"
88 (should (setq :keyword :keyword)))
89
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
96;; frame-local vars
97;; variable aliases
98
99;;; bindings.el ends here