# frozen_string_literal: true #-- # gravaty # rubocop:disable Style/AsciiComments # © 2013 Marco Bresciani # rubocop:enable Style/AsciiComments # # This file is part of gravaty. # # gravaty 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. # # gravaty 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 gravaty. If not, see . # # SPDX-FileCopyrightText: 2013 Marco Bresciani # # SPDX-License-Identifier: GPL-3.0-or-later #++ require_relative '../../test_helper' def test_nil describe 'when passed a nil email address' do it 'must return nil' do _(Gravaty::Utils::Rfc5322::EMAIL.match(nil)).must_be_nil end end end def test_invalid describe 'when passed an invalid email address, according to RF5322' do # This test does not pass with 'Joe Q. Public # ' email: see # that is: it # matches the address even if it has no double-quotes as specified # in RFC 5322. # # Note that the display names for Joe Q. Public and Giant; "Big" Box # needed to be enclosed in double-quotes because the former contains # the period and the latter contains both semicolon and double-quote # characters (the double-quote characters appearing as quoted-pair # constructs). ['-.', 'Joe Q. Public '] .each do |invalid_address| it "must return nil for '#{invalid_address}' invalid address" do skip 'This test does not pass.' _(Gravaty::Utils::Rfc5322::EMAIL.match invalid_address).must_be_nil end end end end TEST_ADDRESSES = ['John Doe ', 'Mary Smith ', 'Mary Smith ', # rubocop:disable Layout/LineLength "A Group(Some people)\n :Chris Jones ,\n joe@example.org,\n John (my dear friend);", # rubocop:enable Layout/LineLength 'Who? ', '"Joe Q. Public" ', '"Giant; \"Big\" Box" ', 'A Group:Ed Jones ,joe@where.test,John ;', 'Pete(A nice \) chap) '].freeze def test_valid describe 'when passed a valid email address, according to RF5322' do # This test shall pass... see # # # The above example is aesthetically displeasing, but perfectly # legal. Note particularly (1) the comments in the "From:" field # (including one that has a ")" character appearing as part of a # quoted-pair); (2) the white space absent after the ":" in the # "To:" field as well as the comment and folding white space after # the group name, the special character (".") in the comment in # Chris Jones's address, and the folding white space before and # after "joe@example.org,"; (3) the multiple and nested comments in # the "Cc:" field as well as the comment immediately following the # ":" after "Cc"; (4) the folding white space (but no comments # except at the end) and the missing seconds in the time of the date # field; and (5) the white space before (but not within) the # identifier in the "Message-ID:" field. TEST_ADDRESSES.each do |address| it "must match the valid '#{address}' email address" do _(Gravaty::Utils::Rfc5322::EMAIL.match address).wont_be_nil end end end end describe Gravaty::Utils::Rfc5322 do test_nil test_invalid test_valid end