]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/search.t
searchidx: remove v1-only msg_mime sub
[public-inbox.git] / t / search.t
index 6cf2bc2d6b428938d1cb2ab6c9f7c355cc540f8d..299f57c85ee0c505c545310f3ad9afd32bfa42a5 100644 (file)
@@ -21,8 +21,8 @@ ok($@, "exception raised on non-existent DB");
 
 my $rw = PublicInbox::SearchIdx->new($ibx, 1);
 $ibx->with_umask(sub {
-       $rw->_xdb_acquire;
-       $rw->_xdb_release;
+       $rw->idx_acquire;
+       $rw->idx_release;
 });
 $rw = undef;
 my $ro = PublicInbox::Search->new($ibx);
@@ -59,6 +59,14 @@ sub oct_is ($$$) {
        }
 }
 
+{
+       my $crlf_adjust = \&PublicInbox::SearchIdx::crlf_adjust;
+       is($crlf_adjust->("hi\r\nworld\r\n"), 0, 'no adjustment needed');
+       is($crlf_adjust->("hi\nworld\n"), 2, 'LF-only counts two CR');
+       is($crlf_adjust->("hi\r\nworld\n"), 1, 'CRLF/LF-mix 1 counts 1 CR');
+       is($crlf_adjust->("hi\nworld\r\n"), 1, 'CRLF/LF-mix 2 counts 1 CR');
+}
+
 $ibx->with_umask(sub {
        my $root = PublicInbox::Eml->new(<<'EOF');
 Date: Fri, 02 Oct 1993 00:00:00 +0000
@@ -318,6 +326,17 @@ $ibx->with_umask(sub {
        foreach my $m ($mset->items) {
                my $smsg = $ro->{over_ro}->get_art($m->get_docid);
                like($smsg->{to}, qr/\blist\@example\.com\b/, 'to appears');
+               my $doc = $m->get_document;
+               my $col = PublicInbox::Search::BYTES();
+               my $bytes = PublicInbox::Smsg::get_val($doc, $col);
+               like($bytes, qr/\A[0-9]+\z/, '$bytes stored as digit');
+               ok($bytes > 0, '$bytes is > 0');
+               is($bytes, $smsg->{bytes}, 'bytes Xapian value matches Over');
+
+               $col = PublicInbox::Search::UID();
+               my $uid = PublicInbox::Smsg::get_val($doc, $col);
+               is($uid, $smsg->{num}, 'UID column matches {num}');
+               is($uid, $m->get_docid, 'UID column matches docid');
        }
 
        $mset = $ro->query('tc:list@example.com', {mset => 1});
@@ -378,7 +397,9 @@ $ibx->with_umask(sub {
 
 $ibx->with_umask(sub {
        my $amsg = eml_load 't/search-amsg.eml';
-       ok($rw->add_message($amsg), 'added attachment');
+       my $oid = ('0'x40);
+       my $smsg = bless { blob => $oid }, 'PublicInbox::Smsg';
+       ok($rw->add_message($amsg, $smsg), 'added attachment');
        $rw_commit->();
        $ro->reopen;
        my $n = $ro->query('n:attached_fart.txt');
@@ -399,7 +420,8 @@ $ibx->with_umask(sub {
                $art = $ro->{over_ro}->next_by_mid($mid, \$id, \$prev);
                ok($art, 'article exists in OVER DB');
        }
-       $rw->unindex_blob($amsg);
+       $rw->_msgmap_init;
+       $rw->unindex_eml($oid, $amsg);
        $rw->commit_txn_lazy;
        SKIP: {
                skip('$art not defined', 1) unless defined $art;