public-inbox.git  about / heads / tags
an "archives first" approach to mailing lists
blob be0fc5b7b41aa1eec50e8a130e7c8ace619cf4e4 1241 bytes (raw)
name: t/address.t 	 # note: path name is non-authoritative(*)

 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
 
# Copyright (C) 2016 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([PublicInbox::Address::emails('"ex@example.com" <ex@example.com>')],
	[qw(ex@example.com)]);

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 path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

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