diff options
Diffstat (limited to 't/address.t')
-rw-r--r-- | t/address.t | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/t/address.t b/t/address.t index 6aa94628..86f47395 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'); @@ -64,6 +77,10 @@ sub test_pkg { is_deeply([], \@emails , 'no address for local address'); @names = $emails->('Local User <user>'); is_deeply([], \@names, 'no address, no name'); + + my $p = $pairs->('NAME, a@example, wtf@'); + is scalar(grep { defined($_->[0] // $_->[1]) } @$p), + scalar(@$p), 'something is always defined in bogus pairs'; } test_pkg('PublicInbox::Address'); |