Improve treatment of Fortran's "class is"
[emacs.git] / test / automated / abbrev-tests.el
blob66413c5a59072a1d8104a223af5b286bd26ccf42
1 ;;; abbrev-tests.el --- Test suite for abbrevs.
3 ;; Copyright (C) 2015-2016 Free Software Foundation, Inc.
5 ;; Author: Eli Zaretskii <eliz@gnu.org>
6 ;; Keywords: abbrevs
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/>.
23 ;;; Commentary:
25 ;; `kill-all-abbrevs-test' will remove all user *and* system abbrevs
26 ;; if called noninteractively with the init file loaded.
28 ;;; Code:
30 (require 'ert)
31 (require 'abbrev)
32 (require 'seq)
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")
39 ert-test-abbrevs)
41 (ert-deftest copy-abbrev-table-test ()
42 (defvar foo-abbrev-table nil) ; Avoid compiler warning
43 (define-abbrev-table 'foo-abbrev-table
44 '())
45 (should (abbrev-table-p foo-abbrev-table))
46 ;; Bug 21828
47 (let ((new-foo-abbrev-table
48 (condition-case nil
49 (copy-abbrev-table foo-abbrev-table)
50 (error nil))))
51 (should (abbrev-table-p new-foo-abbrev-table)))
52 (should-not (string-equal (buffer-name) "*Backtrace*")))
54 (ert-deftest kill-all-abbrevs-test ()
55 "Test undefining all defined abbrevs"
56 (unless noninteractive
57 (ert-skip "Cannot test kill-all-abbrevs in interactive mode"))
59 (let ((num-tables 0))
60 ;; ensure at least one abbrev exists
61 (should (abbrev-table-p (setup-test-abbrev-table)))
62 (setf num-tables (length abbrev-table-name-list))
63 (kill-all-abbrevs)
65 ;; no tables should have been removed/added
66 (should (= num-tables (length abbrev-table-name-list)))
67 ;; number of empty tables should be the same as number of tables
68 (should (= num-tables (length (seq-filter
69 (lambda (table)
70 (abbrev-table-empty-p (symbol-value table)))
71 abbrev-table-name-list))))))
73 (ert-deftest abbrev-table-name-test ()
74 "Test returning name of abbrev-table"
75 (let ((ert-test-abbrevs (setup-test-abbrev-table))
76 (no-such-table nil))
77 (should (equal 'ert-test-abbrevs (abbrev-table-name ert-test-abbrevs)))
78 (should (equal nil (abbrev-table-name no-such-table)))))
80 (ert-deftest clear-abbrev-table-test ()
81 "Test clearing single abbrev table"
82 (let ((ert-test-abbrevs (setup-test-abbrev-table)))
83 (should (equal "a-e-t" (symbol-name
84 (abbrev-symbol "a-e-t" ert-test-abbrevs))))
85 (should (equal "abbrev-ert-test" (symbol-value
86 (abbrev-symbol "a-e-t" ert-test-abbrevs))))
88 (clear-abbrev-table ert-test-abbrevs)
90 (should (equal "nil" (symbol-name
91 (abbrev-symbol "a-e-t" ert-test-abbrevs))))
92 (should (equal nil (symbol-value
93 (abbrev-symbol "a-e-t" ert-test-abbrevs))))
94 (should (equal t (abbrev-table-empty-p ert-test-abbrevs)))))
96 (provide 'abbrev-tests)
98 ;;; abbrev-tests.el ends here