diff options
author | Eric Wong <e@80x24.org> | 2021-04-27 11:07:52 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-04-27 21:28:57 -0400 |
commit | 4b9be88e2465ffcbf91901f06e19a749f6bdf818 (patch) | |
tree | 340f766d10c20fe634b9a5b873e21fdb9f03109b /t/lei_lcat.t | |
parent | 787cbc523c0beac69f6df8b8a689684864a6594e (diff) | |
download | public-inbox-4b9be88e2465ffcbf91901f06e19a749f6bdf818.tar.gz |
It's a wrapper around "lei q" which extracts Message-IDs from URLs, "<$MSGID>", "id:$MSGID" and attempts to display the local version of the message. Its main purpose is to extract Message-IDs out of commonly-understood URLs to save users bandwidth and time by displaying the message locally. When reading from stdin, it will discard things it doesn't understand, so you can just pipe an entire "Link: $URL" line to it and it'll attempt to pluck the Message-ID out of the URL.
Diffstat (limited to 't/lei_lcat.t')
-rw-r--r-- | t/lei_lcat.t | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/t/lei_lcat.t b/t/lei_lcat.t new file mode 100644 index 00000000..536abdea --- /dev/null +++ b/t/lei_lcat.t @@ -0,0 +1,44 @@ +#!perl -w +# Copyright (C) 2021 all contributors <meta@public-inbox.org> +# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> +# unit test for "lei lcat" internals, see t/lei-lcat.t for functional test +use strict; +use v5.10.1; +use Test::More; +use_ok 'PublicInbox::LeiLcat'; +my $cb = \&PublicInbox::LeiLcat::extract_1; +my $ck = sub { + my ($txt, $exp, $t) = @_; + my $lei = {}; + is($cb->($lei, $txt), $exp, $txt); + ($t ? is_deeply($lei, { mset_opt => { threads => 1 } }, "-t $exp") + : is_deeply($lei, {}, "no -t for $exp")) or diag explain($lei); +}; + +for my $txt (qw(https://example.com/inbox/foo@bar/ + https://example.com/inbox/foo@bar + https://example.com/inbox/foo@bar/raw + id:foo@bar + mid:foo@bar + <foo@bar> + <https://example.com/inbox/foo@bar> + <https://example.com/inbox/foo@bar/raw> + <https://example.com/inbox/foo@bar/> + <nntp://example.com/foo@bar>)) { + $ck->($txt, 'mid:foo@bar'); +} + +for my $txt (qw(https://example.com/inbox/foo@bar/T/ + https://example.com/inbox/foo@bar/t/ + https://example.com/inbox/foo@bar/t.mbox.gz + <https://example.com/inbox/foo@bar/t.atom> + <https://example.com/inbox/foo@bar/t/>)) { + $ck->($txt, 'mid:foo@bar', '-t'); +} + +$ck->('https://example.com/x/foobar/T/', 'mid:foobar', '-t'); +$ck->('https://example.com/x/foobar/raw', 'mid:foobar'); +is($cb->(my $lei = {}, 'asdf'), undef, 'no Message-ID'); +is($cb->($lei = {}, 'm:x'), 'm:x', 'bare m: accepted'); + +done_testing; |