aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorNicolas Petton2018-03-13 22:07:08 +0100
committerNicolas Petton2018-03-18 20:47:35 +0100
commit6d2b50a2451a9d7aae040cb82040c2211df75c85 (patch)
treed6beb72fc8f9da6e350cc056fa9d49b0be525560 /test
parent9942734c75c7b78efba41204432533cd3fe3b419 (diff)
downloademacs-6d2b50a2451a9d7aae040cb82040c2211df75c85.tar.gz
emacs-6d2b50a2451a9d7aae040cb82040c2211df75c85.zip
Add URL handler for file-name-directory (Bug#30444)
* lisp/url/url-handlers.el (url-handler-file-name-directory): New function which handles special cases for `file-name-directory' and URLs. * test/lisp/url/url-handlers-test.el: New file. Add tests for `url-handler-file-name-directory'.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/url/url-handlers-test.el75
1 files changed, 75 insertions, 0 deletions
diff --git a/test/lisp/url/url-handlers-test.el b/test/lisp/url/url-handlers-test.el
new file mode 100644
index 00000000000..5822e16a88a
--- /dev/null
+++ b/test/lisp/url/url-handlers-test.el
@@ -0,0 +1,75 @@
1;;; url-handlers-test.el --- Test suite for url-handlers.el -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2018 Free Software Foundation, Inc.
4
5;; Author: Nicolas Petton <nicolas@petton.fr>
6
7;; This program is free software; you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; This program is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with this program. If not, see <https://www.gnu.org/licenses/>.
19
20;;; Commentary:
21
22;;; Code:
23
24(require 'ert)
25(require 'url-handlers)
26
27(defmacro with-url-handler-mode (&rest body)
28 "Evaluate BODY with `url-handler-mode' turned on."
29 (declare (indent 0) (debug t))
30 (let ((url-handler-mode-active (make-symbol "url-handler-mode-active")))
31 `(let ((,url-handler-mode-active url-handler-mode))
32 (unwind-protect
33 (progn
34 (unless ,url-handler-mode-active
35 (url-handler-mode))
36 ,@body)
37 (unless ,url-handler-mode-active
38 (url-handler-mode -1))))))
39
40(ert-deftest url-handlers-file-name-directory/preserve-url-types ()
41 (with-url-handler-mode
42 (should (equal (file-name-directory "https://gnu.org/index.html")
43 "https://gnu.org/"))
44 (should (equal (file-name-directory "http://gnu.org/index.html")
45 "http://gnu.org/"))
46 (should (equal (file-name-directory "ftp://gnu.org/index.html")
47 "ftp://gnu.org/"))))
48
49(ert-deftest url-handlers-file-name-directory/should-not-handle-non-url-file-names ()
50 (with-url-handler-mode
51 (should-not (equal (file-name-directory "not-uri://gnu.org")
52 "not-uri://gnu.org/"))))
53
54(ert-deftest url-handlers-file-name-directory/sub-directories ()
55 (with-url-handler-mode
56 (should (equal (file-name-directory "https://foo/bar/baz/index.html")
57 "https://foo/bar/baz/"))))
58
59(ert-deftest url-handlers-file-name-directory/file-urls ()
60 (with-url-handler-mode
61 (should (equal (file-name-directory "file:///foo/bar/baz.txt")
62 "file:///foo/bar/"))
63 (should (equal (file-name-directory "file:///")
64 "file:///"))))
65
66;; Regression test for bug#30444
67(ert-deftest url-handlers-file-name-directory/no-filename ()
68 (with-url-handler-mode
69 (should (equal (file-name-directory "https://foo.org")
70 "https://foo.org/"))
71 (should (equal (file-name-directory "https://foo.org/")
72 "https://foo.org/"))))
73
74(provide 'url-handlers-test)
75;;; url-handlers-test.el ends here