VMS specific cleanup and strictness for tie_sdbm.t
[p5sagit/p5-mst-13.2.git] / lib / Memoize / t / expire_module_n.t
CommitLineData
a0cb3900 1#!/usr/bin/perl
2
5317c87c 3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6}
a0cb3900 7use Memoize;
8
9my $n = 0;
10
11
899dc88a 12print "1..22\n";
a0cb3900 13
14++$n; print "ok $n\n";
15
16$RETURN = 1;
17
18%CALLS = ();
19sub call {
20# print "CALL $_[0] => $RETURN\n";
21 ++$CALLS{$_[0]};
22 $RETURN;
23}
24
899dc88a 25require Memoize::Expire;
26++$n; print "ok $n\n";
27
28tie my %cache => 'Memoize::Expire', NUM_USES => 2;
a0cb3900 29memoize 'call',
899dc88a 30 SCALAR_CACHE => [HASH => \%cache],
a0cb3900 31 LIST_CACHE => 'FAULT';
32
33# $Memoize::Expire::DEBUG = 1;
34++$n; print "ok $n\n";
35
36# 3--6
37for (0,1,2,3) {
38 print "not " unless call($_) == 1;
39 ++$n; print "ok $n\n";
40}
41
42# 7--10
43for (keys %CALLS) {
44 print "not " unless $CALLS{$_} == (1,1,1,1)[$_];
45 ++$n; print "ok $n\n";
46}
47
48# 11--13
49$RETURN = 2;
50++$n; print ((call(1) == 1 ? '' : 'not '), "ok $n\n"); # 1 expires
51++$n; print ((call(1) == 2 ? '' : 'not '), "ok $n\n"); # 1 gets new val
52++$n; print ((call(2) == 1 ? '' : 'not '), "ok $n\n"); # 2 expires
53
54# 14--17
55$RETURN = 3;
56for (0,1,2,3) {
57 # 0 expires, 1 expires, 2 gets new val, 3 expires
58 print "not " unless call($_) == (1,2,3,1)[$_];
59 ++$n; print "ok $n\n";
60}
61
62for (0,1,2,3) {
63 print "not " unless $CALLS{$_} == (1,2,2,1)[$_];
64 ++$n; print "ok $n\n";
65}