]> Sergey Matveev's repositories - public-inbox.git/blob - t/address.t
address: use comment as name if no phrase available
[public-inbox.git] / t / address.t
1 # Copyright (C) 2016-2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 use strict;
4 use warnings;
5 use Test::More;
6 use_ok 'PublicInbox::Address';
7
8 is_deeply([qw(e@example.com e@example.org)],
9         [PublicInbox::Address::emails('User <e@example.com>, e@example.org')],
10         'address extraction works as expected');
11
12 is_deeply(['user@example.com'],
13         [PublicInbox::Address::emails('<user@example.com (Comment)>')],
14         'comment after domain accepted before >');
15
16 my @names = PublicInbox::Address::names(
17         'User <e@e>, e@e, "John A. Doe" <j@d>, <x@x>, <y@x> (xyz), '.
18         'U Ser <u@x> (do not use)');
19 is_deeply(\@names, ['User', 'e', 'John A. Doe', 'x', 'xyz', 'U Ser'],
20         'name extraction works as expected');
21
22 @names = PublicInbox::Address::names('"user@example.com" <user@example.com>');
23 is_deeply(['user'], \@names, 'address-as-name extraction works as expected');
24
25
26 {
27         my $backwards = 'u@example.com (John Q. Public)';
28         @names = PublicInbox::Address::names($backwards);
29         is_deeply(\@names, ['John Q. Public'], 'backwards name OK');
30         my @emails = PublicInbox::Address::emails($backwards);
31         is_deeply(\@emails, ['u@example.com'], 'backwards emails OK');
32 }
33
34
35 @names = PublicInbox::Address::names('"Quote Unneeded" <user@example.com>');
36 is_deeply(['Quote Unneeded'], \@names, 'extra quotes dropped');
37
38 done_testing;