1 ;;; abbrev-tests.el --- Test suite for abbrevs -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2015-2016 Free Software Foundation, Inc.
5 ;; Author: Eli Zaretskii <eliz@gnu.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; `kill-all-abbrevs-test' will remove all user *and* system abbrevs
26 ;; if called noninteractively with the init file loaded.
34 ;; set up test abbrev table and abbrev entry
35 (defun setup-test-abbrev-table ()
36 (defvar ert-test-abbrevs nil
)
37 (define-abbrev-table 'ert-test-abbrevs
'(("a-e-t" "abbrev-ert-test")))
38 (abbrev-table-put ert-test-abbrevs
:ert-test
"ert-test-value")
41 (ert-deftest abbrev-table-p-test
()
42 (should-not (abbrev-table-p 42))
43 (should-not (abbrev-table-p "aoeu"))
44 (should-not (abbrev-table-p '()))
45 (should-not (abbrev-table-p []))
46 ;; Missing :abbrev-table-modiff counter:
47 (should-not (abbrev-table-p (obarray-make)))
48 (let* ((table (obarray-make)))
49 (abbrev-table-put table
:abbrev-table-modiff
42)
50 (should (abbrev-table-p table
))))
52 (ert-deftest abbrev-make-abbrev-table-test
()
53 ;; Table without properties:
54 (let ((table (make-abbrev-table)))
55 (should (abbrev-table-p table
))
56 (should (= (length table
) obarray-default-size
)))
57 ;; Table with one property 'foo with value 'bar:
58 (let ((table (make-abbrev-table '(foo bar
))))
59 (should (abbrev-table-p table
))
60 (should (= (length table
) obarray-default-size
))
61 (should (eq (abbrev-table-get table
'foo
) 'bar
))))
63 (ert-deftest abbrev-table-get-put-test
()
64 (let ((table (make-abbrev-table)))
65 (should-not (abbrev-table-get table
'foo
))
66 (should (= (abbrev-table-put table
'foo
42) 42))
67 (should (= (abbrev-table-get table
'foo
) 42))
68 (should (eq (abbrev-table-put table
'foo
'bar
) 'bar
))
69 (should (eq (abbrev-table-get table
'foo
) 'bar
))))
71 (ert-deftest copy-abbrev-table-test
()
72 (defvar foo-abbrev-table nil
) ; Avoid compiler warning
73 (define-abbrev-table 'foo-abbrev-table
75 (should (abbrev-table-p foo-abbrev-table
))
77 (let ((new-foo-abbrev-table
79 (copy-abbrev-table foo-abbrev-table
)
81 (should (abbrev-table-p new-foo-abbrev-table
)))
82 (should-not (string-equal (buffer-name) "*Backtrace*")))
84 (ert-deftest kill-all-abbrevs-test
()
85 "Test undefining all defined abbrevs"
86 (unless noninteractive
87 (ert-skip "Cannot test kill-all-abbrevs in interactive mode"))
90 ;; ensure at least one abbrev exists
91 (should (abbrev-table-p (setup-test-abbrev-table)))
92 (setf num-tables
(length abbrev-table-name-list
))
95 ;; no tables should have been removed/added
96 (should (= num-tables
(length abbrev-table-name-list
)))
97 ;; number of empty tables should be the same as number of tables
98 (should (= num-tables
(length (seq-filter
100 (abbrev-table-empty-p (symbol-value table
)))
101 abbrev-table-name-list
))))))
103 (ert-deftest abbrev-table-name-test
()
104 "Test returning name of abbrev-table"
105 (let ((ert-test-abbrevs (setup-test-abbrev-table))
107 (should (equal 'ert-test-abbrevs
(abbrev-table-name ert-test-abbrevs
)))
108 (should (equal nil
(abbrev-table-name no-such-table
)))))
110 (ert-deftest clear-abbrev-table-test
()
111 "Test clearing single abbrev table"
112 (let ((ert-test-abbrevs (setup-test-abbrev-table)))
113 (should (equal "a-e-t" (symbol-name
114 (abbrev-symbol "a-e-t" ert-test-abbrevs
))))
115 (should (equal "abbrev-ert-test" (symbol-value
116 (abbrev-symbol "a-e-t" ert-test-abbrevs
))))
118 (clear-abbrev-table ert-test-abbrevs
)
120 (should (equal "nil" (symbol-name
121 (abbrev-symbol "a-e-t" ert-test-abbrevs
))))
122 (should (equal nil
(symbol-value
123 (abbrev-symbol "a-e-t" ert-test-abbrevs
))))
124 (should (equal t
(abbrev-table-empty-p ert-test-abbrevs
)))))
126 (provide 'abbrev-tests
)
127 ;;; abbrev-tests.el ends here