]> Sergey Matveev's repositories - public-inbox.git/blob - t/lei_lcat.t
lei_mirror: simplify clone_v2_prep
[public-inbox.git] / t / lei_lcat.t
1 #!perl -w
2 # Copyright (C) 2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # unit test for "lei lcat" internals, see t/lei-lcat.t for functional test
5 use strict;
6 use v5.10.1;
7 use Test::More;
8 use_ok 'PublicInbox::LeiLcat';
9 my $cb = \&PublicInbox::LeiLcat::extract_1;
10 my $ck = sub {
11         my ($txt, $exp, $t) = @_;
12         my $lei = {};
13         is($cb->($lei, $txt), $exp, $txt);
14         ($t ? is_deeply($lei, { mset_opt => { threads => 1 } }, "-t $exp")
15                 : is_deeply($lei, {}, "no -t for $exp")) or diag explain($lei);
16 };
17
18 for my $txt (qw(https://example.com/inbox/foo@bar/
19                 https://example.com/inbox/foo@bar
20                 https://example.com/inbox/foo@bar/raw
21                 id:foo@bar
22                 mid:foo@bar
23                 <foo@bar>
24                 <https://example.com/inbox/foo@bar>
25                 <https://example.com/inbox/foo@bar/raw>
26                 <https://example.com/inbox/foo@bar/>
27                 <nntp://example.com/foo@bar>)) {
28         $ck->($txt, 'mid:foo@bar');
29 }
30
31 for my $txt (qw(https://example.com/inbox/foo@bar/T/
32                 https://example.com/inbox/foo@bar/t/
33                 https://example.com/inbox/foo@bar/t.mbox.gz
34                 <https://example.com/inbox/foo@bar/t.atom>
35                 <https://example.com/inbox/foo@bar/t/>)) {
36         $ck->($txt, 'mid:foo@bar', '-t');
37 }
38
39 $ck->('https://example.com/x/foobar/T/', 'mid:foobar', '-t');
40 $ck->('https://example.com/x/foobar/raw', 'mid:foobar');
41 is($cb->(my $lei = {}, 'asdf'), undef, 'no Message-ID');
42 is($cb->($lei = {}, 'm:x'), 'm:x', 'bare m: accepted');
43
44 done_testing;