]> git.vpit.fr Git - perl/modules/Sub-Nary.git/blob - t/11-cache.t
Update VPIT::TestHelpers to 15e8aee3
[perl/modules/Sub-Nary.git] / t / 11-cache.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 10;
7
8 use Sub::Nary;
9
10 sub wat {
11  wantarray ? (1, 2) : 1;
12 }
13
14 my $sn = Sub::Nary->new();
15
16 my $r = { 1 => 0.5, 2 => 0.5 };
17
18 is_deeply($sn->nary(\&wat), $r, 'first run, without cache');
19 isnt(keys %{$sn->{cache}}, 0, 'cache isn\'t empty');
20 is_deeply($sn->nary(\&wat), $r, 'second run, cached');
21 isnt(keys %{$sn->{cache}}, 0, 'cache isn\'t empty');
22
23 my $sn2 = $sn->flush();
24 is_deeply( [ defined $sn2, $sn2->isa('Sub::Nary') ], [ 1, 1 ], 'flush ');
25 is(keys %{$sn->{cache}}, 0, 'cache is empty');
26
27 is_deeply($sn->nary(\&wat), $r, 'third run, without cache');
28 isnt(keys %{$sn->{cache}}, 0, 'cache isn\'t empty');
29 is_deeply($sn->nary(\&wat), $r, 'fourth run, cached');
30 isnt(keys %{$sn->{cache}}, 0, 'cache isn\'t empty');