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 require_mods('DBD::SQLite');
9 use_ok 'PublicInbox::OverIdx';
10 my ($tmpdir, $for_destroy) = tmpdir();
11 my $over = PublicInbox::OverIdx->new("$tmpdir/over.sqlite3");
13 my $x = $over->next_tid;
14 is(int($x), $x, 'integer tid');
15 my $y = $over->next_tid;
16 is($y, $x+1, 'tid increases');
18 $x = $over->sid('hello-world');
19 is(int($x), $x, 'integer sid');
20 $y = $over->sid('hello-WORLD');
21 is($y, $x+1, 'sid ncreases');
22 is($over->sid('hello-world'), $x, 'idempotent');
25 $over = PublicInbox::OverIdx->new("$tmpdir/over.sqlite3");
27 is($over->sid('hello-world'), $x, 'idempotent across reopen');
28 $over->each_by_mid('never', sub { fail('should not be called') });
30 $x = $over->create_ghost('never');
31 is(int($x), $x, 'integer tid for ghost');
32 $y = $over->create_ghost('NEVAR');
33 is($y, $x + 1, 'integer tid for ghost increases');
35 my $ddd = compress('');
36 foreach my $s ('', undef) {
37 $over->add_over([0, 0, 98, [ 'a' ], [], $s, $ddd]);
38 $over->add_over([0, 0, 99, [ 'b' ], [], $s, $ddd]);
39 my $msgs = [ map { $_->{num} } @{$over->get_thread('a')} ];
40 is_deeply([98], $msgs,
41 'messages not linked by empty subject');
44 $over->add_over([0, 0, 98, [ 'a' ], [], 's', $ddd]);
45 $over->add_over([0, 0, 99, [ 'b' ], [], 's', $ddd]);
46 foreach my $mid (qw(a b)) {
47 my $msgs = [ map { $_->{num} } @{$over->get_thread('a')} ];
48 is_deeply([98, 99], $msgs, 'linked messages by subject');
50 $over->add_over([0, 0, 98, [ 'a' ], [], 's', $ddd]);
51 $over->add_over([0, 0, 99, [ 'b' ], ['a'], 'diff', $ddd]);
52 foreach my $mid (qw(a b)) {
53 my $msgs = [ map { $_->{num} } @{$over->get_thread($mid)} ];
54 is_deeply([98, 99], $msgs, "linked messages by Message-ID: <$mid>");