X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fbasic.t;h=80a03ec0c31a91a91a9938976f2752ce6555486e;hb=638a265a89c75e2418ddc1c87a560bb8022ea667;hp=ff6478a6834e5af1ebadad699118638a3abc64e9;hpb=0f6519384a2c1182532e669235866c459dbd17d2;p=p5sagit%2FDevel-Size.git diff --git a/t/basic.t b/t/basic.t index ff6478a..80a03ec 100644 --- a/t/basic.t +++ b/t/basic.t @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -use Test::More tests => 19; +use Test::More tests => 26; use strict; use Devel::Size qw(size total_size); @@ -123,3 +123,25 @@ foreach(['undef', total_size(undef)], "Size doesn't change because OOK is used"); cmp_ok(length $uurk, '<', $before_size, 'but string is shorter'); } + +sub shared_hash_keys { + my %h = @_; + my $one = total_size([keys %h]); + cmp_ok($one, '>', 0, 'Size of one entry is sane'); + my $two = total_size([keys %h, keys %h]); + cmp_ok($two, '>', $one, 'Two take more space than one'); + my $increment = $two - $one; + is(total_size([keys %h, keys %h, keys %h]), $one + 2 * $increment, + 'Linear size increase for three'); + return $increment; +} + +{ + my $small = shared_hash_keys(Perl => 'Rules'); + my $big = shared_hash_keys('x' x 1024, ''); + SKIP: { + skip("[keys %h] doesn't copy as shared hash key scalars prior to 5.10.0", + 1) if $] < 5.010; + is ($small, $big, 'The "shared" part of shared hash keys is spotted'); + } +}