1 # Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use_ok 'PublicInbox::Inbox';
7 use File::Temp 0.19 ();
8 my $x = PublicInbox::Inbox->new({url => [ '//example.com/test/' ]});
9 is($x->base_url, 'https://example.com/test/', 'expanded protocol-relative');
10 $x = PublicInbox::Inbox->new({url => [ 'http://example.com/test' ]});
11 is($x->base_url, 'http://example.com/test/', 'added trailing slash');
13 $x = PublicInbox::Inbox->new({});
15 is($x->base_url, undef, 'undef base_url allowed');
16 my $tmpdir = File::Temp->newdir('pi-inbox-XXXX', TMPDIR => 1);
17 $x->{inboxdir} = $tmpdir->dirname;
18 is_deeply($x->cloneurl, [], 'no cloneurls');
19 is($x->description, '($INBOX_DIR/description missing)', 'default description');
21 open my $fh, '>', "$x->{inboxdir}/cloneurl" or die;
22 print $fh "https://example.com/inbox\n" or die;
24 open $fh, '>', "$x->{inboxdir}/description" or die;
25 print $fh "\xc4\x80blah\n" or die;
28 is_deeply($x->cloneurl, ['https://example.com/inbox'], 'cloneurls update');
29 ok(utf8::valid($x->description), 'description is utf8::valid');
30 is($x->description, "\x{100}blah", 'description updated');
31 is(unlink(glob("$x->{inboxdir}/*")), 2, 'unlinked cloneurl & description');
32 is_deeply($x->cloneurl, ['https://example.com/inbox'], 'cloneurls memoized');
33 is($x->description, "\x{100}blah", 'description memoized');
35 $x->{name} = "2\x{100}wide";
36 $x->{newsgroup} = '2.wide';
37 like($x->mailboxid, qr/\AM32c48077696465-[0-9a-f]+\z/,
38 '->mailboxid w/o slice (JMAP)');
39 like($x->mailboxid(78), qr/\AM322e77696465-4e-[0-9a-f]+\z/,
40 '->mailboxid w/ slice (IMAP)');