1 # Copyright (C) 2018-2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use Compress::Zlib qw(compress);
7 use PublicInbox::TestCommon;
8 foreach my $mod (qw(DBD::SQLite)) {
10 plan skip_all => "$mod missing for over.t" if $@;
13 use_ok 'PublicInbox::OverIdx';
14 my ($tmpdir, $for_destroy) = tmpdir();
15 my $over = PublicInbox::OverIdx->new("$tmpdir/over.sqlite3");
17 my $x = $over->next_tid;
18 is(int($x), $x, 'integer tid');
19 my $y = $over->next_tid;
20 is($y, $x+1, 'tid increases');
22 $x = $over->sid('hello-world');
23 is(int($x), $x, 'integer sid');
24 $y = $over->sid('hello-WORLD');
25 is($y, $x+1, 'sid ncreases');
26 is($over->sid('hello-world'), $x, 'idempotent');
29 $over = PublicInbox::OverIdx->new("$tmpdir/over.sqlite3");
31 is($over->sid('hello-world'), $x, 'idempotent across reopen');
32 $over->each_by_mid('never', sub { fail('should not be called') });
34 $x = $over->create_ghost('never');
35 is(int($x), $x, 'integer tid for ghost');
36 $y = $over->create_ghost('NEVAR');
37 is($y, $x + 1, 'integer tid for ghost increases');
39 my $ddd = compress('');
40 foreach my $s ('', undef) {
41 $over->add_over([0, 0, 98, [ 'a' ], [], $s, $ddd]);
42 $over->add_over([0, 0, 99, [ 'b' ], [], $s, $ddd]);
43 my $msgs = [ map { $_->{num} } @{$over->get_thread('a')} ];
44 is_deeply([98], $msgs,
45 'messages not linked by empty subject');
48 $over->add_over([0, 0, 98, [ 'a' ], [], 's', $ddd]);
49 $over->add_over([0, 0, 99, [ 'b' ], [], 's', $ddd]);
50 foreach my $mid (qw(a b)) {
51 my $msgs = [ map { $_->{num} } @{$over->get_thread('a')} ];
52 is_deeply([98, 99], $msgs, 'linked messages by subject');
54 $over->add_over([0, 0, 98, [ 'a' ], [], 's', $ddd]);
55 $over->add_over([0, 0, 99, [ 'b' ], ['a'], 'diff', $ddd]);
56 foreach my $mid (qw(a b)) {
57 my $msgs = [ map { $_->{num} } @{$over->get_thread($mid)} ];
58 is_deeply([98, 99], $msgs, "linked messages by Message-ID: <$mid>");