1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Add tests for mm-decode.el

This commit is contained in:
Lars Ingebrigtsen 2021-01-07 14:32:28 +01:00
parent a7fdba7889
commit 7e80aecc24
2 changed files with 93 additions and 0 deletions

View file

@ -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==--

View file

@ -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