From 7e80aecc248a78eab923005b266c939c18936c1b Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Thu, 7 Jan 2021 14:32:28 +0100 Subject: [PATCH] Add tests for mm-decode.el --- .../mm-decode-resources/8bit-multipart.bin | 20 +++++ test/lisp/gnus/mm-decode-tests.el | 73 +++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 test/lisp/gnus/mm-decode-resources/8bit-multipart.bin create mode 100644 test/lisp/gnus/mm-decode-tests.el diff --git a/test/lisp/gnus/mm-decode-resources/8bit-multipart.bin b/test/lisp/gnus/mm-decode-resources/8bit-multipart.bin new file mode 100644 index 00000000000..0b193a27234 --- /dev/null +++ b/test/lisp/gnus/mm-decode-resources/8bit-multipart.bin @@ -0,0 +1,20 @@ +From: example +To: example +Content-Type: multipart/alternative; boundary="===============2877195075946974246==" +Date: Thu, 29 Oct 2020 14:47:55 +0100 +MIME-Version: 1.0 +Subject: test + +--===============2877195075946974246== +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 8bit + +ääää + +--===============2877195075946974246== +Content-Type: text/html; charset="utf-8" +Content-Transfer-Encoding: 8bit + +ääää + +--===============2877195075946974246==-- diff --git a/test/lisp/gnus/mm-decode-tests.el b/test/lisp/gnus/mm-decode-tests.el new file mode 100644 index 00000000000..976e7269b14 --- /dev/null +++ b/test/lisp/gnus/mm-decode-tests.el @@ -0,0 +1,73 @@ +;;; mm-decode-tests.el --- -*- lexical-binding:t -*- + +;; Copyright (C) 2021 Free Software Foundation, Inc. + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Commentary: + +;;; Code: + +(require 'ert) +(require 'ert-x) +(require 'mm-decode) + +(ert-deftest test-mm-dissect-buffer () + (with-temp-buffer + (set-buffer-multibyte nil) + (insert-file-contents-literally (ert-resource-file "8bit-multipart.bin")) + (while (search-forward "\r\n" nil t) + (replace-match "\n")) + (let ((handle (mm-dissect-buffer))) + (should (equal (mm-handle-media-type handle) "multipart/alternative")) + ;; Skip multipart type. + (pop handle) + (let ((part (pop handle))) + (should (equal (mm-handle-media-type part) "text/plain")) + (should (eq (mm-handle-encoding part) '8bit)) + (with-current-buffer (mm-handle-buffer part) + (should (equal (decode-coding-string + (buffer-string) + (intern (mail-content-type-get (mm-handle-type part) + 'charset))) + "ääää\n")))) + (let ((part (pop handle))) + (should (equal (mm-handle-media-type part) "text/html")) + (should (eq (mm-handle-encoding part) '8bit)) + (with-current-buffer (mm-handle-buffer part) + (should (equal (decode-coding-string + (buffer-string) + (intern (mail-content-type-get (mm-handle-type part) + 'charset))) + "ääää\n"))))))) + +(ert-deftest test-mm-with-part () + (with-temp-buffer + (set-buffer-multibyte nil) + (insert-file-contents-literally (ert-resource-file "8bit-multipart.bin")) + (while (search-forward "\r\n" nil t) + (replace-match "\n")) + (let ((handle (mm-dissect-buffer))) + (pop handle) + (let ((part (pop handle))) + (should (equal (decode-coding-string + (mm-with-part part + (buffer-string)) + (intern (mail-content-type-get (mm-handle-type part) + 'charset))) + "ääää\n")))))) + +;;; mm-decode-tests.el ends here -- 2.39.5