summaryrefslogtreecommitdiff
path: root/test/lisp/abbrev-tests.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2022-09-25 16:15:16 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2022-09-25 16:15:16 -0400
commit650c20f1ca4e07591a727e1cfcc74b3363d15985 (patch)
tree85d11f6437cde22f410c25e0e5f71a3131ebd07d /test/lisp/abbrev-tests.el
parent8869332684c2302b5ba1ead4568bbc7ba1c0183e (diff)
parent4b85ae6a24380fb67a3315eaec9233f17a872473 (diff)
downloademacs-650c20f1ca4e07591a727e1cfcc74b3363d15985.tar.gz
emacs-650c20f1ca4e07591a727e1cfcc74b3363d15985.tar.bz2
emacs-650c20f1ca4e07591a727e1cfcc74b3363d15985.zip
Merge 'master' into noverlay
Diffstat (limited to 'test/lisp/abbrev-tests.el')
-rw-r--r--test/lisp/abbrev-tests.el120
1 files changed, 88 insertions, 32 deletions
diff --git a/test/lisp/abbrev-tests.el b/test/lisp/abbrev-tests.el
index 1f1a7fb6bb6..947178473e4 100644
--- a/test/lisp/abbrev-tests.el
+++ b/test/lisp/abbrev-tests.el
@@ -1,6 +1,6 @@
;;; abbrev-tests.el --- Test suite for abbrevs -*- lexical-binding: t; -*-
-;; Copyright (C) 2015-2017 Free Software Foundation, Inc.
+;; Copyright (C) 2015-2022 Free Software Foundation, Inc.
;; Author: Eli Zaretskii <eliz@gnu.org>
;; Keywords: abbrevs
@@ -28,6 +28,7 @@
;;; Code:
(require 'ert)
+(require 'ert-x)
(require 'abbrev)
(require 'seq)
@@ -38,6 +39,12 @@
(abbrev-table-put ert-test-abbrevs :ert-test "ert-test-value")
ert-test-abbrevs)
+(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)
+
(ert-deftest abbrev-table-p-test ()
(should-not (abbrev-table-p 42))
(should-not (abbrev-table-p "aoeu"))
@@ -58,6 +65,15 @@
(should (= (length table) obarray-default-size))
(should (eq (abbrev-table-get table 'foo) 'bar))))
+(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")))
+ (let ((syms (abbrev--table-symbols 'ert-test-abbrevs t)))
+ (should (equal (sort (mapcar #'symbol-name syms) #'string<)
+ '("a-e-t" "sys"))))))
+
(ert-deftest abbrev-table-get-put-test ()
(let ((table (make-abbrev-table)))
(should-not (abbrev-table-get table 'foo))
@@ -91,7 +107,7 @@
(should (abbrev-table-empty-p table))))
(ert-deftest kill-all-abbrevs-test ()
- "Test undefining all defined abbrevs"
+ "Test undefining all defined abbrevs."
(unless noninteractive
(ert-skip "Cannot test kill-all-abbrevs in interactive mode"))
@@ -110,14 +126,14 @@
abbrev-table-name-list))))))
(ert-deftest abbrev-table-name-test ()
- "Test returning name of abbrev-table"
+ "Test returning name of abbrev-table."
(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 ()
- "Test clearing single abbrev table"
+ "Test clearing single abbrev table."
(let ((ert-test-abbrevs (setup-test-abbrev-table)))
(should (equal "abbrev-ert-test" (abbrev-expansion "a-e-t" ert-test-abbrevs)))
(clear-abbrev-table ert-test-abbrevs)
@@ -125,7 +141,7 @@
(should (equal t (abbrev-table-empty-p ert-test-abbrevs)))))
(ert-deftest list-abbrevs-test ()
- "Test generation of abbrev list buffer"
+ "Test generation of abbrev list buffer."
;; Somewhat redundant as prepare-abbrev-list-buffer is also tested.
;; all abbrevs
(let ((abbrev-buffer (prepare-abbrev-list-buffer)))
@@ -137,7 +153,7 @@
(kill-buffer abbrev-buffer)))
(ert-deftest prepare-abbrev-list-buffer-test ()
- "Test generation of abbrev list buffer"
+ "Test generation of abbrev list buffer."
;; all abbrevs
(let ((ert-test-abbrevs (setup-test-abbrev-table)))
(with-current-buffer (prepare-abbrev-list-buffer)
@@ -165,7 +181,7 @@
(kill-buffer "*Abbrevs*"))))
(ert-deftest insert-abbrevs-test ()
- "Test inserting abbrev definitions into buffer"
+ "Test inserting abbrev definitions into buffer."
(with-temp-buffer
(insert-abbrevs)
(should (progn
@@ -173,7 +189,7 @@
(search-forward "global-abbrev-table")))))
(ert-deftest edit-abbrevs-test ()
- "Test editing abbrevs from buffer"
+ "Test editing abbrevs from buffer."
(defvar ert-edit-abbrevs-test-table nil)
(let ((ert-test-abbrevs (setup-test-abbrev-table)))
(with-temp-buffer
@@ -190,7 +206,7 @@
(abbrev-expansion "e-a-t" ert-edit-abbrevs-test-table))))))
(ert-deftest define-abbrevs-test ()
- "Test defining abbrevs from buffer"
+ "Test defining abbrevs from buffer."
(defvar ert-bad-abbrev-table nil)
(defvar ert-good-abbrev-table nil)
(defvar ert-redefine-abbrev-table nil)
@@ -220,34 +236,74 @@
(should (equal nil (abbrev-expansion "g-a-t" ert-good-abbrev-table)))))
(ert-deftest read-write-abbrev-file-test ()
- "Test reading and writing abbrevs from file"
- (let ((temp-test-file (make-temp-file "ert-abbrev-test"))
- (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)))
- (delete-file temp-test-file)))
+ "Test reading and writing abbrevs from file."
+ (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))))))
+
+(ert-deftest read-write-abbrev-file-test-with-props ()
+ "Test reading and writing abbrevs from file."
+ (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))))))
(ert-deftest abbrev-edit-save-to-file-test ()
- "Test saving abbrev definitions in buffer to file"
+ "Test saving abbrev definitions in buffer to file."
(defvar ert-save-test-table nil)
- (let ((temp-test-file (make-temp-file "ert-abbrev-test"))
- (ert-test-abbrevs (setup-test-abbrev-table)))
+ (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)))))))
+
+(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"))))
+
+(ert-deftest inverse-add-abbrev-skips-trailing-nonword/positive-arg ()
+ "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))
- (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)))
- (delete-file temp-test-file))))
+ (cl-letf (((symbol-function 'read-string) (lambda (&rest _) "bar")))
+ (inverse-add-abbrev table "Global" -1)))
+ (should (string= (abbrev-expansion "text" table) "bar"))))
+
+(ert-deftest test-abbrev-table-p ()
+ (should-not (abbrev-table-p translation-table-vector))
+ (should (abbrev-table-p (make-abbrev-table))))
(provide 'abbrev-tests)