X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FDevel-Size.git;a=blobdiff_plain;f=t%2Fmagic.t;h=08d7eb0b9ae5e09aa0fe7cf6ba2501e62abb0ff5;hp=d0f5b73fad9bd78237fda19d9581850467364237;hb=b71309488bc6064635eabcac81bb327bb6a01b93;hpb=72e2658d6b79549c2318c52724ff39fd6357c359 diff --git a/t/magic.t b/t/magic.t index d0f5b73..08d7eb0 100644 --- a/t/magic.t +++ b/t/magic.t @@ -1,7 +1,7 @@ #!/usr/bin/perl -w use strict; -use Test::More tests => 7; +use Test::More tests => 11; use Devel::Size ':all'; require Tie::Scalar; @@ -31,3 +31,22 @@ require Tie::Scalar; cmp_ok($after_size, '>', $before_size, 'Still larger than initial size'); cmp_ok($after_size, '<', $compiled_size, 'size decreases due to unmagic'); } + +{ + my $string = 'Perl Rules'; + my $before_size = total_size($string); + cmp_ok($before_size, '>', length $string, + 'Our string has a non-zero length'); + tie $string, 'Tie::StdScalar'; + my $after_size = total_size($string); + cmp_ok($after_size, '>', $before_size, 'size increases due to magic'); + is($string, undef, 'No value yet'); + # This is defineately cheating, in that we're poking inside the + # implementation of Tie::StdScalar, but if we just write to $string, the way + # magic works, the (nice long) value is first written to the regular scalar, + # then picked up by the magic. So it grows, which defeats the purpose of the + # test. + ${tied $string} = 'X' x 1024; + cmp_ok(total_size($string), '>', $after_size + 1024, + 'the magic object is counted'); +}