about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-12-10 13:42:52 +0000
committerEric Wong <e@80x24.org>2023-12-10 21:48:34 +0000
commit235b55840c4066029e56ed91d6d3dc46c921a23b (patch)
treec3df23e25de3c4e9644fadef2b31ca32fd700d91 /t
parent8188164496fcd36aa4fc6ac14a5e4782feace077 (diff)
downloadpublic-inbox-235b55840c4066029e56ed91d6d3dc46c921a23b.tar.gz
Our pure-Perl (PublicInbox::AddressPP) fallback is closer to the
preferred Email::Address::XS (EAX) behavior than Mail::Address
is for ->name support.  EAX tends to be overkill with good spam
filtering, and using our own fallback means life is easier for
users with neither C/XS build tools nor a pre-built EAX package.
Diffstat (limited to 't')
-rw-r--r--t/address.t19
1 files changed, 16 insertions, 3 deletions
diff --git a/t/address.t b/t/address.t
index 6aa94628..16000d2d 100644
--- a/t/address.t
+++ b/t/address.t
@@ -1,7 +1,7 @@
-# Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
+#!perl -w
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
-use strict;
-use warnings;
+use v5.12;
 use Test::More;
 use_ok 'PublicInbox::Address';
 
@@ -10,6 +10,7 @@ sub test_pkg {
         my $emails = $pkg->can('emails');
         my $names = $pkg->can('names');
         my $pairs = $pkg->can('pairs');
+        my $objects = $pkg->can('objects');
 
         is_deeply([qw(e@example.com e@example.org)],
                 [$emails->('User <e@example.com>, e@example.org')],
@@ -35,6 +36,18 @@ sub test_pkg {
                         [ 'xyz', 'y@x' ], [ 'U Ser', 'u@x' ] ],
                 "pairs extraction works for $pkg");
 
+        # only what's used by PublicInbox::IMAP:
+        my @objs = $objects->($s);
+        my @exp = (qw(User e e), qw(e e e), ('John A. Doe', qw(j d)),
+                qw(x x x), qw(xyz y x), ('U Ser', qw(u x)));
+        for (my $i = 0; $i <= $#objs; $i++) {
+                my $exp_name = shift @exp;
+                my $name = $objs[$i]->name;
+                is $name, $exp_name, "->name #$i matches";
+                is $objs[$i]->user, shift @exp, "->user #$i matches";
+                is $objs[$i]->host , shift @exp, "->host #$i matches";
+        }
+
         @names = $names->('"user@example.com" <user@example.com>');
         is_deeply(['user'], \@names,
                 'address-as-name extraction works as expected');