;;; eudc-tests.el --- Tests for EUDC -*- lexical-binding: t -*- ;; Copyright (C) 2022 Free Software Foundation, Inc. ;; Author: Alexander Adolf ;; Maintainer: Thomas Fitzsimmons ;; 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 . ;;; Commentary: ;; This file contains tests for EUDC. ;;; Code: (require 'ert) (require 'eudc) ;;;;;; ;; ;; Phase 0: pure core tests (no back-ends involved) ;; ;; eudc-rfc5322-quote-phrase (string) (ert-deftest eudc-test-rfc5322-quote-phrase () "Tests for RFC5322 compliant phrase quoting." ;; atext-token "[:alpha:][:digit:]!#$%&'*+/=?^_`{|}~-" (should (equal (eudc-rfc5322-quote-phrase "Foo Bar !#$%&'*+/=?^_`{|}~-") "Foo Bar !#$%&'*+/=?^_`{|}~-")) (should (equal (eudc-rfc5322-quote-phrase "Foo, Bar !#$%&'*+/=?^_`{|}~-") "\"Foo, Bar !#$%&'*+/=?^_`{|}~-\""))) ;; eudc-rfc5322-valid-comment-p (string) (ert-deftest eudc-test-rfc5322-valid-comment-p () "Tests for RFC5322 compliant comments." ;; cctext-token "\u005D-\u007E\u002A-\u005B\u0021-\u0027" + fwsp-token (TAB, LF, SPC) ;; Printable US-ASCII characters not including "(", ")", or "\". (let ((good-chars (append (number-sequence #x09 #x0a) (number-sequence #x20 #x20) (number-sequence #x21 #x27) (number-sequence #x2a #x5b) (number-sequence #x5d #x7e))) (bad-chars (append (number-sequence #x00 #x08) (number-sequence #x0b #x1f) (number-sequence #x28 #x29) (number-sequence #x5c #x5c) (number-sequence #x7f #xff)))) (dolist (gc good-chars) (should (eq (eudc-rfc5322-valid-comment-p (format "%c" gc)) t))) (dolist (bc bad-chars) (should (eq (eudc-rfc5322-valid-comment-p (format "%c" bc)) nil))))) ;; eudc-rfc5322-make-address (address &optional firstname name comment) (ert-deftest eudc-test-make-address () "Tests for RFC5322 compliant email address formatting." (should (equal (eudc-rfc5322-make-address "") nil)) (should (equal (eudc-rfc5322-make-address nil) nil)) (should (equal (eudc-rfc5322-make-address "j.sixpack@example.org") "j.sixpack@example.org")) (should (equal (eudc-rfc5322-make-address "") "")) (should (equal (eudc-rfc5322-make-address "j.sixpack@example.org" "Joey") "Joey ")) (should (equal (eudc-rfc5322-make-address "j.sixpack@example.org" "Joey" "Sixpack") "Joey Sixpack ")) (should (equal (eudc-rfc5322-make-address "j.sixpack@example.org" "Joey" "Sixpack" "ten-packs are fine, too") "Joey Sixpack (ten-packs are fine, too)")) (should (equal (eudc-rfc5322-make-address "j.sixpack@example.org" "" "Sixpack, Joey") "\"Sixpack, Joey\" ")) (should (equal (eudc-rfc5322-make-address "j.sixpack@example.org" nil "Sixpack, Joey") "\"Sixpack, Joey\" ")) (should (equal (eudc-rfc5322-make-address "j.sixpack@example.org" nil nil "Duh!") "j.sixpack@example.org (Duh!)")) (should (equal (eudc-rfc5322-make-address "j.sixpack@example.org" nil nil "Duh\\!") "j.sixpack@example.org"))) ;;;;;; ;; ;; Phase 1: back-end tests ;; (require 'ert-x) ;;;;;; ;; Phase 1.0: ecomplete back-end ;; (require 'eudcb-ecomplete) (ert-deftest eudcb-ecomplete () "Test the ecomplete back-end." (ert-with-temp-directory home (with-environment-variables (("HOME" home)) (let ((ecomplete-database-file (ert-resource-file "ecompleterc")) (eudc-options-file (locate-user-emacs-file "eudc-options" ".eudc-options"))) (eudc-ecomplete-set-server "localhost") (should (equal (eudc-ecomplete-query-internal '((mail . "brigts"))) '(((mail . "larsi@ecomplete.org") (name . "Lars Ingebrigtsen"))))) (should (equal (eudc-ecomplete-query-internal '((mail . "karl"))) '(((mail . "kfogel@ecomplete.com") (name . "Karl Fogel"))))) (should (equal (eudc-ecomplete-query-internal '((mail . "behs"))) '(((mail . "behse@ecomplete.org"))))) (should (equal (eudc-ecomplete-query-internal '((mail . "louie"))) nil)))))) (provide 'eudc-tests) ;;; eudc-tests.el ends here