File Coverage

File:t/00-example.t
Coverage:100.0%

linestmtbrancondsubpodtimecode
1
1
1
1
2884
2
25
use strict;
2
1
1
1
3
1
37
use warnings;
3
1
1
1
413
145576
16
use Test::More;
4
1
1
1
811
4
2193
use Dispatch::Fu;
5
6sub _runner {
7
99
122
    my $INPUT = shift;
8
9    my ($ouput, $canary) = dispatch {
10
99
111
        my $input_ref = shift;
11
12        # checking internal inspection routine, cases
13
99
134
        my @cases = cases;
14
99
264
        is 7, @cases, q{found expected number of cases};
15
16
99
25982
        return ( scalar @$input_ref > 5 )
17          ? q{case5}
18          : sprintf qq{case%d}, scalar @$input_ref;
19    }
20    $INPUT,
21
1
3
      on case0 => sub { return qw/0 +/ },
22
1
2
      on case1 => sub { return qw/1 +/ },
23
1
2
      on case2 => sub { return qw/2 +/ },
24
1
4
      on case3 => sub { return qw/3 +/ },
25
1
3
      on case4 => sub { return qw/4 +/ },
26
99
94
908
221
      on case5 => sub { return qw/5 +/ };
27
28
99
731
    my @cases = cases;
29
99
230
    is 1, @cases, q{found expected number of cases};
30
31    # quick test to make sure files get returned as expected when run in
32    # a loop, necessarily involves clearing $DISPATCH_TABLE and rebuilding it
33
99
25966
    is $canary, q{+}, q{return LIST working fine.};
34
35
99
25640
    return $ouput;
36}
37
38
1
104645
my @queue = ();
39
1
4
foreach my $i ( 0 .. 5 ) {
40
6
12
    is _runner( \@queue ), $i, q{Got expected result back from dispatch};
41
6
1850
    push @queue, $i;
42}
43
44
1
3
foreach my $i ( 6 ... 98 ) {
45
93
189
    is _runner( \@queue ), 5, q{Got expected result back from dispatch};
46
93
23540
    push @queue, $i;
47}
48
49
1
8
done_testing;