1 # Copyright (C) 2016-2018 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use_ok('PublicInbox::SearchThread');
11 $Mail::Thread::nosubject = 1;
12 $Mail::Thread::noprune = 1;
17 $msg->{references} =~ s/\s+/ /sg if $msg->{references};
18 my $simple = Email::Simple->create(header => [
19 'Message-Id' => "<$msg->{mid}>",
20 'References' => $msg->{references},
23 bless $msg, 'PublicInbox::SearchMsg'
26 # data from t/testbox-6 in Mail::Thread 2.55:
27 { mid => '20021124145312.GA1759@nlin.net' },
28 { mid => 'slrnau448m.7l4.markj+0111@cloaked.freeserve.co.uk',
29 references => '<20021124145312.GA1759@nlin.net>',
31 { mid => '15842.10677.577458.656565@jupiter.akutech-local.de',
32 references => '<20021124145312.GA1759@nlin.net>
33 <slrnau448m.7l4.markj+0111@cloaked.freeserve.co.uk>',
35 { mid => '20021125171807.GK8236@somanetworks.com',
36 references => '<20021124145312.GA1759@nlin.net>
37 <slrnau448m.7l4.markj+0111@cloaked.freeserve.co.uk>
38 <15842.10677.577458.656565@jupiter.akutech-local.de>',
40 { mid => '15843.12163.554914.469248@jupiter.akutech-local.de',
41 references => '<20021124145312.GA1759@nlin.net>
42 <slrnau448m.7l4.markj+0111@cloaked.freeserve.co.uk>
43 <15842.10677.577458.656565@jupiter.akutech-local.de>
44 <E18GPHf-0000zp-00@cloaked.freeserve.co.uk>',
46 { mid => 'E18GPHf-0000zp-00@cloaked.freeserve.co.uk',
47 references => '<20021124145312.GA1759@nlin.net>
48 <slrnau448m.7l4.markj+0111@cloaked.freeserve.co.uk>
49 <15842.10677.577458.656565@jupiter.akutech-local.de>'
53 my $st = thread_to_s(\@msgs);
56 skip 'Mail::Thread missing', 1 unless $mt;
57 $mt = Mail::Thread->new(@check);
59 $mt->order(sub { sort { $a->messageid cmp $b->messageid } @_ });
62 my @q = map { (0, $_) } $mt->rootset;
65 my $node = shift @q or next;
66 $check .= (" "x$level) . $node->messageid . "\n";
67 unshift @q, $level + 1, $node->child, $level, $node->next;
69 is($check, $st, 'Mail::Thread output matches');
76 my $rootset = PublicInbox::SearchThread::thread($msgs, sub {
77 [ sort { $a->{id} cmp $b->{id} } @{$_[0]} ] });
79 my @q = map { (0, $_) } @$rootset;
82 my $node = shift @q or next;
83 $st .= (" "x$level). "$node->{id}\n";
85 unshift @q, map { ($cl, $_) } @{$node->{children}};