1 # Copyright (C) 2018 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use File::Temp qw/tempdir/;
7 use Compress::Zlib qw(compress);
8 # FIXME: allow using Over w/o Xapian
9 foreach my $mod (qw(DBD::SQLite Search::Xapian)) {
11 plan skip_all => "$mod missing for over.t" if $@;
14 use_ok 'PublicInbox::OverIdx';
15 my $tmpdir = tempdir('pi-over-XXXXXX', TMPDIR => 1, CLEANUP => 1);
16 my $over = PublicInbox::OverIdx->new("$tmpdir/over.sqlite3");
18 my $x = $over->next_tid;
19 is(int($x), $x, 'integer tid');
20 my $y = $over->next_tid;
21 is($y, $x+1, 'tid increases');
23 $x = $over->sid('hello-world');
24 is(int($x), $x, 'integer sid');
25 $y = $over->sid('hello-WORLD');
26 is($y, $x+1, 'sid ncreases');
27 is($over->sid('hello-world'), $x, 'idempotent');
30 $over = PublicInbox::OverIdx->new("$tmpdir/over.sqlite3");
32 is($over->sid('hello-world'), $x, 'idempotent across reopen');
33 $over->each_by_mid('never', sub { fail('should not be called') });
35 $x = $over->create_ghost('never');
36 is(int($x), $x, 'integer tid for ghost');
37 $y = $over->create_ghost('NEVAR');
38 is($y, $x + 1, 'integer tid for ghost increases');
40 my $ddd = compress('');
41 foreach my $s ('', undef) {
42 $over->add_over([0, 0, 98, [ 'a' ], [], $s, $ddd]);
43 $over->add_over([0, 0, 99, [ 'b' ], [], $s, $ddd]);
44 my $msgs = [ map { $_->{num} } @{$over->get_thread('a')} ];
45 is_deeply([98], $msgs,
46 'messages not linked by empty subject');
49 $over->add_over([0, 0, 98, [ 'a' ], [], 's', $ddd]);
50 $over->add_over([0, 0, 99, [ 'b' ], [], 's', $ddd]);
51 foreach my $mid (qw(a b)) {
52 my $msgs = [ map { $_->{num} } @{$over->get_thread('a')} ];
53 is_deeply([98, 99], $msgs, 'linked messages by subject');
55 $over->add_over([0, 0, 98, [ 'a' ], [], 's', $ddd]);
56 $over->add_over([0, 0, 99, [ 'b' ], ['a'], 'diff', $ddd]);
57 foreach my $mid (qw(a b)) {
58 my $msgs = [ map { $_->{num} } @{$over->get_thread($mid)} ];
59 is_deeply([98, 99], $msgs, "linked messages by Message-ID: <$mid>");