diff options
| author | Stefan Kangas | 2019-06-09 17:05:15 -0700 |
|---|---|---|
| committer | Paul Eggert | 2019-06-09 17:07:09 -0700 |
| commit | 4503310cac33da4da74fd6376244da82c7134432 (patch) | |
| tree | 55596d1643c1dea1a30b1e42888aee0c101e78c7 | |
| parent | 45c525a685041c274a26c70caed4088726a790de (diff) | |
| download | emacs-4503310cac33da4da74fd6376244da82c7134432.tar.gz emacs-4503310cac33da4da74fd6376244da82c7134432.zip | |
Add tests for mail/uudecode.el
* lisp/mail/uudecode.el: Remove redundant :group usage.
* test/lisp/mail/uudecode-resources/uudecoded.txt,
test/lisp/mail/uudecode-resources/uuencoded.txt,
test/lisp/mail/uudecode-tests.el: New files.
| -rw-r--r-- | lisp/mail/uudecode.el | 5 | ||||
| -rw-r--r-- | test/lisp/mail/uudecode-resources/uudecoded.txt | 16 | ||||
| -rw-r--r-- | test/lisp/mail/uudecode-resources/uuencoded.txt | 19 | ||||
| -rw-r--r-- | test/lisp/mail/uudecode-tests.el | 89 |
4 files changed, 125 insertions, 4 deletions
diff --git a/lisp/mail/uudecode.el b/lisp/mail/uudecode.el index 32e668baab3..57ca1ccc629 100644 --- a/lisp/mail/uudecode.el +++ b/lisp/mail/uudecode.el | |||
| @@ -38,19 +38,16 @@ | |||
| 38 | "Non-nil value should be a string that names a uu decoder. | 38 | "Non-nil value should be a string that names a uu decoder. |
| 39 | The program should expect to read uu data on its standard | 39 | The program should expect to read uu data on its standard |
| 40 | input and write the converted data to its standard output." | 40 | input and write the converted data to its standard output." |
| 41 | :type 'string | 41 | :type 'string) |
| 42 | :group 'uudecode) | ||
| 43 | 42 | ||
| 44 | (defcustom uudecode-decoder-switches nil | 43 | (defcustom uudecode-decoder-switches nil |
| 45 | "List of command line flags passed to `uudecode-decoder-program'." | 44 | "List of command line flags passed to `uudecode-decoder-program'." |
| 46 | :group 'uudecode | ||
| 47 | :type '(repeat string)) | 45 | :type '(repeat string)) |
| 48 | 46 | ||
| 49 | (defcustom uudecode-use-external | 47 | (defcustom uudecode-use-external |
| 50 | (executable-find uudecode-decoder-program) | 48 | (executable-find uudecode-decoder-program) |
| 51 | "Use external uudecode program." | 49 | "Use external uudecode program." |
| 52 | :version "22.1" | 50 | :version "22.1" |
| 53 | :group 'uudecode | ||
| 54 | :type 'boolean) | 51 | :type 'boolean) |
| 55 | 52 | ||
| 56 | (defconst uudecode-alphabet "\040-\140") | 53 | (defconst uudecode-alphabet "\040-\140") |
diff --git a/test/lisp/mail/uudecode-resources/uudecoded.txt b/test/lisp/mail/uudecode-resources/uudecoded.txt new file mode 100644 index 00000000000..a6f75519a17 --- /dev/null +++ b/test/lisp/mail/uudecode-resources/uudecoded.txt | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | This is a test file encoded with uuencode. | ||
| 2 | |||
| 3 | This file is part of GNU Emacs. | ||
| 4 | |||
| 5 | GNU Emacs is free software: you can redistribute it and/or modify | ||
| 6 | it under the terms of the GNU General Public License as published by | ||
| 7 | the Free Software Foundation, either version 3 of the License, or | ||
| 8 | (at your option) any later version. | ||
| 9 | |||
| 10 | GNU Emacs is distributed in the hope that it will be useful, | ||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | GNU General Public License for more details. | ||
| 14 | |||
| 15 | You should have received a copy of the GNU General Public License | ||
| 16 | along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. | ||
diff --git a/test/lisp/mail/uudecode-resources/uuencoded.txt b/test/lisp/mail/uudecode-resources/uuencoded.txt new file mode 100644 index 00000000000..1d2f888bea3 --- /dev/null +++ b/test/lisp/mail/uudecode-resources/uuencoded.txt | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | begin 644 uudecoded.txt | ||
| 2 | M5&AI<R!I<R!A('1E<W0@9FEL92!E;F-O9&5D('=I=&@@=75E;F-O9&4N"@I4 | ||
| 3 | M:&ES(&9I;&4@:7,@<&%R="!O9B!'3E4@16UA8W,N"@I'3E4@16UA8W,@:7,@ | ||
| 4 | M9G)E92!S;V9T=V%R93H@>6]U(&-A;B!R961I<W1R:6)U=&4@:70@86YD+V]R | ||
| 5 | M(&UO9&EF>0II="!U;F1E<B!T:&4@=&5R;7,@;V8@=&AE($=.52!'96YE<F%L | ||
| 6 | M(%!U8FQI8R!,:6-E;G-E(&%S('!U8FQI<VAE9"!B>0IT:&4@1G)E92!3;V9T | ||
| 7 | M=V%R92!&;W5N9&%T:6]N+"!E:71H97(@=F5R<VEO;B`S(&]F('1H92!,:6-E | ||
| 8 | M;G-E+"!O<@HH870@>6]U<B!O<'1I;VXI(&%N>2!L871E<B!V97)S:6]N+@H* | ||
| 9 | M1TY5($5M86-S(&ES(&1I<W1R:6)U=&5D(&EN('1H92!H;W!E('1H870@:70@ | ||
| 10 | M=VEL;"!B92!U<V5F=6PL"F)U="!7251(3U54($%.62!705)204Y463L@=VET | ||
| 11 | M:&]U="!E=F5N('1H92!I;7!L:65D('=A<G)A;G1Y(&]F"DU%4D-(04Y404)) | ||
| 12 | M3$E462!O<B!&251.15-3($9/4B!!(%!!4E1)0U5,05(@4%524$]312X@(%-E | ||
| 13 | M92!T:&4*1TY5($=E;F5R86P@4'5B;&EC($QI8V5N<V4@9F]R(&UO<F4@9&5T | ||
| 14 | M86EL<RX*"EEO=2!S:&]U;&0@:&%V92!R96-E:79E9"!A(&-O<'D@;V8@=&AE | ||
| 15 | M($=.52!'96YE<F%L(%!U8FQI8R!,:6-E;G-E"F%L;VYG('=I=&@@1TY5($5M | ||
| 16 | M86-S+B`@268@;F]T+"!S964@/&AT='!S.B\O=W=W+F=N=2YO<F<O;&EC96YS | ||
| 17 | &97,O/BX* | ||
| 18 | ` | ||
| 19 | end | ||
diff --git a/test/lisp/mail/uudecode-tests.el b/test/lisp/mail/uudecode-tests.el new file mode 100644 index 00000000000..510cbd7fbc5 --- /dev/null +++ b/test/lisp/mail/uudecode-tests.el | |||
| @@ -0,0 +1,89 @@ | |||
| 1 | ;;; uudecode-tests.el --- Tests for uudecode.el -*- lexical-binding: t -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2019 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Stefan Kangas <stefankangas@gmail.com> | ||
| 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 <https://www.gnu.org/licenses/>. | ||
| 21 | |||
| 22 | ;;; Commentary: | ||
| 23 | |||
| 24 | ;;; Code: | ||
| 25 | |||
| 26 | (require 'ert) | ||
| 27 | (require 'uudecode) | ||
| 28 | |||
| 29 | (defvar uudecode-tests-data-dir | ||
| 30 | (file-truename | ||
| 31 | (expand-file-name "uudecode-resources/" | ||
| 32 | (file-name-directory (or load-file-name | ||
| 33 | buffer-file-name)))) | ||
| 34 | "Base directory of uudecode-tests.el test data files.") | ||
| 35 | |||
| 36 | (defun uudecode-tests-read-file (file) | ||
| 37 | "Read contents of FILE and return as string." | ||
| 38 | (with-temp-buffer | ||
| 39 | (insert-file-contents file) | ||
| 40 | (buffer-string))) | ||
| 41 | |||
| 42 | (defvar uudecode-tests-encoded-str | ||
| 43 | (uudecode-tests-read-file | ||
| 44 | (expand-file-name "uuencoded.txt" uudecode-tests-data-dir)) | ||
| 45 | "Uuencoded data for bookmark-tests.el | ||
| 46 | Same as `bookmark-tests-decoded-str' but uuencoded.") | ||
| 47 | (defvar uudecode-tests-decoded-str | ||
| 48 | (uudecode-tests-read-file | ||
| 49 | (expand-file-name "uudecoded.txt" uudecode-tests-data-dir)) | ||
| 50 | "Plain text data for bookmark-tests.el | ||
| 51 | Same as `bookmark-tests-encoded-str' but plain text.") | ||
| 52 | |||
| 53 | (ert-deftest uudecode-tests-decode-region-internal () | ||
| 54 | ;; Write to buffer | ||
| 55 | (with-temp-buffer | ||
| 56 | (insert uudecode-tests-encoded-str) | ||
| 57 | (uudecode-decode-region-internal (point-min) (point-max)) | ||
| 58 | (should (equal (buffer-string) uudecode-tests-decoded-str))) | ||
| 59 | ;; Write to file | ||
| 60 | (with-temp-buffer | ||
| 61 | (let ((tmpfile (make-temp-file "uudecode-tests-"))) | ||
| 62 | (unwind-protect | ||
| 63 | (progn | ||
| 64 | (insert uudecode-tests-encoded-str) | ||
| 65 | (uudecode-decode-region-internal (point-min) (point-max) tmpfile) | ||
| 66 | (should (equal (uudecode-tests-read-file tmpfile) | ||
| 67 | uudecode-tests-decoded-str))) | ||
| 68 | (delete-file tmpfile))))) | ||
| 69 | |||
| 70 | (ert-deftest uudecode-tests-decode-region-external () | ||
| 71 | ;; Write to buffer | ||
| 72 | (when uudecode-use-external | ||
| 73 | (with-temp-buffer | ||
| 74 | (insert uudecode-tests-encoded-str) | ||
| 75 | (uudecode-decode-region-external (point-min) (point-max)) | ||
| 76 | (should (equal (buffer-string) uudecode-tests-decoded-str))) | ||
| 77 | ;; Write to file | ||
| 78 | (with-temp-buffer | ||
| 79 | (let ((tmpfile (make-temp-file "uudecode-tests-"))) | ||
| 80 | (unwind-protect | ||
| 81 | (progn | ||
| 82 | (insert uudecode-tests-encoded-str) | ||
| 83 | (uudecode-decode-region-external (point-min) (point-max) tmpfile) | ||
| 84 | (should (equal (uudecode-tests-read-file tmpfile) | ||
| 85 | uudecode-tests-decoded-str))) | ||
| 86 | (delete-file tmpfile)))))) | ||
| 87 | |||
| 88 | (provide 'uudecode-tests) | ||
| 89 | ;;; uudecode-tests.el ends here | ||