about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-01-05 09:04:37 +0000
committerEric Wong <e@80x24.org>2021-01-06 10:45:09 +0000
commit348e7a39627fd40d7cc0ca1be01412da51a71352 (patch)
tree00af1f86f9aa4cb935f4d6638217b2a8ea97b1ac /t
parent27f8e2b161f4a8bb1ef030bd45e3f5ae7a9f0bb0 (diff)
downloadpublic-inbox-348e7a39627fd40d7cc0ca1be01412da51a71352.tar.gz
Per JMAP RFC 8621 sec 4.1.2.3, we should be able to
denote the lack of a phrase/comment corresponding to an
email address with a JSON "null" (or Perl `undef').

  [
    { "name": "James Smythe", "email": "james@example.com" },
    { "name": null, "email": "jane@example.com" },
    { "name": "John Smith", "email": "john@example.com" }
  ]

The new "pairs" method just returns a 2 dimensional array
and the consumer will fill in the field names if necessary
(or not).

lei(1) may use the two dimensional array as-is for JSON output.
Diffstat (limited to 't')
-rw-r--r--t/address.t33
1 files changed, 27 insertions, 6 deletions
diff --git a/t/address.t b/t/address.t
index 0adcf46d..6aa94628 100644
--- a/t/address.t
+++ b/t/address.t
@@ -7,26 +7,40 @@ use_ok 'PublicInbox::Address';
 
 sub test_pkg {
         my ($pkg) = @_;
-        my $emails = \&{"${pkg}::emails"};
-        my $names = \&{"${pkg}::names"};
+        my $emails = $pkg->can('emails');
+        my $names = $pkg->can('names');
+        my $pairs = $pkg->can('pairs');
 
         is_deeply([qw(e@example.com e@example.org)],
                 [$emails->('User <e@example.com>, e@example.org')],
                 'address extraction works as expected');
 
+        is_deeply($pairs->('User <e@example.com>, e@example.org'),
+                        [[qw(User e@example.com)], [undef, 'e@example.org']],
+                "pair extraction works ($pkg)");
+
         is_deeply(['user@example.com'],
                 [$emails->('<user@example.com (Comment)>')],
                 'comment after domain accepted before >');
+        is_deeply($pairs->('<user@example.com (Comment)>'),
+                [[qw(Comment user@example.com)]], "comment as name ($pkg)");
 
-        my @names = $names->(
-                'User <e@e>, e@e, "John A. Doe" <j@d>, <x@x>, <y@x> (xyz), '.
-                'U Ser <u@x> (do not use)');
+        my $s = 'User <e@e>, e@e, "John A. Doe" <j@d>, <x@x>, <y@x> (xyz), '.
+                'U Ser <u@x> (do not use)';
+        my @names = $names->($s);
         is_deeply(\@names, ['User', 'e', 'John A. Doe', 'x', 'xyz', 'U Ser'],
                 'name extraction works as expected');
+        is_deeply($pairs->($s), [ [ 'User', 'e@e' ], [ undef, 'e@e' ],
+                        [ 'John A. Doe', 'j@d' ], [ undef, 'x@x' ],
+                        [ 'xyz', 'y@x' ], [ 'U Ser', 'u@x' ] ],
+                "pairs extraction works for $pkg");
 
         @names = $names->('"user@example.com" <user@example.com>');
         is_deeply(['user'], \@names,
                 'address-as-name extraction works as expected');
+        is_deeply($pairs->('"user@example.com" <user@example.com>'),
+                [ [ 'user@example.com', 'user@example.com' ] ],
+                "pairs for $pkg");
 
         {
                 my $backwards = 'u@example.com (John Q. Public)';
@@ -34,10 +48,17 @@ sub test_pkg {
                 is_deeply(\@names, ['John Q. Public'], 'backwards name OK');
                 my @emails = $emails->($backwards);
                 is_deeply(\@emails, ['u@example.com'], 'backwards emails OK');
+
+                is_deeply($pairs->($backwards),
+                        [ [ 'John Q. Public', 'u@example.com' ] ],
+                        "backwards pairs $pkg");
         }
 
-        @names = $names->('"Quote Unneeded" <user@example.com>');
+        $s = '"Quote Unneeded" <user@example.com>';
+        @names = $names->($s);
         is_deeply(['Quote Unneeded'], \@names, 'extra quotes dropped');
+        is_deeply($pairs->($s), [ [ 'Quote Unneeded', 'user@example.com' ] ],
+                "extra quotes dropped in pairs $pkg");
 
         my @emails = $emails->('Local User <user>');
         is_deeply([], \@emails , 'no address for local address');