diff options
| author | Mark Oteiza | 2017-09-05 11:53:37 -0400 |
|---|---|---|
| committer | Mark Oteiza | 2017-09-05 11:55:01 -0400 |
| commit | 9f64d59ae6d87f38276fe05254094113a171fb0e (patch) | |
| tree | b2cf026ff90bc91d7e336a8825fc631d09caf50f | |
| parent | 8d251607e08e1ea4df201928b5bee21782a6526e (diff) | |
| download | emacs-9f64d59ae6d87f38276fe05254094113a171fb0e.tar.gz emacs-9f64d59ae6d87f38276fe05254094113a171fb0e.zip | |
Add tests for mailcap.el
* test/data/mailcap/mime.types: New file.
* test/lisp/net/mailcap-tests.el: New file.
| -rw-r--r-- | test/data/mailcap/mime.types | 5 | ||||
| -rw-r--r-- | test/lisp/net/mailcap-tests.el | 69 |
2 files changed, 74 insertions, 0 deletions
diff --git a/test/data/mailcap/mime.types b/test/data/mailcap/mime.types new file mode 100644 index 00000000000..4bedfaf9702 --- /dev/null +++ b/test/data/mailcap/mime.types | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # this is a comment | ||
| 2 | |||
| 3 | audio/ogg opus | ||
| 4 | audio/flac flac | ||
| 5 | audio/x-wav wav | ||
diff --git a/test/lisp/net/mailcap-tests.el b/test/lisp/net/mailcap-tests.el new file mode 100644 index 00000000000..9e32931ff7e --- /dev/null +++ b/test/lisp/net/mailcap-tests.el | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | ;;; mailcap-tests.el --- tests for mailcap.el -*- lexical-binding: t -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2017 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Mark Oteiza <mvoteiza@udel.edu> | ||
| 6 | |||
| 7 | ;; This file is part of GNU Emacs. | ||
| 8 | |||
| 9 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 10 | ;; it under the terms of the GNU General Public License as published by | ||
| 11 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 12 | ;; (at your option) any later version. | ||
| 13 | |||
| 14 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | ;; GNU General Public License for more details. | ||
| 18 | |||
| 19 | ;; You should have received a copy of the GNU General Public License | ||
| 20 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | |||
| 22 | ;;; Commentary: | ||
| 23 | |||
| 24 | ;;; Code: | ||
| 25 | |||
| 26 | (require 'ert) | ||
| 27 | (require 'mailcap) | ||
| 28 | |||
| 29 | (defconst mailcap-tests-data-dir | ||
| 30 | (expand-file-name "test/data/mailcap" source-directory)) | ||
| 31 | |||
| 32 | (defconst mailcap-tests-path | ||
| 33 | (expand-file-name "mime.types" mailcap-tests-data-dir) | ||
| 34 | "String used as PATH argument of `mailcap-parse-mimetypes'.") | ||
| 35 | |||
| 36 | (defconst mailcap-tests-mime-extensions (copy-alist mailcap-mime-extensions)) | ||
| 37 | |||
| 38 | (defconst mailcap-tests-path-extensions | ||
| 39 | '((".wav" . "audio/x-wav") | ||
| 40 | (".flac" . "audio/flac") | ||
| 41 | (".opus" . "audio/ogg")) | ||
| 42 | "Alist of MIME associations in `mailcap-tests-path'.") | ||
| 43 | |||
| 44 | (ert-deftest mailcap-mimetypes-parsed-p () | ||
| 45 | (should (null mailcap-mimetypes-parsed-p))) | ||
| 46 | |||
| 47 | (ert-deftest mailcap-parse-empty-path () | ||
| 48 | "If PATH is empty, this should be a noop." | ||
| 49 | (mailcap-parse-mimetypes "file/that/should/not/exist" t) | ||
| 50 | (should mailcap-mimetypes-parsed-p) | ||
| 51 | (should (equal mailcap-mime-extensions mailcap-tests-mime-extensions))) | ||
| 52 | |||
| 53 | (ert-deftest mailcap-parse-path () | ||
| 54 | (let ((mimetypes (getenv "MIMETYPES"))) | ||
| 55 | (unwind-protect | ||
| 56 | (progn | ||
| 57 | (setenv "MIMETYPES" mailcap-tests-path) | ||
| 58 | (mailcap-parse-mimetypes nil t)) | ||
| 59 | (setenv "MIMETYPES" mimetypes))) | ||
| 60 | (should (equal mailcap-mime-extensions | ||
| 61 | (append mailcap-tests-path-extensions | ||
| 62 | mailcap-tests-mime-extensions))) | ||
| 63 | ;; Already parsed this, should be a noop | ||
| 64 | (mailcap-parse-mimetypes mailcap-tests-path) | ||
| 65 | (should (equal mailcap-mime-extensions | ||
| 66 | (append mailcap-tests-path-extensions | ||
| 67 | mailcap-tests-mime-extensions)))) | ||
| 68 | |||
| 69 | ;;; mailcap-tests.el ends here | ||