--- Add three tests. The third one currently fails. emacs/notmuch-test.el | 87 +++++++++++++++++++++++++++++++++++++++++++++++++ test/emacs | 6 +++ 2 files changed, 93 insertions(+), 0 deletions(-) create mode 100644 emacs/notmuch-test.el diff --git a/emacs/notmuch-test.el b/emacs/notmuch-test.el new file mode 100644 index 0000000..d6cf318 --- /dev/null +++ b/emacs/notmuch-test.el @@ -0,0 +1,87 @@ +;; notmuch-test.el --- testing the emacs interface +;; +;; Copyright © David Edmondson +;; +;; This file is part of Notmuch. +;; +;; Notmuch 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. +;; +;; Notmuch 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 Notmuch. If not, see <http://www.gnu.org/licenses/>. +;; +;; Authors: David Edmondson <dme@dme.org> + +(require 'cl) ;; This code is often used uncompiled. + +;; + +(defun notmuch-test-reporter (output expected) + "Report that the `output' does not match the `expected' result." + (concat "Expect:\t" (prin1-to-string expected) "\n" + "Output:\t" (prin1-to-string output) "\n")) + +(defun notmuch-test-unsimilar (output expected) + "`output' and `expected' are dissimilar. Show a summary of +the differences, ignoring similarities." + (cond ((and (listp output) + (listp expected)) + (apply #'concat (loop for o in output + for e in expected + if (not (equal o e)) + collect (notmuch-test-reporter o e)))) + + (t + ;; Catch all case. + (notmuch-test-reporter output expected)))) + +(defun notmuch-test-compare (output expected) + "Compare `output' with `expected'. Report any discrepencies." + (if (equal output expected) + t + (notmuch-test-unsimilar output expected))) + +;; + +;; Tests: + +(defun notmuch-test-clean-address-1 () + (notmuch-test-compare (notmuch-show-clean-address "dme@dme.org") + "dme@dme.org")) + +(defun notmuch-test-clean-address-2 () + (let* ((input '("foo@bar.com" + "<foo@bar.com>" + "Foo Bar <foo@bar.com>" + "foo@bar.com <foo@bar.com>" + "\"Foo Bar\" <foo@bar.com>")) + (expected '("foo@bar.com" + "foo@bar.com" + "Foo Bar <foo@bar.com>" + "foo@bar.com" + "Foo Bar <foo@bar.com>")) + (output (mapcar #'notmuch-show-clean-address input))) + (notmuch-test-compare output expected))) + +(defun notmuch-test-clean-address-3 () + (let* ((input '("ДБ <db-uknot@stop.me.uk>" + "foo (at home) <foo@bar.com>" + "foo [at home] <foo@bar.com>" + "Foo Bar")) + (expected '("ДБ <db-uknot@stop.me.uk>" + "foo (at home) <foo@bar.com>" + "foo [at home] <foo@bar.com>" + "Foo Bar")) + (output (mapcar #'notmuch-show-clean-address input))) + (notmuch-test-compare output expected))) + +;; + +(provide 'notmuch-test) diff --git a/test/emacs b/test/emacs index ac47b16..3a536fb 100755 --- a/test/emacs +++ b/test/emacs @@ -514,4 +514,10 @@ counter=$(test_emacs \ ) test_expect_equal "$counter" 2 +for i in 1 2 3; do + test_begin_subtest "notmuch-show-clean-address $i" + result=$(test_emacs '(load "notmuch-test.el") (notmuch-test-clean-address-'$i')') + test_expect_emacs_t "$result" +done + test_done -- 1.7.7.3