X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fthread-cycle.t;h=7d85909f1f9a534186707f3d84fe7b404fe55d15;hb=e350de7fdbe12dafc36e893e66ce8c93ec6dc3f2;hp=4d60f7e39bcb8df3f99411c921e0c2924ae30157;hpb=30100c46326e2eac275e0af13116636701d2537e;p=public-inbox.git diff --git a/t/thread-cycle.t b/t/thread-cycle.t index 4d60f7e3..7d85909f 100644 --- a/t/thread-cycle.t +++ b/t/thread-cycle.t @@ -1,9 +1,8 @@ -# Copyright (C) 2016 all contributors +# Copyright (C) 2016-2018 all contributors # License: AGPL-3.0+ use strict; use warnings; use Test::More; -use_ok('PublicInbox::SearchMsg'); use_ok('PublicInbox::SearchThread'); use Email::Simple; my $mt = eval { @@ -51,18 +50,7 @@ my @msgs = map { } ); -my $th = PublicInbox::SearchThread->new(\@msgs); -$th->thread; -$th->order(sub { [ sort { $a->{id} cmp $b->{id} } @{$_[0]} ] }); -my $st = ''; -my @q = map { (0, $_) } @{$th->{rootset}}; -while (@q) { - my $level = shift @q; - my $node = shift @q or next; - $st .= (" "x$level). "$node->{id}\n"; - my $cl = $level + 1; - unshift @q, map { ($cl, $_) } @{$node->{children}} -} +my $st = thread_to_s(\@msgs); SKIP: { skip 'Mail::Thread missing', 1 unless $mt; @@ -71,7 +59,7 @@ SKIP: { $mt->order(sub { sort { $a->messageid cmp $b->messageid } @_ }); my $check = ''; - @q = map { (0, $_) } $mt->rootset; + my @q = map { (0, $_) } $mt->rootset; while (@q) { my $level = shift @q; my $node = shift @q or next; @@ -83,4 +71,18 @@ SKIP: { done_testing(); -1; +sub thread_to_s { + my ($msgs) = @_; + my $rootset = PublicInbox::SearchThread::thread($msgs, sub { + [ sort { $a->{id} cmp $b->{id} } @{$_[0]} ] }); + my $st = ''; + my @q = map { (0, $_) } @$rootset; + while (@q) { + my $level = shift @q; + my $node = shift @q or next; + $st .= (" "x$level). "$node->{id}\n"; + my $cl = $level + 1; + unshift @q, map { ($cl, $_) } @{$node->{children}}; + } + $st; +}