1 ;;; obarray-tests.el --- Tests for obarray -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2015-2017 Free Software Foundation, Inc.
5 ;; Author: Przemysław Wojnowski <esperanto@cumego.com>
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 (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))))
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])))
43 (ert-deftest obarray-make-default-test
()
44 (let ((table (obarray-make)))
45 (should (obarrayp table
))
46 (should (equal (make-vector 59 0) table
))))
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
))))
55 (ert-deftest obarray-get-test
()
56 (let ((table (obarray-make 3)))
57 (should-not (obarray-get table
"aoeu"))
59 (should (string= "aoeu" (obarray-get table
"aoeu")))))
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")))))
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"))))
76 (ert-deftest obarray-map-test
()
77 "Should execute function on all elements of obarray."
78 (let* ((table (obarray-make 3))
80 (collect-names (lambda (sym) (push (symbol-name sym
) syms
))))
81 (obarray-map collect-names table
)
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")))))
89 (provide 'obarray-tests
)
90 ;;; obarray-tests.el ends here