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