import Devel-Size 0.59 from CPAN
[p5sagit/Devel-Size.git] / t / basic.t
1 # Before `make install' is performed this script should be runnable with
2 # `make test'. After `make install' it should work as `perl test.pl'
3
4 ######################### We start with some black magic to print on failure.
5
6 # Change 1..1 below to 1..last_test_to_print .
7 # (It may become useful if the test is moved to ./t subdirectory.)
8
9 BEGIN { $| = 1; print "1..8\n"; }
10 END {print "not ok 1\n" unless $loaded;}
11 use Devel::Size qw(size total_size);
12 $loaded = 1;
13 print "ok 1\n";
14
15 ######################### End of black magic.
16
17 # Insert your test code below (better if it prints "ok 13"
18 # (correspondingly "not ok 13") depending on the success of chunk 13
19 # of the test code):
20
21 use vars qw($foo @foo %foo);
22 $foo = "12";
23 @foo = (1,2,3);
24 %foo = (a => 1, b => 2);
25
26 my $x = "A string";
27 my $y = "A longer string";
28 if (size($x) < size($y)) {
29     print "ok 2\n";
30 } else {
31     print "not ok 2\n";
32 }
33
34 if (total_size($x) < total_size($y)) {
35     print "ok 3\n";
36 } else {
37     print "not ok 3\n";
38 }
39
40 my @x = (1..4);
41 my @y = (1..10);
42
43 if (size(\@x) < size(\@y)) {
44     print "ok 4\n";
45 } else {
46     print "not ok 4\n";
47 }
48
49 if (total_size(\@x) < total_size(\@y)) {
50     print "ok 5\n";
51 } else {
52     print "not ok 5\n";
53 }
54
55 # check that the tracking_hash is working
56
57 my($a,$b) = (1,2);
58 my @ary1 = (\$a, \$a);
59 my @ary2 = (\$a, \$b);
60
61 if (total_size(\@ary1) < total_size(\@ary2)) {
62     print "ok 6\n";
63 } else {
64     print "not ok 6\n";
65 }
66
67 # check that circular references don't mess things up
68
69 my($c1,$c2); $c2 = \$c1; $c1 = \$c2;
70
71 if( total_size($c1) == total_size($c2) ) {
72     print "ok 7\n";
73 } else {
74     print "not ok 7\n";
75 }
76
77 if (total_size(*foo)) {
78    print "ok 8\n";
79 } else {
80   print "not ok 8\n";
81 }