aboutsummaryrefslogtreecommitdiffstats
path: root/test/lisp/obarray-tests.el
diff options
context:
space:
mode:
Diffstat (limited to 'test/lisp/obarray-tests.el')
-rw-r--r--test/lisp/obarray-tests.el90
1 files changed, 90 insertions, 0 deletions
diff --git a/test/lisp/obarray-tests.el b/test/lisp/obarray-tests.el
new file mode 100644
index 00000000000..4cc61b6903f
--- /dev/null
+++ b/test/lisp/obarray-tests.el
@@ -0,0 +1,90 @@
1;;; obarray-tests.el --- Tests for obarray -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2015 Free Software Foundation, Inc.
4
5;; Author: Przemysław Wojnowski <esperanto@cumego.com>
6
7;; This file is part of GNU Emacs.
8
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.
13
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.
18
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/>.
21
22;;; Commentary:
23
24;;; Code:
25
26(require 'obarray)
27(require 'ert)
28
29(ert-deftest obarrayp-test ()
30 "Should assert that given object is an obarray."
31 (should-not (obarrayp 42))
32 (should-not (obarrayp "aoeu"))
33 (should-not (obarrayp '()))
34 (should-not (obarrayp []))
35 (should (obarrayp (make-vector 7 0))))
36
37(ert-deftest obarrayp-unchecked-content-test ()
38 "Should fail to check content of passed obarray."
39 :expected-result :failed
40 (should-not (obarrayp ["a" "b" "c"]))
41 (should-not (obarrayp [1 2 3])))
42
43(ert-deftest obarray-make-default-test ()
44 (let ((table (obarray-make)))
45 (should (obarrayp table))
46 (should (equal (make-vector 59 0) table))))
47
48(ert-deftest obarray-make-with-size-test ()
49 (should-error (obarray-make -1) :type 'wrong-type-argument)
50 (should-error (obarray-make 0) :type 'wrong-type-argument)
51 (let ((table (obarray-make 1)))
52 (should (obarrayp table))
53 (should (equal (make-vector 1 0) table))))
54
55(ert-deftest obarray-get-test ()
56 (let ((table (obarray-make 3)))
57 (should-not (obarray-get table "aoeu"))
58 (intern "aoeu" table)
59 (should (string= "aoeu" (obarray-get table "aoeu")))))
60
61(ert-deftest obarray-put-test ()
62 (let ((table (obarray-make 3)))
63 (should-not (obarray-get table "aoeu"))
64 (should (string= "aoeu" (obarray-put table "aoeu")))
65 (should (string= "aoeu" (obarray-get table "aoeu")))))
66
67(ert-deftest obarray-remove-test ()
68 (let ((table (obarray-make 3)))
69 (should-not (obarray-get table "aoeu"))
70 (should-not (obarray-remove table "aoeu"))
71 (should (string= "aoeu" (obarray-put table "aoeu")))
72 (should (string= "aoeu" (obarray-get table "aoeu")))
73 (should (obarray-remove table "aoeu"))
74 (should-not (obarray-get table "aoeu"))))
75
76(ert-deftest obarray-map-test ()
77 "Should execute function on all elements of obarray."
78 (let* ((table (obarray-make 3))
79 (syms '())
80 (collect-names (lambda (sym) (push (symbol-name sym) syms))))
81 (obarray-map collect-names table)
82 (should (null syms))
83 (obarray-put table "a")
84 (obarray-put table "b")
85 (obarray-put table "c")
86 (obarray-map collect-names table)
87 (should (equal (sort syms #'string<) '("a" "b" "c")))))
88
89(provide 'obarray-tests)
90;;; obarray-tests.el ends here