diff options
author | Jim Porter <jporterbugs@gmail.com> | 2021-11-07 18:03:23 +0100 |
---|---|---|
committer | Michael Albinus <michael.albinus@gmx.de> | 2021-11-07 18:03:23 +0100 |
commit | 7fdb2ae412d4b727c6075ff3988836841b052120 (patch) | |
tree | af9073fbd4f461053d200171732d8bc562145e71 /test/lisp/files-tests.el | |
parent | 21de5e7b2e55d98aab9750abac6f70243fd1b61d (diff) | |
download | emacs-7fdb2ae412d4b727c6075ff3988836841b052120.tar.gz |
Add some unit tests for 'abbreviate-file-name'
* test/lisp/files-tests.el (files-tests-abbreviate-file-name-homedir)
(files-tests-abbreviate-file-name-directory-abbrev-alist): New tests.
Diffstat (limited to 'test/lisp/files-tests.el')
-rw-r--r-- | test/lisp/files-tests.el | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index b283a512a42..9547ac2b695 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -1342,6 +1342,39 @@ name (Bug#28412)." (should (file-directory-p (concat (file-name-as-directory dest2) "a"))) (delete-directory dir 'recursive))) +(ert-deftest files-tests-abbreviate-file-name-homedir () + ;; Check homedir abbreviation. + (let* ((homedir temporary-file-directory) + (process-environment (cons (format "HOME=%s" homedir) + process-environment)) + (abbreviated-home-dir nil)) + (should (equal "~/foo/bar" + (abbreviate-file-name (concat homedir "foo/bar"))))) + ;; Check that homedir abbreviation doesn't occur when homedir is just /. + (let* ((homedir "/") + (process-environment (cons (format "HOME=%s" homedir) + process-environment)) + (abbreviated-home-dir nil)) + (should (equal "/foo/bar" + (abbreviate-file-name (concat homedir "foo/bar")))))) + +(ert-deftest files-tests-abbreviate-file-name-directory-abbrev-alist () + ;; Check `directory-abbrev-alist' abbreviation. + (let ((directory-abbrev-alist '(("\\`/nowhere/special" . "/nw/sp")))) + (should (equal "/nw/sp/here" + (abbreviate-file-name "/nowhere/special/here")))) + ;; Check homedir and `directory-abbrev-alist' abbreviation. + (let* ((homedir temporary-file-directory) + (process-environment (cons (format "HOME=%s" homedir) + process-environment)) + (abbreviated-home-dir nil) + (directory-abbrev-alist + `((,(concat "\\`" (regexp-quote homedir) "nowhere/special") + . ,(concat homedir "nw/sp"))))) + (should (equal "~/nw/sp/here" + (abbreviate-file-name + (concat homedir "nowhere/special/here")))))) + (ert-deftest files-tests-abbreviated-home-dir () "Test that changing HOME does not confuse `abbreviate-file-name'. See <https://debbugs.gnu.org/19657#20>." |