Commit | Line | Data |
72e2658d |
1 | #!/usr/bin/perl -w |
2 | |
3 | use strict; |
4 | use Test::More tests => 7; |
5 | use Devel::Size ':all'; |
6 | require Tie::Scalar; |
7 | |
8 | { |
9 | my $string = 'Perl Rules'; |
10 | my $before_size = total_size($string); |
11 | is($string =~ /Perl/g, 1, 'It had better match'); |
12 | cmp_ok($before_size, '>', length $string, |
13 | 'Our string has a non-zero length'); |
14 | cmp_ok(total_size($string), '>', $before_size, |
15 | 'size increases due to magic'); |
16 | } |
17 | |
18 | { |
19 | my $string = 'Perl Rules'; |
20 | my $before_size = total_size($string); |
21 | formline $string; |
22 | my $compiled_size = total_size($string); |
23 | cmp_ok($before_size, '>', length $string, |
24 | 'Our string has a non-zero length'); |
25 | cmp_ok($compiled_size, '>', $before_size, |
26 | 'size increases due to magic (and the compiled state)'); |
27 | # Not fully sure why (didn't go grovelling) but need to use a temporary to |
28 | # avoid the magic being copied. |
29 | $string = '' . $string; |
30 | my $after_size = total_size($string); |
31 | cmp_ok($after_size, '>', $before_size, 'Still larger than initial size'); |
32 | cmp_ok($after_size, '<', $compiled_size, 'size decreases due to unmagic'); |
33 | } |