unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
blob a3d886a2e032714439654bfe353821b0aa7bc271 6027 bytes (raw)
name: test/lisp/net/eudc-tests.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
 
;;; eudc-tests.el --- Tests for EUDC -*- lexical-binding: t -*-

;; Copyright (C) 2022 Free Software Foundation, Inc.

;; Author: Alexander Adolf <alexander.adolf@condition-alpha.com>
;; Maintainer: Thomas Fitzsimmons <fitzsim@fitzsim.org>

;; 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:

;; 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 "<j.sixpack@example.org>")
                 "<j.sixpack@example.org>"))
  (should (equal (eudc-rfc5322-make-address "j.sixpack@example.org"
                                            "Joey")
                 "Joey <j.sixpack@example.org>"))
  (should (equal (eudc-rfc5322-make-address "j.sixpack@example.org"
                                            "Joey"
                                            "Sixpack")
                 "Joey Sixpack <j.sixpack@example.org>"))
  (should (equal (eudc-rfc5322-make-address "j.sixpack@example.org"
                                            "Joey"
                                            "Sixpack"
                                            "ten-packs are fine, too")
                 "Joey Sixpack <j.sixpack@example.org> (ten-packs are fine, too)"))
  (should (equal (eudc-rfc5322-make-address "j.sixpack@example.org"
                                            ""
                                            "Sixpack, Joey")
                 "\"Sixpack, Joey\" <j.sixpack@example.org>"))
  (should (equal (eudc-rfc5322-make-address "j.sixpack@example.org"
                                            nil
                                            "Sixpack, Joey")
                 "\"Sixpack, Joey\" <j.sixpack@example.org>"))
  (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

debug log:

solving a3d886a2e0 ...
found a3d886a2e0 in https://yhetil.org/emacs-devel/8e9c60585677321e437a29215963a908@condition-alpha.com/

applying [1/1] https://yhetil.org/emacs-devel/8e9c60585677321e437a29215963a908@condition-alpha.com/
diff --git a/test/lisp/net/eudc-tests.el b/test/lisp/net/eudc-tests.el
new file mode 100644
index 0000000000..a3d886a2e0

Checking patch test/lisp/net/eudc-tests.el...
Applied patch test/lisp/net/eudc-tests.el cleanly.

index at:
100644 a3d886a2e032714439654bfe353821b0aa7bc271	test/lisp/net/eudc-tests.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).