1*0Sstevel@tonic-gate#!/usr/bin/perl
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gateuse lib 'blib/lib';
4*0Sstevel@tonic-gateuse Memoize 0.45 qw(memoize unmemoize);
5*0Sstevel@tonic-gateuse Fcntl;
6*0Sstevel@tonic-gate
7*0Sstevel@tonic-gate# print STDERR $INC{'Memoize.pm'}, "\n";
8*0Sstevel@tonic-gate
9*0Sstevel@tonic-gateprint "1..10\n";
10*0Sstevel@tonic-gate
11*0Sstevel@tonic-gate# Test MERGE
12*0Sstevel@tonic-gatesub xx {
13*0Sstevel@tonic-gate  wantarray();
14*0Sstevel@tonic-gate}
15*0Sstevel@tonic-gate
16*0Sstevel@tonic-gatemy $s = xx();
17*0Sstevel@tonic-gateprint ((!$s) ? "ok 1\n" : "not ok 1\n");
18*0Sstevel@tonic-gatemy ($a) = xx();
19*0Sstevel@tonic-gateprint (($a) ? "ok 2\n" : "not ok 2\n");
20*0Sstevel@tonic-gatememoize 'xx', LIST_CACHE => MERGE;
21*0Sstevel@tonic-gate$s = xx();
22*0Sstevel@tonic-gateprint ((!$s) ? "ok 3\n" : "not ok 3\n");
23*0Sstevel@tonic-gate($a) = xx();  # Should return cached false value from previous invocation
24*0Sstevel@tonic-gateprint ((!$a) ? "ok 4\n" : "not ok 4\n");
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate# Test FAULT
28*0Sstevel@tonic-gatesub ns {}
29*0Sstevel@tonic-gatesub na {}
30*0Sstevel@tonic-gatememoize 'ns', SCALAR_CACHE => FAULT;
31*0Sstevel@tonic-gatememoize 'na', LIST_CACHE => FAULT;
32*0Sstevel@tonic-gateeval { my $s = ns() };  # Should fault
33*0Sstevel@tonic-gateprint (($@) ?  "ok 5\n" : "not ok 5\n");
34*0Sstevel@tonic-gateeval { my ($a) = na() };  # Should fault
35*0Sstevel@tonic-gateprint (($@) ?  "ok 6\n" : "not ok 6\n");
36*0Sstevel@tonic-gate
37*0Sstevel@tonic-gate
38*0Sstevel@tonic-gate# Test HASH
39*0Sstevel@tonic-gatemy (%s, %l);
40*0Sstevel@tonic-gatesub nul {}
41*0Sstevel@tonic-gatememoize 'nul', SCALAR_CACHE => [HASH => \%s], LIST_CACHE => [HASH => \%l];
42*0Sstevel@tonic-gatenul('x');
43*0Sstevel@tonic-gatenul('y');
44*0Sstevel@tonic-gateprint ((join '', sort keys %s) eq 'xy' ? "ok 7\n" : "not ok 7\n");
45*0Sstevel@tonic-gateprint ((join '', sort keys %l) eq ''   ? "ok 8\n" : "not ok 8\n");
46*0Sstevel@tonic-gate() = nul('p');
47*0Sstevel@tonic-gate() = nul('q');
48*0Sstevel@tonic-gateprint ((join '', sort keys %s) eq 'xy' ? "ok 9\n" : "not ok 9\n");
49*0Sstevel@tonic-gateprint ((join '', sort keys %l) eq 'pq' ? "ok 10\n" : "not ok 10\n");
50*0Sstevel@tonic-gate
51