From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Felix Dietrich Newsgroups: gmane.emacs.bugs Subject: bug#57532: Restructure mailcap-add-mailcap-entry to improve readability Date: Thu, 01 Sep 2022 23:37:41 +0200 Message-ID: <878rn2rd22.fsf@sperrhaken.name> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="885"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) Cc: Lars Ingebrigtsen To: 57532@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Sep 01 23:39:11 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oTru3-000AbF-7w for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 01 Sep 2022 23:39:11 +0200 Original-Received: from localhost ([::1]:39508 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oTru1-0006VU-Tx for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 01 Sep 2022 17:39:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39988) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oTrtu-0006Ut-RU for bug-gnu-emacs@gnu.org; Thu, 01 Sep 2022 17:39:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54558) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oTrtu-0007Ew-I1 for bug-gnu-emacs@gnu.org; Thu, 01 Sep 2022 17:39:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oTrtu-0001lL-5a; Thu, 01 Sep 2022 17:39:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Felix Dietrich Original-Sender: "Debbugs-submit" Resent-CC: larsi@gnus.org, bug-gnu-emacs@gnu.org Resent-Date: Thu, 01 Sep 2022 21:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 57532 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs X-Debbugs-Original-Xcc: Lars Ingebrigtsen Original-Received: via spool by submit@debbugs.gnu.org id=B.16620682826695 (code B ref -1); Thu, 01 Sep 2022 21:39:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 1 Sep 2022 21:38:02 +0000 Original-Received: from localhost ([127.0.0.1]:44305 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oTrsv-0001jd-E2 for submit@debbugs.gnu.org; Thu, 01 Sep 2022 17:38:02 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:58060) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oTrss-0001jT-9s for submit@debbugs.gnu.org; Thu, 01 Sep 2022 17:37:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53156) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oTrsr-0006PH-1G for bug-gnu-emacs@gnu.org; Thu, 01 Sep 2022 17:37:58 -0400 Original-Received: from mout.kundenserver.de ([217.72.192.73]:41771) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oTrso-0004i3-3b for bug-gnu-emacs@gnu.org; Thu, 01 Sep 2022 17:37:56 -0400 Original-Received: from localhost ([78.54.95.255]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1N6srB-1pSped3HWJ-018GD9 for ; Thu, 01 Sep 2022 23:37:48 +0200 X-Provags-ID: V03:K1:fDVmRQvRx2KIAKdZlT30CBk+vG33vXdXF8b4R+7risgu+CL+Qvy 6LmBXQjq3gpPrmA+Vo9rJtCfW8ldIGMWEmMSlRWEZEiEyGGUiq9yV7NusH5E+DWdBiEoaBu 2DuVGhEzQu9lAawrvtGtCw7gEf3xW5t4WyNhMbsQT5KukKFM7FxnBiZH6HcFXYVuMPfOtOe zXkgweBSnF44APr+xGhjg== X-UI-Out-Filterresults: notjunk:1;V03:K0:syXoJw2Y3J8=:gBEYaY0ABfRlq/teHQegKv OSr6SI+421S6W1KSzscWRcMD4Uo/eQpaapmdYAHncl2RuqjWDqkrzxSO0f3FVC117ttxZVGhZ NzxUw8di0SsjnwZSQU8Y9Ko10DAq8gfABxowXWtYCXBQ6rN5BliYKo3ry8eYNjWESlY/mMXLx rsPLql5m0OWy7VGBgXm5yut2/zkTF+WyIPZMr04GTR9hVP85BZZu44G1oo57WuVCiD6Eb/h05 LI8TwZpmrmteslDdsV7WX8r8P13zYWQsjwGDVrNQVRcsn6x4DJkmtVBJeIXuBjLMcgMtQCE+a 8mdaWXz+2CLqg0ZGOl2Pmt4kWwRuCzPCnssYtcv7cF7HlxPqO8XG0gXeIy3OdMZduX2rIAu/u EIenBCa/erLtVII6mAO7z0QffFSHJXnkd1ICEbrI7w00w+wbx3snLBpNsrPHcNxCAKJfrfHWz usCTRGeCzdUq4SZ5n6iO4FbmkkOatUy4/VDzC3ehSOR2Y8huupI5vaJGz4CDu/G7HbYOIY9r+ W7K1Z9Q3mYigT/QPBpjlp5wwhLy7TCjEAN5Df0bgL3BPW1WklODq/MCMV0Md456l5rJwg2x4C GUw5gcPygo9x6AhbwFELe5eBf/RazoGBBcCsZmFgdDWKdnMyahpv7PIXgN8ntanN3eg4s5tOO NkDdaS7RCrYUGcfWoLK2GhkApDEonf+r4ib8gSZtJWCzxgk7xXEfy4aK1ZaXqjaY20nTMKdfb YUF2sxaiPr94/Ld7BcVIDiQkVfJgNo+kf9aEK/5hHuHWq3ck5yT8Gk3Ee3dKDhJ7GYByHB/C Received-SPF: none client-ip=217.72.192.73; envelope-from=felix.dietrich@sperrhaken.name; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:241276 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Package: emacs Tags: patch Severity: wishlist Hello, =E2=80=98mailcap-add-mailcap-entry=E2=80=99 is written in a way that makes = it hard to follow. My patch aims to improve its readability. In order to show that my modification retains the original functionality, another Patch adds ERT test cases for this function. The new version also shows clearer an issue with the current implementation that causes some mailcap entries to be forgotten; this is mentioned in a comment. A docstring for the function is added as well. As was suggested by Lars in March on the emacs-devel mailing list [1], I am submitting my patches now to the bug tracker for them not to be forgotten (which I should have done then =E2=80=93 but life got in the way)= . By now, I have signed the copyright assignment papers, and they have been processed. Footnotes: [1] Message-ID: <878rt3nync.fsf@gnus.org> https://lists.gnu.org/archive/html/emacs-devel/2022-03/msg00593.html --=20 Felix Dietrich --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename=0001-Add-tests-for-mailcap-add-mailcap-entry.patch Content-Transfer-Encoding: quoted-printable Content-Description: Patch to add tests for =?utf-8?Q?=E2=80=98mailcap-add-mailcap-entry?= =?utf-8?Q?=E2=80=99?= >From d698762f6e0bcb3176e0c2696dc2443aee0496e5 Mon Sep 17 00:00:00 2001 From: Felix Dietrich Date: Mon, 14 Mar 2022 14:01:26 +0100 Subject: [PATCH] =3D?UTF-8?q?Add=3D20tests=3D20for=3D20=3DE2=3D80=3D98mailc= ap-add-mailca?=3D =3D?UTF-8?q?p-entry=3DE2=3D80=3D99?=3D MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit * test/lisp/net/mailcap-tests.el: Add tests for =E2=80=98mailcap-add-mailcap-entry=E2=80=99 --- test/lisp/net/mailcap-tests.el | 405 +++++++++++++++++++++++++++++++++ 1 file changed, 405 insertions(+) diff --git a/test/lisp/net/mailcap-tests.el b/test/lisp/net/mailcap-tests.el index 188706fc86..c4f011dd1a 100644 --- a/test/lisp/net/mailcap-tests.el +++ b/test/lisp/net/mailcap-tests.el @@ -133,4 +133,409 @@ (mailcap-view-file (ert-resource-file "test.test"))) (should mailcap--test-result)))) =20 + + +(ert-deftest mailcap-add-mailcap-entry-new-major () + "Add a major entry not yet in =E2=80=98mailcap-mime-data=E2=80=99." + (let ((mailcap-mime-data)) + + ;; Add a new major entry to a empty =E2=80=98mailcap-mime-data=E2=80= =99. + (mailcap-add-mailcap-entry "major1" "minor1" + (list (cons 'viewer "viewer1")) + 'mailcap-mime-data) + (should (equal mailcap-mime-data + '(("major1" + ("minor1" . ((viewer . "viewer1"))))))) + + ;; Add a new major entry to a non-empty =E2=80=98mailcap-mime-data=E2= =80=99. + (mailcap-add-mailcap-entry "major2" "minor2" + (list (cons 'viewer "viewer2")) + 'mailcap-mime-data) + (should (equal mailcap-mime-data + '(("major2" + ("minor2" . ((viewer . "viewer2")))) + ("major1" + ("minor1" . ((viewer . "viewer1")))))))) + + ;; Same spiel but with extra entries in INFO. + (let ((mailcap-mime-data)) + ;; Add a new major entry to an empty =E2=80=98mailcap-mime-data=E2=80= =99. + (mailcap-add-mailcap-entry "major1" "minor1" + (list (cons 'viewer "viewer1") + (cons 'print "print1")) + 'mailcap-mime-data) + (should (equal mailcap-mime-data + '(("major1" + ("minor1" . ((viewer . "viewer1") + (print . "print1"))))))) + + ;; Add a new major entry to a non-empty =E2=80=98mailcap-mime-data=E2= =80=99. + (mailcap-add-mailcap-entry "major2" "minor2" + (list (cons 'viewer "viewer2") + (cons 'print "print2") + (cons 'compose "compose2")) + 'mailcap-mime-data) + (should (equal mailcap-mime-data + '(("major2" + ("minor2" . ((viewer . "viewer2") + (print . "print2") + (compose . "compose2")))) + ("major1" + ("minor1" . ((viewer . "viewer1") + (print . "print1"))))))))) + + +(ert-deftest mailcap-add-mailcap-entry-new-minor-to-empty-major () + "Add a minor entry to a an empty major entry." + (let ((mailcap-mime-data (list (list "major")))) + (mailcap-add-mailcap-entry "major" "minor1" + (list (cons 'viewer "viewer1") + (cons 'print "print1")) + 'mailcap-mime-data) + (should (equal mailcap-mime-data + '(("major" + ("minor1" . ((viewer . "viewer1") + (print . "print1"))))))))) + +(ert-deftest mailcap-add-mailcap-entry-new-minor-to-non-empty-major () + "Add a minor to a major entry containing already minor entries." + (let ((mailcap-mime-data + (list + (list "major" + (list "minor1" + (cons 'viewer "viewer1") + (cons 'test "test1") + (cons 'print "print1")))))) + + (mailcap-add-mailcap-entry "major" "minor2" + (list (cons 'viewer "viewer2") + (cons 'test "test2") + (cons 'print "print2")) + 'mailcap-mime-data) + (should (equal mailcap-mime-data + '(("major" + ("minor2" . ((viewer . "viewer2") + (test . "test2") + (print . "print2"))) + ("minor1" . ((viewer . "viewer1") + (test . "test1") + (print . "print1"))))))) + + (mailcap-add-mailcap-entry "major" "minor3" + (list (cons 'viewer "viewer3") + (cons 'test "test3") + (cons 'compose "compose3")) + 'mailcap-mime-data) + (should (equal mailcap-mime-data + '(("major" + ("minor3" . ((viewer . "viewer3") + (test . "test3") + (compose . "compose3"))) + ("minor2" . ((viewer . "viewer2") + (test . "test2") + (print . "print2"))) + ("minor1" . ((viewer . "viewer1") + (test . "test1") + (print . "print1"))))))))) + +(ert-deftest mailcap-add-mailcap-entry-new-minor-to-various-major-position= s () + "Add a new minor entry to major entries at various postions +in =E2=80=98mailcap-mime-data=E2=80=99." + (let ((mailcap-mime-data + (list + (list "major1" + (list "minor1.1" + (cons 'viewer "viewer1.1") + (cons 'print "print1.1"))) + (list "major2" + (list "minor2.1" + (cons 'viewer "viewer2.1") + (cons 'print "print2.1") + (cons 'compose "compose2.1"))) + (list "major3" + (list "minor3.1" + (cons 'viewer "viewer3.1") + (cons 'compose "compose3.1"))) + (list "major4" + (list "minor4.1" + (cons 'viewer "viewer4.1") + (cons 'edit "edit4.1")))))) + + ;; Add a minor entry to a major mode at the front of + ;; =E2=80=98mailcap-mime-data=E2=80=99. + (mailcap-add-mailcap-entry "major1" "minor1.2" + (list (cons 'viewer "viewer1.2") + (cons 'test "test1.2")) + 'mailcap-mime-data) + (should (equal mailcap-mime-data + '(("major1" + ("minor1.2" . ((viewer . "viewer1.2") + (test . "test1.2"))) + ("minor1.1" . ((viewer . "viewer1.1") + (print . "print1.1")))) + ("major2" + ("minor2.1" . ((viewer . "viewer2.1") + (print . "print2.1") + (compose . "compose2.1")))) + ("major3" + ("minor3.1" . ((viewer . "viewer3.1") + (compose . "compose3.1")))) + ("major4" + ("minor4.1" . ((viewer . "viewer4.1") + (edit . "edit4.1"))))))) + + ;; Add a minor entry to a major mode in the middle of + ;; =E2=80=98mailcap-mime-data=E2=80=99. + (mailcap-add-mailcap-entry "major3" "minor3.2" + (list (cons 'viewer "viewer3.2") + (cons 'test "test3.2") + (cons 'compose "compose3.2")) + 'mailcap-mime-data) + (should (equal mailcap-mime-data + '(("major1" + ("minor1.2" . ((viewer . "viewer1.2") + (test . "test1.2"))) + ("minor1.1" . ((viewer . "viewer1.1") + (print . "print1.1")))) + ("major2" + ("minor2.1" . ((viewer . "viewer2.1") + (print . "print2.1") + (compose . "compose2.1")))) + ("major3" + ("minor3.2" . ((viewer . "viewer3.2") + (test . "test3.2") + (compose . "compose3.2"))) + ("minor3.1" . ((viewer . "viewer3.1") + (compose . "compose3.1")))) + ("major4" + ("minor4.1" . ((viewer . "viewer4.1") + (edit . "edit4.1"))))))) + + ;; Add a minor entry to a major mode at the end of + ;; =E2=80=98mailcap-mime-data=E2=80=99. + (mailcap-add-mailcap-entry "major4" "minor4.2" + (list (cons 'viewer "viewer4.2") + (cons 'test "test4.2") + (cons 'print "print4.2") + (cons 'compose "compose4.2")) + 'mailcap-mime-data) + (should (equal mailcap-mime-data + '(("major1" + ("minor1.2" . ((viewer . "viewer1.2") + (test . "test1.2"))) + ("minor1.1" . ((viewer . "viewer1.1") + (print . "print1.1")))) + ("major2" + ("minor2.1" . ((viewer . "viewer2.1") + (print . "print2.1") + (compose . "compose2.1")))) + ("major3" + ("minor3.2" . ((viewer . "viewer3.2") + (test . "test3.2") + (compose . "compose3.2"))) + ("minor3.1" . ((viewer . "viewer3.1") + (compose . "compose3.1")))) + ("major4" + ("minor4.2" . ((viewer . "viewer4.2") + (test . "test4.2") + (print . "print4.2") + (compose . "compose4.2"))) + ("minor4.1" . ((viewer . "viewer4.1") + (edit . "edit4.1"))))))))) + +(ert-deftest mailcap-add-mailcap-entry-existing-with-test-differing-viewer= () + "Add a new entry for an already existing major/minor entry." + + ;; The new and the existing entry have each a test info field. + (let ((mailcap-mime-data + (list + (list "major" + (list "minor" + (cons 'viewer "viewer1") + (cons 'test "test1") + (cons 'print "print1")))))) + (mailcap-add-mailcap-entry "major" "minor" + (list (cons 'viewer "viewer2") + (cons 'test "test2")) + 'mailcap-mime-data) + (should (equal mailcap-mime-data + '(("major" + ("minor" . ((viewer . "viewer2") + (test . "test2"))) + ("minor" . ((viewer . "viewer1") + (test . "test1") + (print . "print1")))))))) + + ;; Only the new entry has a test info field. + (let ((mailcap-mime-data + (list + (list "major" + (list "minor" + (cons 'viewer "viewer1") + (cons 'print "print1")))))) + (mailcap-add-mailcap-entry "major" "minor" + (list (cons 'viewer "viewer2") + (cons 'test "test2")) + 'mailcap-mime-data) + (should (equal mailcap-mime-data + '(("major" + ("minor" . ((viewer . "viewer2") + (test . "test2"))) + ("minor" . ((viewer . "viewer1") + (print . "print1")))))))) + + ;; Only the existing entry has a test info field. + (let ((mailcap-mime-data + (list + (list "major" + (list "minor" + (cons 'viewer "viewer1") + (cons 'test "test1") + (cons 'print "print1")))))) + (mailcap-add-mailcap-entry "major" "minor" + (list (cons 'viewer "viewer2")) + 'mailcap-mime-data) + (should (equal mailcap-mime-data + '(("major" + ("minor" . ((viewer . "viewer2"))) + ("minor" . ((viewer . "viewer1") + (test . "test1") + (print . "print1"))))))))) + +(ert-deftest mailcap-add-mailcap-entry-existing-with-test-same-viewer () + "Add a new entry for an already existing major/minor entry." + ;; Both the new and the existing entry have each a test info field. + (let ((mailcap-mime-data + (list + (list "major" + (list "minor" + (cons 'viewer "viewer") + (cons 'test "test1") + (cons 'print "print1")))))) + (mailcap-add-mailcap-entry "major" "minor" + (list (cons 'viewer "viewer") + (cons 'test "test2")) + 'mailcap-mime-data) + (should (equal mailcap-mime-data + '(("major" + ("minor" . ((viewer . "viewer") + (test . "test2"))) + ("minor" . ((viewer . "viewer") + (test . "test1") + (print . "print1")))))))) + + ;; Only the new entry has a test field. + (let ((mailcap-mime-data + (list + (list "major" + (list "minor" + (cons 'viewer "viewer") + (cons 'print "print1")))))) + (mailcap-add-mailcap-entry "major" "minor" + (list (cons 'viewer "viewer") + (cons 'test "test2")) + 'mailcap-mime-data) + (should (equal mailcap-mime-data + '(("major" + ("minor" . ((viewer . "viewer") + (test . "test2"))) + ("minor" . ((viewer . "viewer") + (print . "print1")))))))) + + ;; Only the existing entry has a test info field. + (let ((mailcap-mime-data + (list + (list "major" + (list "minor" + (cons 'viewer "viewer") + (cons 'test "test1") + (cons 'print "print1")))))) + (mailcap-add-mailcap-entry "major" "minor" + (list (cons 'viewer "viewer")) + 'mailcap-mime-data) + (should (equal mailcap-mime-data + '(("major" + ("minor" . ((viewer . "viewer"))) + ("minor" . ((viewer . "viewer") + (test . "test1") + (print . "print1"))))))))) + +(ert-deftest mailcap-add-mailcap-entry-existing-without-test-differing-vie= wer () + "Add a new entry for an already existing major/minor entry." + ;; Both entries do not have test fields. + (let ((mailcap-mime-data + (list + (list "major" + (list "minor" + (cons 'viewer "viewer1") + (cons 'print "print1")))))) + (mailcap-add-mailcap-entry "major" "minor" + (list (cons 'viewer "viewer2") + (cons 'compose "print2")) + 'mailcap-mime-data) + (should (equal mailcap-mime-data + '(("major" + ("minor" . ((viewer . "viewer2") + (compose . "print2"))) + ("minor" . ((viewer . "viewer1") + (print . "print1"))))))))) + +(ert-deftest mailcap-add-mailcap-entry-simple-merge () + "Merge entries without tests (no extra info fields in the existing entry= )." + (let ((mailcap-mime-data + (list + (list "major" + (list "minor" + (cons 'viewer "viewer")))))) + (mailcap-add-mailcap-entry "major" "minor" + (list (cons 'viewer "viewer")) + 'mailcap-mime-data) + (should (equal mailcap-mime-data + '(("major" + ("minor" . ((viewer . "viewer")))))))) + + (let ((mailcap-mime-data + (list + (list "major" + (list "minor" + (cons 'viewer "viewer")))))) + (mailcap-add-mailcap-entry "major" "minor" + (list (cons 'viewer "viewer") + (cons 'print "print")) + 'mailcap-mime-data) + + (should (equal mailcap-mime-data + '(("major" + ("minor" . ((viewer . "viewer") + (print . "print"))))))))) + +(ert-deftest mailcap-add-mailcap-entry-erroneous-merge () + "Merge entries without tests (extra info fields in existing entry). + +In its current implementation =E2=80=98mailcap-add-mailcap-entry=E2=80=99 = loses +extra fields of an entry already existing in =E2=80=98mailcap-mime-data=E2= =80=99. +This test does not actually verify a correct result; it merely +checks whether =E2=80=98mailcap-add-mailcap-entry=E2=80=99 behaviour is st= ill the +incorrect one. As such, it can be satisfied by any other result +than the expected and known wrong one, and its success does not +help to verify the correct addition and merging of an entry." + :expected-result :failed + + (let ((mailcap-mime-data + (list + (list "major" + (list "minor" + (cons 'viewer "viewer") + (cons 'print "print")))))) + (mailcap-add-mailcap-entry "major" "minor" + (list (cons 'viewer "viewer") + (cons 'edit "edit")) + 'mailcap-mime-data) + ;; Has the print field been lost? + (should-not (equal mailcap-mime-data + '(("major" + ("minor" . ((viewer . "viewer") + (edit . "edit"))))))))) + + ;;; mailcap-tests.el ends here --=20 2.36.1 --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename=0001-Restructure-mailcap-add-mailcap-entry.patch Content-Transfer-Encoding: quoted-printable Content-Description: Patch to restructure =?utf-8?Q?=E2=80=98mailcap-add-mailcap-entry=E2=80=99?= >From a370e5f9397fbf5abe1e624acbc19ee009c5c7db Mon Sep 17 00:00:00 2001 From: Felix Dietrich Date: Sun, 6 Mar 2022 20:41:41 +0100 Subject: [PATCH] =3D?UTF-8?q?Restructure=3D20=3DE2=3D80=3D98mailcap-add-mai= lcap-entr?=3D =3D?UTF-8?q?y=3DE2=3D80=3D99?=3D MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit * lisp/net/mailcap.el (mailcap-add-mailcap-entry): Restructure mailcap-add-mailcap-entry to improve readability. --- lisp/net/mailcap.el | 56 +++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/lisp/net/mailcap.el b/lisp/net/mailcap.el index 469643dbca..1fa4130339 100644 --- a/lisp/net/mailcap.el +++ b/lisp/net/mailcap.el @@ -716,27 +716,43 @@ to supply to the test." result)))) =20 (defun mailcap-add-mailcap-entry (major minor info &optional storage) + "Add handler INFO for mime type MAJOR/MINOR to STORAGE. + +MAJOR and MINOR should be strings. MINOR is treated as a regexp +in later lookups, and, therefore, you may need to escape it +appropriately. + +The format of INFO is described in =E2=80=98mailcap-mime-data=E2=80=99. + +STORAGE should be a symbol refering to a variable. The value of +this variable should have the same format as =E2=80=98mailcap-mime-data=E2= =80=99. +STORAGE defaults to =E2=80=98mailcap--computed-mime-data=E2=80=99. + +None of this is enforced." (let* ((storage (or storage 'mailcap--computed-mime-data)) - (old-major (assoc major (symbol-value storage)))) - (if (null old-major) ; New major area - (set storage - (cons (cons major (list (cons minor info))) - (symbol-value storage))) - (let ((cur-minor (assoc minor old-major))) - (cond - ((or (null cur-minor) ; New minor area, or - (assq 'test info)) ; Has a test, insert at beginning - (setcdr old-major - (cons (cons minor info) (cdr old-major)))) - ((and (not (assq 'test info)) ; No test info, replace completely - (not (assq 'test cur-minor)) - (equal (assq 'viewer info) ; Keep alternative viewer - (assq 'viewer cur-minor))) - (setcdr cur-minor info)) - (t - (setcdr old-major - (setcdr old-major - (cons (cons minor info) (cdr old-major)))))))))) + (major-entry (assoc major (symbol-value storage))) + (new-minor-entry (cons minor info)) + minor-entry) + (cond + ((null major-entry) + ;; Add a new major entry containing the new minor entry. + (setf major-entry (list major new-minor-entry)) + (push major-entry (symbol-value storage))) + ((and (setf minor-entry (assoc minor major-entry)) + (not (assq 'test info)) + (not (assq 'test minor-entry)) + (equal (assq 'viewer info) + (assq 'viewer minor-entry))) + ;; Replace a previous MINOR entry if it and the entry to be + ;; added both do *not* have a =E2=80=98test=E2=80=99 associated in t= heir info + ;; alist and both use the same =E2=80=98viewer=E2=80=99 command. Th= is ignores + ;; other fields in the previous entry=CA=BCs info alist: they will be + ;; lost when the info alist in the cdr of the previous entry is + ;; replaced with the new INFO alist. + (setf (cdr minor-entry) info)) + (t + ;; Add the new minor entry to the existing major entry. + (push new-minor-entry (cdr major-entry)))))) =20 (defun mailcap-add (type viewer &optional test) "Add VIEWER as a handler for TYPE. --=20 2.36.1 --=-=-=--