Commit 39a00145 authored by Stefan Kangas's avatar Stefan Kangas

* test/lisp/mail/rfc822-tests.el: New file.

parent 8b6b4176
Pipeline #7390 passed with stage
in 65 minutes and 26 seconds
;;; rfc822-tests.el --- Tests for rfc822.el -*- lexical-binding:t -*-
;; Copyright (C) 2020 Free Software Foundation, Inc.
;; 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
;; 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:
;;; Code:
(require 'ert)
(require 'rfc822)
(defmacro rfc822-tests-deftest (email desc &optional valid)
`(ert-deftest ,(intern (format "rfc822-email-%s-%s"
(if valid "valid" "invalid")
desc)) ()
(if ,valid
(should (equal (rfc822-addresses ,email) (list ,email)))
(let ((addresses (rfc822-addresses ,email)))
;; `rfc822-addresses' returns a string if parsing fails.
(while (and (consp addresses)
(not (eq (string-to-char (car addresses)) ?\()))
(setq addresses (cdr addresses)))
;; Found saved error.
(should (= (length addresses) 1))))))
;;;; Valid emails
(rfc822-tests-deftest "" "email" t)
(rfc822-tests-deftest "" "dot-in-address" t)
(rfc822-tests-deftest "" "dot-in-subdomain" t)
(rfc822-tests-deftest "" "contains-plus-sign" t)
(rfc822-tests-deftest "email@" "domain-valid-ip" t)
(rfc822-tests-deftest "email@[]" "domain-valid-ip-square-bracket" t)
(rfc822-tests-deftest "\"email\"" "quotes-around-email" t)
(rfc822-tests-deftest "" "digits-in-address" t)
(rfc822-tests-deftest "" "dash-in-domain-name" t)
(rfc822-tests-deftest "" "underscore-in-address" t)
(rfc822-tests-deftest "" "dotname-tld" t)
(rfc822-tests-deftest "" "dot-in-tld" t)
(rfc822-tests-deftest "" "dash-in-address" t)
(rfc822-tests-deftest "" "address-long" t)
;;;; Invalid emails
(rfc822-tests-deftest "#@%^%#$@#$" "garbage")
(rfc822-tests-deftest "" "missing-username")
(rfc822-tests-deftest "" "two-at-signs")
(rfc822-tests-deftest "" "address-leading-dot")
(rfc822-tests-deftest "" "address-trailing-dot")
(rfc822-tests-deftest "" "address-multiple-dots")
(rfc822-tests-deftest "" "domain-multiple-dots")
(rfc822-tests-deftest "" "domain-trailing-dot")
(rfc822-tests-deftest "" "domain-leading-dot")
(rfc822-tests-deftest "test\\" "address-escaped-at-sign")
;; FIXME: Should these fail?
;; (rfc822-tests-deftest "plainaddress" "missing-at-sign-and-domain")
;; (rfc822-tests-deftest " (J. Random Hacker)" "text-following-email")
;; (rfc822-tests-deftest "" "leading-dash-in-domain-is-invalid")
;; (rfc822-tests-deftest "" "trailing-dash-in-domain-is-invalid")
;; (rfc822-tests-deftest "あいうえお" "address-unicode-chars")
;; (rfc822-tests-deftest "" "missing-at")
;; (rfc822-tests-deftest "email@111.222.333.44444" "invalid-IP-format")
;; (rfc822-tests-deftest "email@domain" "missing-top-level-domain")
;; (rfc822-tests-deftest "email@domain.web" ".web-is-not-a-valid-top-level-domain")
(provide 'rfc822-tests)
;;; rfc822-tests.el ends here
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment