2015-11-08 19:19:15 +01:00
|
|
|
;;; abbrev-tests.el --- Test suite for abbrevs -*- lexical-binding: t; -*-
|
2015-11-07 13:32:33 +02:00
|
|
|
|
2024-01-02 09:47:10 +08:00
|
|
|
;; Copyright (C) 2015-2024 Free Software Foundation, Inc.
|
2015-11-07 13:32:33 +02:00
|
|
|
|
|
|
|
;; Author: Eli Zaretskii <eliz@gnu.org>
|
|
|
|
;; Keywords: abbrevs
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 15:52:52 -07:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2015-11-07 13:32:33 +02:00
|
|
|
|
2015-11-08 19:19:15 +01:00
|
|
|
;;; Commentary:
|
|
|
|
|
2015-11-26 15:38:09 +09:00
|
|
|
;; `kill-all-abbrevs-test' will remove all user *and* system abbrevs
|
|
|
|
;; if called noninteractively with the init file loaded.
|
|
|
|
|
2015-11-07 13:32:33 +02:00
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(require 'ert)
|
Prefer ert-with-temp-(directory|file)
* test/lisp/abbrev-tests.el (read-write-abbrev-file-test)
(read-write-abbrev-file-test-with-props)
(abbrev-edit-save-to-file-test):
* test/lisp/auth-source-tests.el (auth-source-test-netrc-create-secret)
(auth-source-delete):
* test/lisp/autoinsert-tests.el (autoinsert-tests-auto-insert-file):
* test/lisp/bookmark-tests.el (with-bookmark-test-save-load):
* test/lisp/buff-menu-tests.el (buff-menu-24962):
* test/lisp/calendar/icalendar-tests.el (icalendar-tests--do-test-export):
* test/lisp/calendar/todo-mode-tests.el (with-todo-test):
* test/lisp/dired-tests.el
(dired-test-bug27243-01, dired-test-bug27243-02)
(dired-test-bug27243-03, dired-test-bug27631)
(dired-test-bug27968, dired-test-with-temp-dirs):
* test/lisp/dired-x-tests.el (dired-test-bug25942):
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-tests--with-temp-file):
* test/lisp/emacs-lisp/check-declare-tests.el (check-declare-tests-scan)
(check-declare-tests-verify-mismatch):
* test/lisp/emacs-lisp/edebug-tests.el (edebug-tests-with-normal-env):
* test/lisp/emacs-lisp/package-tests.el (with-package-test)
(package-test-signed):
* test/lisp/emacs-lisp/testcover-tests.el (testcover-tests-markup-region)
(testcover-tests-run-test-case):
* test/lisp/emulation/viper-tests.el (viper-test-undo-kmacro):
* test/lisp/epg-tests.el (with-epg-tests):
* test/lisp/eshell/em-hist-tests.el (eshell-write-readonly-history):
* test/lisp/eshell/em-ls-tests.el (em-ls-test-bug27631):
* test/lisp/ffap-tests.el (ffap-tests-25243):
* test/lisp/files-tests.el (files-tests-bug-18141)
(files-tests-read-file-in-~, files-tests-make-directory)
(files-tests-copy-directory, files-tests-executable-find)
(files-tests-dont-rewrite-precious-files)
(files-tests--save-some-buffers):
* test/lisp/ls-lisp-tests.el (ls-lisp-test-bug27631):
* test/lisp/mail/uudecode-tests.el (uudecode-tests-decode-region-internal)
(uudecode-tests-decode-region-external):
* test/lisp/net/browse-url-tests.el (browse-url-tests-delete-temp-file):
* test/lisp/progmodes/elisp-mode-tests.el (xref--case-insensitive):
* test/lisp/progmodes/etags-tests.el (etags-buffer-local-tags-table-list):
* test/lisp/progmodes/flymake-tests.el (ruby-backend):
* test/lisp/progmodes/python-tests.el (python-tests-with-temp-file):
* test/lisp/progmodes/sql-tests.el (with-sql-test-connect-harness):
* test/lisp/saveplace-tests.el (saveplace-test-save-place-to-alist/file)
(saveplace-test-forget-unreadable-files)
(saveplace-test-place-alist-to-file):
* test/lisp/so-long-tests/spelling-tests.el:
* test/lisp/textmodes/reftex-tests.el (reftex-locate-bibliography-files)
(reftex-parse-from-file-test):
* test/lisp/thumbs-tests.el (thumbs-tests-thumbsdir/create-if-missing):
* test/lisp/vc/vc-bzr-tests.el (vc-bzr-test-bug9726)
(vc-bzr-test-bug9781, vc-bzr-test-faulty-bzr-autoloads):
* test/lisp/vc/diff-mode-tests.el (diff-mode-test-ignore-trailing-dashes):
* test/lisp/vc/ediff-ptch-tests.el (ediff-ptch-test-bug26084):
* test/lisp/wdired-tests.el (wdired-test-bug32173-01)
(wdired-test-bug32173-02, wdired-test-symlink-name)
(wdired-test-unfinished-edit-01, wdired-test-bug34915)
(wdired-test-bug39280):
* test/src/buffer-tests.el (test-kill-buffer-auto-save-default):
* test/src/filelock-tests.el (filelock-tests--fixture):
* test/src/inotify-tests.el (inotify-file-watch-simple):
* test/src/undo-tests.el (undo-test-file-modified): Prefer
'ert-with-temp-(directory|file)' to using 'make-temp-file' directly.
In some cases, this is just cleanup, but in several cases this fixes
bugs where an error would have lead to us not cleaning up.
2021-11-06 23:20:59 +01:00
|
|
|
(require 'ert-x)
|
2015-11-07 13:32:33 +02:00
|
|
|
(require 'abbrev)
|
2015-11-26 15:38:09 +09:00
|
|
|
(require 'seq)
|
|
|
|
|
|
|
|
;; set up test abbrev table and abbrev entry
|
|
|
|
(defun setup-test-abbrev-table ()
|
|
|
|
(defvar ert-test-abbrevs nil)
|
|
|
|
(define-abbrev-table 'ert-test-abbrevs '(("a-e-t" "abbrev-ert-test")))
|
|
|
|
(abbrev-table-put ert-test-abbrevs :ert-test "ert-test-value")
|
|
|
|
ert-test-abbrevs)
|
2015-11-07 13:32:33 +02:00
|
|
|
|
2017-12-31 20:14:09 -08:00
|
|
|
(defun setup-test-abbrev-table-with-props ()
|
|
|
|
(defvar ert-test-abbrevs nil)
|
|
|
|
(define-abbrev-table 'ert-test-abbrevs '(("fb" "fooBar" nil :case-fixed t)))
|
|
|
|
(abbrev-table-put ert-test-abbrevs :ert-test "ert-test-value")
|
|
|
|
ert-test-abbrevs)
|
|
|
|
|
2015-11-08 19:19:15 +01:00
|
|
|
(ert-deftest abbrev-table-p-test ()
|
|
|
|
(should-not (abbrev-table-p 42))
|
|
|
|
(should-not (abbrev-table-p "aoeu"))
|
|
|
|
(should-not (abbrev-table-p '()))
|
|
|
|
(should-not (abbrev-table-p []))
|
|
|
|
;; Missing :abbrev-table-modiff counter:
|
|
|
|
(should-not (abbrev-table-p (obarray-make)))
|
2017-01-28 04:40:36 +01:00
|
|
|
(should (abbrev-table-empty-p (make-abbrev-table))))
|
2015-11-08 19:19:15 +01:00
|
|
|
|
|
|
|
(ert-deftest abbrev-make-abbrev-table-test ()
|
|
|
|
;; Table without properties:
|
|
|
|
(let ((table (make-abbrev-table)))
|
Add a proper type for obarrays
The new opaque type replaces the previous use of vectors for obarrays.
`obarray-make` now returns objects of this type. Functions that take
obarrays continue to accept vectors for compatibility, now just using
their first slot to store an actual obarray object.
obarray-size and obarray-default-size now obsolete.
* lisp/obarray.el (obarray-default-size, obarray-size):
Declare obsolete.
(obarray-make, obarrayp, obarray-clear): Remove from here.
* src/fns.c (reduce_emacs_uint_to_hash_hash): Remove from here.
* src/lisp.h (struct Lisp_Obarray, OBARRAYP, XOBARRAY, CHECK_OBARRAY)
(make_lisp_obarray, obarray_size, check_obarray)
(obarray_iter_t, make_obarray_iter, obarray_iter_at_end)
(obarray_iter_step, obarray_iter_symbol, DOOBARRAY, knuth_hash): New.
(reduce_emacs_uint_to_hash_hash): Moved here.
* src/lread.c (check_obarray): Renamed and reworked as...
(checked_obarray_slow): ...this.
(intern_sym, Funintern, oblookup, map_obarray)
(Finternal__obarray_buckets): Adapt to new type.
(obarray_index, allocate_obarray, make_obarray, grow_obarray)
(obarray_default_bits, Fobarray_make, Fobarrayp, Fobarray_clear): New.
* etc/emacs_lldb.py (Lisp_Object):
* lisp/emacs-lisp/cl-macs.el (`(,type . ,pred)):
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types):
* lisp/emacs-lisp/comp-common.el (comp-known-type-specifiers):
* lisp/emacs-lisp/comp.el (comp-known-predicates):
* src/alloc.c (cleanup_vector, process_mark_stack):
* src/data.c (Ftype_of, syms_of_data):
* src/minibuf.c (Ftry_completion, Fall_completions, Ftest_completion):
* src/pdumper.c (dump_obarray_buckets, dump_obarray, dump_vectorlike):
* src/print.c (print_vectorlike_unreadable):
* test/lisp/abbrev-tests.el (abbrev-make-abbrev-table-test):
* test/lisp/obarray-tests.el (obarrayp-test)
(obarrayp-unchecked-content-test, obarray-make-default-test)
(obarray-make-with-size-test):
Adapt to new type.
2024-02-10 21:14:09 +01:00
|
|
|
(should (abbrev-table-p table)))
|
2015-11-08 19:19:15 +01:00
|
|
|
;; Table with one property 'foo with value 'bar:
|
|
|
|
(let ((table (make-abbrev-table '(foo bar))))
|
|
|
|
(should (abbrev-table-p table))
|
|
|
|
(should (eq (abbrev-table-get table 'foo) 'bar))))
|
|
|
|
|
2018-09-29 15:19:04 -07:00
|
|
|
(ert-deftest abbrev--table-symbols-test ()
|
|
|
|
(let ((ert-test-abbrevs (setup-test-abbrev-table)))
|
|
|
|
(define-abbrev ert-test-abbrevs "sys" "system abbrev" nil :system t)
|
|
|
|
(should (equal (mapcar #'symbol-name (abbrev--table-symbols 'ert-test-abbrevs))
|
|
|
|
'("a-e-t")))
|
2020-12-09 00:54:34 +00:00
|
|
|
(let ((syms (abbrev--table-symbols 'ert-test-abbrevs t)))
|
|
|
|
(should (equal (sort (mapcar #'symbol-name syms) #'string<)
|
|
|
|
'("a-e-t" "sys"))))))
|
2018-09-29 15:19:04 -07:00
|
|
|
|
2015-11-08 19:19:15 +01:00
|
|
|
(ert-deftest abbrev-table-get-put-test ()
|
|
|
|
(let ((table (make-abbrev-table)))
|
|
|
|
(should-not (abbrev-table-get table 'foo))
|
|
|
|
(should (= (abbrev-table-put table 'foo 42) 42))
|
|
|
|
(should (= (abbrev-table-get table 'foo) 42))
|
|
|
|
(should (eq (abbrev-table-put table 'foo 'bar) 'bar))
|
|
|
|
(should (eq (abbrev-table-get table 'foo) 'bar))))
|
|
|
|
|
2015-11-07 13:32:33 +02:00
|
|
|
(ert-deftest copy-abbrev-table-test ()
|
|
|
|
(defvar foo-abbrev-table nil) ; Avoid compiler warning
|
|
|
|
(define-abbrev-table 'foo-abbrev-table
|
|
|
|
'())
|
|
|
|
(should (abbrev-table-p foo-abbrev-table))
|
|
|
|
;; Bug 21828
|
|
|
|
(let ((new-foo-abbrev-table
|
|
|
|
(condition-case nil
|
|
|
|
(copy-abbrev-table foo-abbrev-table)
|
|
|
|
(error nil))))
|
|
|
|
(should (abbrev-table-p new-foo-abbrev-table)))
|
|
|
|
(should-not (string-equal (buffer-name) "*Backtrace*")))
|
|
|
|
|
2016-05-03 00:12:53 +02:00
|
|
|
(ert-deftest abbrev-table-empty-p-test ()
|
|
|
|
(should-error (abbrev-table-empty-p 42))
|
|
|
|
(should-error (abbrev-table-empty-p "aoeu"))
|
|
|
|
(should-error (abbrev-table-empty-p '()))
|
|
|
|
(should-error (abbrev-table-empty-p []))
|
|
|
|
;; Missing :abbrev-table-modiff counter:
|
|
|
|
(should-error (abbrev-table-empty-p (obarray-make)))
|
|
|
|
(let* ((table (obarray-make)))
|
|
|
|
(abbrev-table-put table :abbrev-table-modiff 42)
|
|
|
|
(should (abbrev-table-empty-p table))))
|
|
|
|
|
2015-11-26 15:38:09 +09:00
|
|
|
(ert-deftest kill-all-abbrevs-test ()
|
2021-09-14 08:43:18 +02:00
|
|
|
"Test undefining all defined abbrevs."
|
2015-11-26 15:38:09 +09:00
|
|
|
(unless noninteractive
|
|
|
|
(ert-skip "Cannot test kill-all-abbrevs in interactive mode"))
|
|
|
|
|
|
|
|
(let ((num-tables 0))
|
|
|
|
;; ensure at least one abbrev exists
|
|
|
|
(should (abbrev-table-p (setup-test-abbrev-table)))
|
|
|
|
(setf num-tables (length abbrev-table-name-list))
|
|
|
|
(kill-all-abbrevs)
|
|
|
|
|
|
|
|
;; no tables should have been removed/added
|
|
|
|
(should (= num-tables (length abbrev-table-name-list)))
|
|
|
|
;; number of empty tables should be the same as number of tables
|
|
|
|
(should (= num-tables (length (seq-filter
|
|
|
|
(lambda (table)
|
|
|
|
(abbrev-table-empty-p (symbol-value table)))
|
|
|
|
abbrev-table-name-list))))))
|
|
|
|
|
|
|
|
(ert-deftest abbrev-table-name-test ()
|
2021-09-14 08:43:18 +02:00
|
|
|
"Test returning name of abbrev-table."
|
2015-11-26 15:38:09 +09:00
|
|
|
(let ((ert-test-abbrevs (setup-test-abbrev-table))
|
|
|
|
(no-such-table nil))
|
|
|
|
(should (equal 'ert-test-abbrevs (abbrev-table-name ert-test-abbrevs)))
|
|
|
|
(should (equal nil (abbrev-table-name no-such-table)))))
|
|
|
|
|
|
|
|
(ert-deftest clear-abbrev-table-test ()
|
2021-09-14 08:43:18 +02:00
|
|
|
"Test clearing single abbrev table."
|
2015-11-26 15:38:09 +09:00
|
|
|
(let ((ert-test-abbrevs (setup-test-abbrev-table)))
|
2016-05-03 00:12:53 +02:00
|
|
|
(should (equal "abbrev-ert-test" (abbrev-expansion "a-e-t" ert-test-abbrevs)))
|
|
|
|
(clear-abbrev-table ert-test-abbrevs)
|
|
|
|
(should (equal nil (abbrev-expansion "a-e-t" ert-test-abbrevs)))
|
|
|
|
(should (equal t (abbrev-table-empty-p ert-test-abbrevs)))))
|
|
|
|
|
|
|
|
(ert-deftest list-abbrevs-test ()
|
2021-09-14 08:43:18 +02:00
|
|
|
"Test generation of abbrev list buffer."
|
2016-05-03 00:12:53 +02:00
|
|
|
;; Somewhat redundant as prepare-abbrev-list-buffer is also tested.
|
|
|
|
;; all abbrevs
|
|
|
|
(let ((abbrev-buffer (prepare-abbrev-list-buffer)))
|
|
|
|
(should (equal "*Abbrevs*" (buffer-name abbrev-buffer)))
|
|
|
|
(kill-buffer abbrev-buffer))
|
|
|
|
;; mode-specific abbrevs
|
|
|
|
(let ((abbrev-buffer (prepare-abbrev-list-buffer t)))
|
|
|
|
(should (equal "*Abbrevs*" (buffer-name abbrev-buffer)))
|
|
|
|
(kill-buffer abbrev-buffer)))
|
|
|
|
|
|
|
|
(ert-deftest prepare-abbrev-list-buffer-test ()
|
2021-09-14 08:43:18 +02:00
|
|
|
"Test generation of abbrev list buffer."
|
2016-05-03 00:12:53 +02:00
|
|
|
;; all abbrevs
|
|
|
|
(let ((ert-test-abbrevs (setup-test-abbrev-table)))
|
|
|
|
(with-current-buffer (prepare-abbrev-list-buffer)
|
|
|
|
;; Check for a couple of abbrev-table names in buffer.
|
|
|
|
(should (and (progn
|
|
|
|
(goto-char (point-min))
|
|
|
|
(search-forward (symbol-name (abbrev-table-name ert-test-abbrevs))))
|
|
|
|
(progn
|
|
|
|
(goto-char (point-min))
|
|
|
|
(search-forward "global-abbrev-table"))))
|
|
|
|
(should (equal 'edit-abbrevs-mode major-mode))
|
|
|
|
(kill-buffer "*Abbrevs*")))
|
|
|
|
|
|
|
|
;; mode-specific abbrevs (temp buffer uses fundamental-mode)
|
|
|
|
(with-temp-buffer
|
|
|
|
(prepare-abbrev-list-buffer t)
|
|
|
|
(with-current-buffer "*Abbrevs*"
|
|
|
|
(should (progn
|
|
|
|
(goto-char (point-min))
|
|
|
|
(search-forward "fundamental-mode-abbrev-table")))
|
|
|
|
(should-error (progn
|
|
|
|
(goto-char (point-min))
|
|
|
|
(search-forward "global-abbrev-table")))
|
|
|
|
(should-not (equal 'edit-abbrevs-mode major-mode))
|
|
|
|
(kill-buffer "*Abbrevs*"))))
|
|
|
|
|
|
|
|
(ert-deftest insert-abbrevs-test ()
|
2021-09-14 08:43:18 +02:00
|
|
|
"Test inserting abbrev definitions into buffer."
|
2016-05-03 00:12:53 +02:00
|
|
|
(with-temp-buffer
|
|
|
|
(insert-abbrevs)
|
|
|
|
(should (progn
|
|
|
|
(goto-char (point-min))
|
|
|
|
(search-forward "global-abbrev-table")))))
|
|
|
|
|
|
|
|
(ert-deftest edit-abbrevs-test ()
|
2021-09-14 08:43:18 +02:00
|
|
|
"Test editing abbrevs from buffer."
|
2016-05-03 00:12:53 +02:00
|
|
|
(defvar ert-edit-abbrevs-test-table nil)
|
|
|
|
(let ((ert-test-abbrevs (setup-test-abbrev-table)))
|
|
|
|
(with-temp-buffer
|
|
|
|
;; insert test table and new abbrev, redefine, check definition
|
|
|
|
(goto-char (point-min))
|
|
|
|
(insert "(ert-edit-abbrevs-test-table)\n")
|
|
|
|
(insert "\n" "\"e-a-t\"\t" "0\t" "\"edit-abbrevs-test\"\n")
|
|
|
|
;; check test table before redefine
|
|
|
|
(should (equal "abbrev-ert-test"
|
|
|
|
(abbrev-expansion "a-e-t" ert-test-abbrevs)))
|
|
|
|
(edit-abbrevs-redefine)
|
|
|
|
(should-not (abbrev-expansion "a-e-t" ert-test-abbrevs))
|
|
|
|
(should (equal "edit-abbrevs-test"
|
|
|
|
(abbrev-expansion "e-a-t" ert-edit-abbrevs-test-table))))))
|
|
|
|
|
|
|
|
(ert-deftest define-abbrevs-test ()
|
2021-09-14 08:43:18 +02:00
|
|
|
"Test defining abbrevs from buffer."
|
2016-05-03 00:12:53 +02:00
|
|
|
(defvar ert-bad-abbrev-table nil)
|
|
|
|
(defvar ert-good-abbrev-table nil)
|
|
|
|
(defvar ert-redefine-abbrev-table nil)
|
|
|
|
(with-temp-buffer
|
|
|
|
;; insert bad abbrev data and attempt define
|
|
|
|
(goto-char (point-min))
|
|
|
|
(insert "ert-bad-abbrev-table\n")
|
|
|
|
(insert "\n" "\"b-a-t\"\t" "0\t" "\n")
|
|
|
|
(should-not (define-abbrevs))
|
|
|
|
(should (equal nil (abbrev-expansion "b-a-t" ert-bad-abbrev-table)))
|
|
|
|
(delete-region (point-min) (point-max))
|
|
|
|
;; try with valid abbrev data
|
|
|
|
(goto-char (point-min))
|
|
|
|
(insert "(ert-good-abbrev-table)\n")
|
|
|
|
(insert "\n" "\"g-a-t\"\t" "0\t" "\"good-abbrev-table\"\n")
|
|
|
|
(define-abbrevs)
|
|
|
|
(should (equal "good-abbrev-table"
|
|
|
|
(abbrev-expansion "g-a-t" ert-good-abbrev-table)))
|
|
|
|
;; redefine from buffer
|
|
|
|
(delete-region (point-min) (point-max))
|
|
|
|
(insert "(ert-redefine-abbrev-table)\n")
|
|
|
|
(insert "\n" "\"r-a-t\"\t" "0\t" "\"redefine-abbrev-table\"\n")
|
|
|
|
;; arg = kill-all-abbrevs
|
|
|
|
(define-abbrevs t)
|
|
|
|
(should (equal "redefine-abbrev-table"
|
|
|
|
(abbrev-expansion "r-a-t" ert-redefine-abbrev-table)))
|
|
|
|
(should (equal nil (abbrev-expansion "g-a-t" ert-good-abbrev-table)))))
|
2015-11-26 15:38:09 +09:00
|
|
|
|
2016-05-03 00:12:53 +02:00
|
|
|
(ert-deftest read-write-abbrev-file-test ()
|
2021-09-14 08:43:18 +02:00
|
|
|
"Test reading and writing abbrevs from file."
|
Prefer ert-with-temp-(directory|file)
* test/lisp/abbrev-tests.el (read-write-abbrev-file-test)
(read-write-abbrev-file-test-with-props)
(abbrev-edit-save-to-file-test):
* test/lisp/auth-source-tests.el (auth-source-test-netrc-create-secret)
(auth-source-delete):
* test/lisp/autoinsert-tests.el (autoinsert-tests-auto-insert-file):
* test/lisp/bookmark-tests.el (with-bookmark-test-save-load):
* test/lisp/buff-menu-tests.el (buff-menu-24962):
* test/lisp/calendar/icalendar-tests.el (icalendar-tests--do-test-export):
* test/lisp/calendar/todo-mode-tests.el (with-todo-test):
* test/lisp/dired-tests.el
(dired-test-bug27243-01, dired-test-bug27243-02)
(dired-test-bug27243-03, dired-test-bug27631)
(dired-test-bug27968, dired-test-with-temp-dirs):
* test/lisp/dired-x-tests.el (dired-test-bug25942):
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-tests--with-temp-file):
* test/lisp/emacs-lisp/check-declare-tests.el (check-declare-tests-scan)
(check-declare-tests-verify-mismatch):
* test/lisp/emacs-lisp/edebug-tests.el (edebug-tests-with-normal-env):
* test/lisp/emacs-lisp/package-tests.el (with-package-test)
(package-test-signed):
* test/lisp/emacs-lisp/testcover-tests.el (testcover-tests-markup-region)
(testcover-tests-run-test-case):
* test/lisp/emulation/viper-tests.el (viper-test-undo-kmacro):
* test/lisp/epg-tests.el (with-epg-tests):
* test/lisp/eshell/em-hist-tests.el (eshell-write-readonly-history):
* test/lisp/eshell/em-ls-tests.el (em-ls-test-bug27631):
* test/lisp/ffap-tests.el (ffap-tests-25243):
* test/lisp/files-tests.el (files-tests-bug-18141)
(files-tests-read-file-in-~, files-tests-make-directory)
(files-tests-copy-directory, files-tests-executable-find)
(files-tests-dont-rewrite-precious-files)
(files-tests--save-some-buffers):
* test/lisp/ls-lisp-tests.el (ls-lisp-test-bug27631):
* test/lisp/mail/uudecode-tests.el (uudecode-tests-decode-region-internal)
(uudecode-tests-decode-region-external):
* test/lisp/net/browse-url-tests.el (browse-url-tests-delete-temp-file):
* test/lisp/progmodes/elisp-mode-tests.el (xref--case-insensitive):
* test/lisp/progmodes/etags-tests.el (etags-buffer-local-tags-table-list):
* test/lisp/progmodes/flymake-tests.el (ruby-backend):
* test/lisp/progmodes/python-tests.el (python-tests-with-temp-file):
* test/lisp/progmodes/sql-tests.el (with-sql-test-connect-harness):
* test/lisp/saveplace-tests.el (saveplace-test-save-place-to-alist/file)
(saveplace-test-forget-unreadable-files)
(saveplace-test-place-alist-to-file):
* test/lisp/so-long-tests/spelling-tests.el:
* test/lisp/textmodes/reftex-tests.el (reftex-locate-bibliography-files)
(reftex-parse-from-file-test):
* test/lisp/thumbs-tests.el (thumbs-tests-thumbsdir/create-if-missing):
* test/lisp/vc/vc-bzr-tests.el (vc-bzr-test-bug9726)
(vc-bzr-test-bug9781, vc-bzr-test-faulty-bzr-autoloads):
* test/lisp/vc/diff-mode-tests.el (diff-mode-test-ignore-trailing-dashes):
* test/lisp/vc/ediff-ptch-tests.el (ediff-ptch-test-bug26084):
* test/lisp/wdired-tests.el (wdired-test-bug32173-01)
(wdired-test-bug32173-02, wdired-test-symlink-name)
(wdired-test-unfinished-edit-01, wdired-test-bug34915)
(wdired-test-bug39280):
* test/src/buffer-tests.el (test-kill-buffer-auto-save-default):
* test/src/filelock-tests.el (filelock-tests--fixture):
* test/src/inotify-tests.el (inotify-file-watch-simple):
* test/src/undo-tests.el (undo-test-file-modified): Prefer
'ert-with-temp-(directory|file)' to using 'make-temp-file' directly.
In some cases, this is just cleanup, but in several cases this fixes
bugs where an error would have lead to us not cleaning up.
2021-11-06 23:20:59 +01:00
|
|
|
(ert-with-temp-file temp-test-file
|
|
|
|
(let ((ert-test-abbrevs (setup-test-abbrev-table)))
|
|
|
|
(write-abbrev-file temp-test-file)
|
|
|
|
(clear-abbrev-table ert-test-abbrevs)
|
|
|
|
(should (abbrev-table-empty-p ert-test-abbrevs))
|
|
|
|
(read-abbrev-file temp-test-file)
|
|
|
|
(should (equal "abbrev-ert-test" (abbrev-expansion "a-e-t" ert-test-abbrevs))))))
|
2015-11-26 15:38:09 +09:00
|
|
|
|
2017-12-31 20:14:09 -08:00
|
|
|
(ert-deftest read-write-abbrev-file-test-with-props ()
|
2021-09-14 08:43:18 +02:00
|
|
|
"Test reading and writing abbrevs from file."
|
Prefer ert-with-temp-(directory|file)
* test/lisp/abbrev-tests.el (read-write-abbrev-file-test)
(read-write-abbrev-file-test-with-props)
(abbrev-edit-save-to-file-test):
* test/lisp/auth-source-tests.el (auth-source-test-netrc-create-secret)
(auth-source-delete):
* test/lisp/autoinsert-tests.el (autoinsert-tests-auto-insert-file):
* test/lisp/bookmark-tests.el (with-bookmark-test-save-load):
* test/lisp/buff-menu-tests.el (buff-menu-24962):
* test/lisp/calendar/icalendar-tests.el (icalendar-tests--do-test-export):
* test/lisp/calendar/todo-mode-tests.el (with-todo-test):
* test/lisp/dired-tests.el
(dired-test-bug27243-01, dired-test-bug27243-02)
(dired-test-bug27243-03, dired-test-bug27631)
(dired-test-bug27968, dired-test-with-temp-dirs):
* test/lisp/dired-x-tests.el (dired-test-bug25942):
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-tests--with-temp-file):
* test/lisp/emacs-lisp/check-declare-tests.el (check-declare-tests-scan)
(check-declare-tests-verify-mismatch):
* test/lisp/emacs-lisp/edebug-tests.el (edebug-tests-with-normal-env):
* test/lisp/emacs-lisp/package-tests.el (with-package-test)
(package-test-signed):
* test/lisp/emacs-lisp/testcover-tests.el (testcover-tests-markup-region)
(testcover-tests-run-test-case):
* test/lisp/emulation/viper-tests.el (viper-test-undo-kmacro):
* test/lisp/epg-tests.el (with-epg-tests):
* test/lisp/eshell/em-hist-tests.el (eshell-write-readonly-history):
* test/lisp/eshell/em-ls-tests.el (em-ls-test-bug27631):
* test/lisp/ffap-tests.el (ffap-tests-25243):
* test/lisp/files-tests.el (files-tests-bug-18141)
(files-tests-read-file-in-~, files-tests-make-directory)
(files-tests-copy-directory, files-tests-executable-find)
(files-tests-dont-rewrite-precious-files)
(files-tests--save-some-buffers):
* test/lisp/ls-lisp-tests.el (ls-lisp-test-bug27631):
* test/lisp/mail/uudecode-tests.el (uudecode-tests-decode-region-internal)
(uudecode-tests-decode-region-external):
* test/lisp/net/browse-url-tests.el (browse-url-tests-delete-temp-file):
* test/lisp/progmodes/elisp-mode-tests.el (xref--case-insensitive):
* test/lisp/progmodes/etags-tests.el (etags-buffer-local-tags-table-list):
* test/lisp/progmodes/flymake-tests.el (ruby-backend):
* test/lisp/progmodes/python-tests.el (python-tests-with-temp-file):
* test/lisp/progmodes/sql-tests.el (with-sql-test-connect-harness):
* test/lisp/saveplace-tests.el (saveplace-test-save-place-to-alist/file)
(saveplace-test-forget-unreadable-files)
(saveplace-test-place-alist-to-file):
* test/lisp/so-long-tests/spelling-tests.el:
* test/lisp/textmodes/reftex-tests.el (reftex-locate-bibliography-files)
(reftex-parse-from-file-test):
* test/lisp/thumbs-tests.el (thumbs-tests-thumbsdir/create-if-missing):
* test/lisp/vc/vc-bzr-tests.el (vc-bzr-test-bug9726)
(vc-bzr-test-bug9781, vc-bzr-test-faulty-bzr-autoloads):
* test/lisp/vc/diff-mode-tests.el (diff-mode-test-ignore-trailing-dashes):
* test/lisp/vc/ediff-ptch-tests.el (ediff-ptch-test-bug26084):
* test/lisp/wdired-tests.el (wdired-test-bug32173-01)
(wdired-test-bug32173-02, wdired-test-symlink-name)
(wdired-test-unfinished-edit-01, wdired-test-bug34915)
(wdired-test-bug39280):
* test/src/buffer-tests.el (test-kill-buffer-auto-save-default):
* test/src/filelock-tests.el (filelock-tests--fixture):
* test/src/inotify-tests.el (inotify-file-watch-simple):
* test/src/undo-tests.el (undo-test-file-modified): Prefer
'ert-with-temp-(directory|file)' to using 'make-temp-file' directly.
In some cases, this is just cleanup, but in several cases this fixes
bugs where an error would have lead to us not cleaning up.
2021-11-06 23:20:59 +01:00
|
|
|
(ert-with-temp-file temp-test-file
|
|
|
|
(let ((ert-test-abbrevs (setup-test-abbrev-table-with-props)))
|
|
|
|
(write-abbrev-file temp-test-file)
|
|
|
|
(clear-abbrev-table ert-test-abbrevs)
|
|
|
|
(should (abbrev-table-empty-p ert-test-abbrevs))
|
|
|
|
(read-abbrev-file temp-test-file)
|
|
|
|
(should (equal "fooBar" (abbrev-expansion "fb" ert-test-abbrevs))))))
|
2017-12-31 20:14:09 -08:00
|
|
|
|
2016-05-03 00:12:53 +02:00
|
|
|
(ert-deftest abbrev-edit-save-to-file-test ()
|
2021-09-14 08:43:18 +02:00
|
|
|
"Test saving abbrev definitions in buffer to file."
|
2016-05-03 00:12:53 +02:00
|
|
|
(defvar ert-save-test-table nil)
|
Prefer ert-with-temp-(directory|file)
* test/lisp/abbrev-tests.el (read-write-abbrev-file-test)
(read-write-abbrev-file-test-with-props)
(abbrev-edit-save-to-file-test):
* test/lisp/auth-source-tests.el (auth-source-test-netrc-create-secret)
(auth-source-delete):
* test/lisp/autoinsert-tests.el (autoinsert-tests-auto-insert-file):
* test/lisp/bookmark-tests.el (with-bookmark-test-save-load):
* test/lisp/buff-menu-tests.el (buff-menu-24962):
* test/lisp/calendar/icalendar-tests.el (icalendar-tests--do-test-export):
* test/lisp/calendar/todo-mode-tests.el (with-todo-test):
* test/lisp/dired-tests.el
(dired-test-bug27243-01, dired-test-bug27243-02)
(dired-test-bug27243-03, dired-test-bug27631)
(dired-test-bug27968, dired-test-with-temp-dirs):
* test/lisp/dired-x-tests.el (dired-test-bug25942):
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-tests--with-temp-file):
* test/lisp/emacs-lisp/check-declare-tests.el (check-declare-tests-scan)
(check-declare-tests-verify-mismatch):
* test/lisp/emacs-lisp/edebug-tests.el (edebug-tests-with-normal-env):
* test/lisp/emacs-lisp/package-tests.el (with-package-test)
(package-test-signed):
* test/lisp/emacs-lisp/testcover-tests.el (testcover-tests-markup-region)
(testcover-tests-run-test-case):
* test/lisp/emulation/viper-tests.el (viper-test-undo-kmacro):
* test/lisp/epg-tests.el (with-epg-tests):
* test/lisp/eshell/em-hist-tests.el (eshell-write-readonly-history):
* test/lisp/eshell/em-ls-tests.el (em-ls-test-bug27631):
* test/lisp/ffap-tests.el (ffap-tests-25243):
* test/lisp/files-tests.el (files-tests-bug-18141)
(files-tests-read-file-in-~, files-tests-make-directory)
(files-tests-copy-directory, files-tests-executable-find)
(files-tests-dont-rewrite-precious-files)
(files-tests--save-some-buffers):
* test/lisp/ls-lisp-tests.el (ls-lisp-test-bug27631):
* test/lisp/mail/uudecode-tests.el (uudecode-tests-decode-region-internal)
(uudecode-tests-decode-region-external):
* test/lisp/net/browse-url-tests.el (browse-url-tests-delete-temp-file):
* test/lisp/progmodes/elisp-mode-tests.el (xref--case-insensitive):
* test/lisp/progmodes/etags-tests.el (etags-buffer-local-tags-table-list):
* test/lisp/progmodes/flymake-tests.el (ruby-backend):
* test/lisp/progmodes/python-tests.el (python-tests-with-temp-file):
* test/lisp/progmodes/sql-tests.el (with-sql-test-connect-harness):
* test/lisp/saveplace-tests.el (saveplace-test-save-place-to-alist/file)
(saveplace-test-forget-unreadable-files)
(saveplace-test-place-alist-to-file):
* test/lisp/so-long-tests/spelling-tests.el:
* test/lisp/textmodes/reftex-tests.el (reftex-locate-bibliography-files)
(reftex-parse-from-file-test):
* test/lisp/thumbs-tests.el (thumbs-tests-thumbsdir/create-if-missing):
* test/lisp/vc/vc-bzr-tests.el (vc-bzr-test-bug9726)
(vc-bzr-test-bug9781, vc-bzr-test-faulty-bzr-autoloads):
* test/lisp/vc/diff-mode-tests.el (diff-mode-test-ignore-trailing-dashes):
* test/lisp/vc/ediff-ptch-tests.el (ediff-ptch-test-bug26084):
* test/lisp/wdired-tests.el (wdired-test-bug32173-01)
(wdired-test-bug32173-02, wdired-test-symlink-name)
(wdired-test-unfinished-edit-01, wdired-test-bug34915)
(wdired-test-bug39280):
* test/src/buffer-tests.el (test-kill-buffer-auto-save-default):
* test/src/filelock-tests.el (filelock-tests--fixture):
* test/src/inotify-tests.el (inotify-file-watch-simple):
* test/src/undo-tests.el (undo-test-file-modified): Prefer
'ert-with-temp-(directory|file)' to using 'make-temp-file' directly.
In some cases, this is just cleanup, but in several cases this fixes
bugs where an error would have lead to us not cleaning up.
2021-11-06 23:20:59 +01:00
|
|
|
(ert-with-temp-file temp-test-file
|
|
|
|
(let ((ert-test-abbrevs (setup-test-abbrev-table)))
|
|
|
|
(with-temp-buffer
|
|
|
|
(goto-char (point-min))
|
|
|
|
(insert "(ert-save-test-table)\n")
|
|
|
|
(insert "\n" "\"s-a-t\"\t" "0\t" "\"save-abbrevs-test\"\n")
|
|
|
|
(should (equal "abbrev-ert-test"
|
|
|
|
(abbrev-expansion "a-e-t" ert-test-abbrevs)))
|
|
|
|
;; clears abbrev tables
|
|
|
|
(abbrev-edit-save-to-file temp-test-file)
|
|
|
|
(should-not (abbrev-expansion "a-e-t" ert-test-abbrevs))
|
|
|
|
(read-abbrev-file temp-test-file)
|
|
|
|
(should (equal "save-abbrevs-test"
|
|
|
|
(abbrev-expansion "s-a-t" ert-save-test-table)))))))
|
2015-11-26 15:38:09 +09:00
|
|
|
|
2019-06-16 03:32:02 -07:00
|
|
|
(ert-deftest inverse-add-abbrev-skips-trailing-nonword ()
|
|
|
|
"Test that adding an inverse abbrev skips trailing nonword characters."
|
|
|
|
(let ((table (make-abbrev-table)))
|
|
|
|
(with-temp-buffer
|
|
|
|
(insert "some text foo ")
|
|
|
|
(cl-letf (((symbol-function 'read-string) (lambda (&rest _) "bar")))
|
|
|
|
(inverse-add-abbrev table "Global" 1)))
|
|
|
|
(should (string= (abbrev-expansion "foo" table) "bar"))))
|
|
|
|
|
2019-12-10 20:04:36 -08:00
|
|
|
(ert-deftest inverse-add-abbrev-skips-trailing-nonword/positive-arg ()
|
2019-06-16 03:32:02 -07:00
|
|
|
"Test that adding an inverse abbrev skips trailing nonword characters."
|
|
|
|
(let ((table (make-abbrev-table)))
|
|
|
|
(with-temp-buffer
|
|
|
|
(insert "some text foo ")
|
|
|
|
(cl-letf (((symbol-function 'read-string) (lambda (&rest _) "bar")))
|
|
|
|
(inverse-add-abbrev table "Global" 2)))
|
|
|
|
(should (string= (abbrev-expansion "text" table) "bar"))))
|
|
|
|
|
|
|
|
(ert-deftest inverse-add-abbrev-skips-trailing-nonword/negative-arg ()
|
|
|
|
"Test that adding an inverse abbrev skips trailing nonword characters."
|
|
|
|
(let ((table (make-abbrev-table)))
|
|
|
|
(with-temp-buffer
|
|
|
|
(insert "some text foo")
|
|
|
|
(goto-char (point-min))
|
|
|
|
(cl-letf (((symbol-function 'read-string) (lambda (&rest _) "bar")))
|
|
|
|
(inverse-add-abbrev table "Global" -1)))
|
|
|
|
(should (string= (abbrev-expansion "text" table) "bar"))))
|
|
|
|
|
2022-02-14 12:00:22 +01:00
|
|
|
(ert-deftest test-abbrev-table-p ()
|
|
|
|
(should-not (abbrev-table-p translation-table-vector))
|
|
|
|
(should (abbrev-table-p (make-abbrev-table))))
|
|
|
|
|
2023-03-15 21:04:26 +03:00
|
|
|
(ert-deftest abbrev--possibly-save-test ()
|
|
|
|
"Test that `abbrev--possibly-save' properly resets
|
|
|
|
`abbrevs-changed'."
|
|
|
|
(ert-with-temp-file temp-test-file
|
|
|
|
(let ((abbrev-file-name temp-test-file)
|
|
|
|
(save-abbrevs t))
|
|
|
|
;; Save
|
|
|
|
(let ((abbrevs-changed t))
|
|
|
|
(should-not (abbrev--possibly-save nil t))
|
|
|
|
(should-not abbrevs-changed))
|
|
|
|
;; Don't save
|
|
|
|
(let ((abbrevs-changed t))
|
2023-03-18 12:35:10 +02:00
|
|
|
(ert-simulate-keys '(?n ?\C-m)
|
2023-03-15 21:04:26 +03:00
|
|
|
(should (abbrev--possibly-save nil)))
|
|
|
|
(should-not abbrevs-changed)))))
|
|
|
|
|
2015-11-07 13:32:33 +02:00
|
|
|
(provide 'abbrev-tests)
|
2016-05-03 00:12:53 +02:00
|
|
|
|
2015-11-08 05:43:00 +02:00
|
|
|
;;; abbrev-tests.el ends here
|