emacs-diffs
[Top][All Lists]
Advanced

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

master 3c81066: Use lexical-binding in qp.el and add tests


From: Stefan Kangas
Subject: master 3c81066: Use lexical-binding in qp.el and add tests
Date: Thu, 30 Apr 2020 04:37:33 -0400 (EDT)

branch: master
commit 3c810669f7b913f63049826a89e08c1691767506
Author: Stefan Kangas <address@hidden>
Commit: Stefan Kangas <address@hidden>

    Use lexical-binding in qp.el and add tests
    
    * test/lisp/mail/qp-tests.el: New file.
    * lisp/mail/qp.el: Use lexical-binding.
---
 lisp/mail/qp.el            |  2 +-
 test/lisp/mail/qp-tests.el | 74 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/lisp/mail/qp.el b/lisp/mail/qp.el
index 388c398..35ff47f 100644
--- a/lisp/mail/qp.el
+++ b/lisp/mail/qp.el
@@ -1,4 +1,4 @@
-;;; qp.el --- Quoted-Printable functions
+;;; qp.el --- Quoted-Printable functions  -*- lexical-binding:t -*-
 
 ;; Copyright (C) 1998-2020 Free Software Foundation, Inc.
 
diff --git a/test/lisp/mail/qp-tests.el b/test/lisp/mail/qp-tests.el
new file mode 100644
index 0000000..8d70449
--- /dev/null
+++ b/test/lisp/mail/qp-tests.el
@@ -0,0 +1,74 @@
+;;; qp-tests.el --- Tests for qp.el  -*- lexical-binding:t; coding:utf-8 -*-
+
+;; Copyright (C) 2020 Free Software Foundation, Inc.
+
+;; Author: Stefan Kangas <address@hidden>
+
+;; 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 of the License, 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 'qp)
+
+;; Quote by Antoine de Saint-Exupéry, Citadelle (1948)
+;; from https://en.wikipedia.org/wiki/Quoted-printable
+(defvar qp-tests-quote-qp
+  (concat "J'interdis aux marchands de vanter trop leurs marchandises. Car ils 
se font =\n"
+          "vite p=C3=A9dagogues et t'enseignent comme but ce qui n'est par 
essence qu'=\n"
+          "un moyen, et te trompant ainsi sur la route =C3=A0 suivre les 
voil=C3=A0 bi=\n"
+          "ent=C3=B4t qui te d=C3=A9gradent, car si leur musique est vulgaire 
ils te f=\n"
+          "abriquent pour te la vendre une =C3=A2me vulgaire."))
+(defvar qp-tests-quote-utf8
+  (concat "J'interdis aux marchands de vanter trop leurs marchandises. Car ils 
se font "
+          "vite pédagogues et t'enseignent comme but ce qui n'est par essence 
qu'"
+          "un moyen, et te trompant ainsi sur la route à suivre les voilà bi"
+          "entôt qui te dégradent, car si leur musique est vulgaire ils te f"
+          "abriquent pour te la vendre une âme vulgaire."))
+
+(ert-deftest qp-test--quoted-printable-decode-region ()
+  (with-temp-buffer
+    (insert qp-tests-quote-qp)
+    (encode-coding-region (point-min) (point-max) 'utf-8)
+    (quoted-printable-decode-region (point-min) (point-max) 'utf-8)
+    (should (equal (buffer-string) qp-tests-quote-utf8))))
+
+(ert-deftest qp-test--quoted-printable-decode-string ()
+  (should (equal (quoted-printable-decode-string "foo!") "foo!"))
+    (should (equal (quoted-printable-decode-string "=0C") "\^L"))
+  (should (equal (quoted-printable-decode-string "=3D") "="))
+  (should (equal (quoted-printable-decode-string "=A1Hola, se=F1or!?")
+                 "\241Hola, se\361or!?")))
+
+(ert-deftest qp-test--quoted-printable-encode-region ()
+  (with-temp-buffer
+    (insert (make-string 26 ?=))
+    ;; (encode-coding-region (point-min) (point-max) 'utf-8)
+    (quoted-printable-encode-region (point-min) (point-max) t)
+    (should (equal (buffer-string)
+                   (concat "=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D"
+                           "=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=\n=3D")))))
+
+(ert-deftest qp-test--quoted-printable-encode-string ()
+  (should (equal (quoted-printable-encode-string "\241Hola, se\361or!?")
+                 "=A1Hola, se=F1or!?"))
+  ;; Multibyte character.
+  (should-error (quoted-printable-encode-string "å")))
+
+(provide 'qp-tests)
+;;; qp-tests.el ends here



reply via email to

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