; ChangeLog.3 fixes
[emacs.git] / test / lisp / obarray-tests.el
blobdca7c8567839965f787fe95a80e235b4e3696d33
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 <https://www.gnu.org/licenses/>.
22 ;;; Commentary:
24 ;;; Code:
26 (require 'obarray)
27 (require 'ert)
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 (eq (obarray-size table) obarray-default-size))))
48 (ert-deftest obarray-make-with-size-test ()
49 ;; FIXME: Actually, `wrong-type-argument' is not the right error to signal,
50 ;; so we shouldn't enforce this misbehavior in tests!
51 (should-error (obarray-make -1) :type 'wrong-type-argument)
52 (should-error (obarray-make 0) :type 'wrong-type-argument)
53 (let ((table (obarray-make 1)))
54 (should (obarrayp table))
55 (should (eq (obarray-size table) 1))))
57 (ert-deftest obarray-get-test ()
58 (let ((table (obarray-make 3)))
59 (should-not (obarray-get table "aoeu"))
60 (intern "aoeu" table)
61 (should (string= "aoeu" (obarray-get table "aoeu")))))
63 (ert-deftest obarray-put-test ()
64 (let ((table (obarray-make 3)))
65 (should-not (obarray-get table "aoeu"))
66 (should (string= "aoeu" (obarray-put table "aoeu")))
67 (should (string= "aoeu" (obarray-get table "aoeu")))))
69 (ert-deftest obarray-remove-test ()
70 (let ((table (obarray-make 3)))
71 (should-not (obarray-get table "aoeu"))
72 (should-not (obarray-remove table "aoeu"))
73 (should (string= "aoeu" (obarray-put table "aoeu")))
74 (should (string= "aoeu" (obarray-get table "aoeu")))
75 (should (obarray-remove table "aoeu"))
76 (should-not (obarray-get table "aoeu"))))
78 (ert-deftest obarray-map-test ()
79 "Should execute function on all elements of obarray."
80 (let* ((table (obarray-make 3))
81 (syms '())
82 (collect-names (lambda (sym) (push (symbol-name sym) syms))))
83 (obarray-map collect-names table)
84 (should (null syms))
85 (obarray-put table "a")
86 (obarray-put table "b")
87 (obarray-put table "c")
88 (obarray-map collect-names table)
89 (should (equal (sort syms #'string<) '("a" "b" "c")))))
91 (provide 'obarray-tests)
92 ;;; obarray-tests.el ends here