# Copyright (C) 2016-2019 all contributors
# License: AGPL-3.0+
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.org')],
'address extraction works as expected');
is_deeply(['user@example.com'],
[PublicInbox::Address::emails('')],
'comment after domain accepted before >');
my @names = PublicInbox::Address::names(
'User , e@e, "John A. Doe" , ');
is_deeply(['User', 'e', 'John A. Doe', 'x'], \@names,
'name extraction works as expected');
@names = PublicInbox::Address::names('"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" ');
is_deeply(['Quote Unneeded'], \@names, 'extra quotes dropped');
done_testing;