X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fimap.t;h=e6efe04f7702c0c6a2b92f23ec8da32fbd9e77c6;hb=refs%2Fheads%2Fmaster;hp=81b3d844e76013aee4b7310369c11d9844748a84;hpb=12b21f035cc223ea3782bef7102160cc3f0ee214;p=public-inbox.git diff --git a/t/imap.t b/t/imap.t index 81b3d844..e6efe04f 100644 --- a/t/imap.t +++ b/t/imap.t @@ -1,29 +1,14 @@ #!perl -w -# Copyright (C) 2020 all contributors +# Copyright (C) 2020-2021 all contributors # License: AGPL-3.0+ # unit tests (no network) for IMAP, see t/imapd.t for end-to-end tests use strict; -use Test::More; -use PublicInbox::IMAP; -use PublicInbox::IMAPD; +use v5.10.1; use PublicInbox::TestCommon; -require_mods(qw(DBD::SQLite)); require_git 2.6; -use POSIX qw(strftime); - -{ - my $parse_date = \&PublicInbox::IMAP::parse_date; - is(strftime('%Y-%m-%d', gmtime($parse_date->('02-Oct-1993'))), - '1993-10-02', 'parse_date works'); - is(strftime('%Y-%m-%d', gmtime($parse_date->('2-Oct-1993'))), - '1993-10-02', 'parse_date works w/o leading zero'); - - is($parse_date->('2-10-1993'), undef, 'bad month'); - - # from what I can tell, RFC 3501 says nothing about date-month - # case-insensitivity, so be case-sensitive for now - is($parse_date->('02-oct-1993'), undef, 'case-sensitive month'); -} +require_mods(qw(-imapd)); +require_ok 'PublicInbox::IMAP'; +require_ok 'PublicInbox::IMAPD'; my ($tmpdir, $for_destroy) = tmpdir(); my $cfgfile = "$tmpdir/config"; @@ -130,4 +115,47 @@ EOF ], 'placed op_eml_new before emit_body'); } +# UID <=> MSN mapping + +sub uo2m_str_new ($) { + no warnings 'uninitialized'; # uom2m_ary_new may have may have undef + pack('S*', @{$_[0]->uo2m_ary_new}); # 2 bytes per-MSN +} + +{ + my $ibx = bless { uid_range => [ 1, 2, 4 ] }, 'Uo2mTestInbox'; + my $imap = bless { uid_base => 0, ibx => $ibx }, 'PublicInbox::IMAP'; + my $uo2m = $imap->uo2m_ary_new; + is_deeply($uo2m, [ 1, 2, undef, 3 ], 'uo2m ary'); + $uo2m = uo2m_str_new($imap); + is_deeply([ unpack('S*', $uo2m) ], [ 1, 2, 0, 3 ], 'uo2m str'); + + $ibx->{uid_range} = [ 1, 2, 4, 5, 6 ]; + for ([ 1, 2, undef, 3 ], $uo2m) { + $imap->{uo2m} = $_; + is($imap->uid2msn(1), 1, 'uid2msn'); + is($imap->uid2msn(4), 3, 'uid2msn'); + is($imap->uo2m_last_uid, 4, 'uo2m_last_uid'); + $imap->uo2m_extend(6); + is($imap->uid2msn(5), 4, 'uid2msn 5 => 4'); + is($imap->uid2msn(6), 5, 'uid2msn 6 => 5'); + is($imap->uo2m_last_uid, 6, 'uo2m_last_uid'); + + my $msn2uid = $imap->msn2uid; + my $range = '1,4:5'; + $imap->can('msn_to_uid_range')->($msn2uid, $range); + is($range, '1,5:6', 'range converted'); + } +} + done_testing; + +package Uo2mTestInbox; +use strict; +require PublicInbox::DummyInbox; +our @ISA = qw(PublicInbox::DummyInbox); +sub over { shift } +sub uid_range { + my ($self, $beg, $end, undef) = @_; + [ grep { $_ >= $beg && $_ <= $end } @{$self->{uid_range}} ]; +}