-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
422e290
commit cb87578
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!perl -wT | ||
|
||
use strict; | ||
use warnings; | ||
use Test::Most tests => 8; | ||
use Test::NoWarnings; | ||
use utf8; | ||
|
||
BEGIN { | ||
use_ok('Class::Simple::Readonly::Cached'); | ||
} | ||
|
||
HASH: { | ||
my $cache = {}; | ||
my $cached = new_ok('Class::Simple::Readonly::Cached' => [ cache => $cache, object => x->new() ]); | ||
|
||
|
||
ok($cached->utf8('Mrkvička') eq 'Mrkvička'); | ||
ok($cached->utf8() eq 'Mrkvička'); | ||
ok($cached->utf8() eq 'Mrkvička'); | ||
|
||
# White box test the cache | ||
ok($cache->{'utf8::'} eq 'Mrkvička'); | ||
|
||
# foreach my $key(sort keys %{$cache}) { | ||
# diag($key); | ||
# } | ||
|
||
# diag(Data::Dumper->new([$cached->state()])->Dump()); | ||
my $misses = $cached->state()->{'misses'}; | ||
my $fail; | ||
while(my($k, $v) = each %{$misses}) { | ||
if($v != 1) { | ||
$fail = $k; | ||
last; | ||
} | ||
} | ||
ok(!defined($fail)); | ||
diag($fail) if($fail); | ||
} | ||
|
||
package x; | ||
|
||
sub new { | ||
my $proto = shift; | ||
|
||
my $class = ref($proto) || $proto; | ||
|
||
return bless { }, $class; | ||
} | ||
|
||
sub utf8 { | ||
my $self = shift; | ||
my $param = shift; | ||
|
||
return 'Mrkvička'; | ||
} | ||
|
||
1; |