public-inbox.git  about / heads / tags
an "archives first" approach to mailing lists
blob eced5c4632cdea1e86990ac7e594e61acf75c6ab 1284 bytes (raw)
$ git show ci-WIP:t/address.t	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 
# Copyright (C) 2016-2018 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict;
use warnings;
use Test::More;
use_ok 'PublicInbox::Address';

is_deeply([qw(e@example.com e@example.org)],
	[PublicInbox::Address::emails('User <e@example.com>, e@example.org')],
	'address extraction works as expected');

is_deeply(['user@example.com'],
	[PublicInbox::Address::emails('<user@example.com (Comment)>')],
	'comment after domain accepted before >');

my @names = PublicInbox::Address::names(
	'User <e@e>, e@e, "John A. Doe" <j@d>, <x@x>');
is_deeply(['User', 'e', 'John A. Doe', 'x'], \@names,
	'name extraction works as expected');

@names = PublicInbox::Address::names('"user@example.com" <user@example.com>');
is_deeply(['user'], \@names, 'address-as-name extraction works as expected');


{
	my $backwards = 'u@example.com (John Q. Public)';
	@names = PublicInbox::Address::names($backwards);
	is_deeply(\@names, ['u'], 'backwards name OK');
	my @emails = PublicInbox::Address::emails($backwards);
	is_deeply(\@emails, ['u@example.com'], 'backwards emails OK');
}


@names = PublicInbox::Address::names('"Quote Unneeded" <user@example.com>');
is_deeply(['Quote Unneeded'], \@names, 'extra quotes dropped');

done_testing;

git clone https://public-inbox.org/public-inbox.git
git clone http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/public-inbox.git