emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 7e80aec: Add tests for mm-decode.el


From: Lars Ingebrigtsen
Subject: master 7e80aec: Add tests for mm-decode.el
Date: Thu, 7 Jan 2021 08:33:42 -0500 (EST)

branch: master
commit 7e80aecc248a78eab923005b266c939c18936c1b
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Add tests for mm-decode.el
---
 .../gnus/mm-decode-resources/8bit-multipart.bin    | 20 ++++++
 test/lisp/gnus/mm-decode-tests.el                  | 73 ++++++++++++++++++++++
 2 files changed, 93 insertions(+)

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 0000000..0b193a2
--- /dev/null
+++ b/test/lisp/gnus/mm-decode-resources/8bit-multipart.bin
@@ -0,0 +1,20 @@
+From: example <example@example.org>
+To: example <example@example.org>
+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
+
+<!doctype html><html><head><meta http-equiv="content-type" content="text/html; 
charset=UTF-8"></head><body>ääää</body></html>
+
+--===============2877195075946974246==--
diff --git a/test/lisp/gnus/mm-decode-tests.el 
b/test/lisp/gnus/mm-decode-tests.el
new file mode 100644
index 0000000..976e726
--- /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 <https://www.gnu.org/licenses/>.
+
+;;; 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)))
+                         "<!doctype html><html><head><meta 
http-equiv=\"content-type\" content=\"text/html; 
charset=UTF-8\"></head><body>ääää</body></html>\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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]