]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - t/33-code.t
This is 0.64
[perl/modules/Variable-Magic.git] / t / 33-code.t
index 538beb2380d05747578b5196ceea75b638f6bf2a..a2d6711c2ff0af41ce60de4c21e74d7db10ccfa7 100644 (file)
@@ -1,60 +1,58 @@
 #!perl -T
 
-use Test::More tests => 10;
+use strict;
+use warnings;
 
-use Variable::Magic qw/wizard cast dispell/;
+use Test::More tests => 2 * 12 + 11 + 1;
 
-my @c = (0) x 5;
-my @x = (0) x 5;
+use Variable::Magic qw<cast dispell>;
 
-sub check {
- for (0 .. 4) { return 0 unless $c[$_] == $x[$_]; }
- return 1;
-}
+use lib 't/lib';
+use Variable::Magic::TestWatcher;
 
-my $i = -1;
-my $wiz = wizard get   => sub { ++$c[0] },
-                 set   => sub { ++$c[1] },
-                 len   => sub { ++$c[2] },
-                 clear => sub { ++$c[3] },
-                 free  => sub { ++$c[4] };
-ok(check(), 'code : create wizard');
+my $wiz = init_watcher
+        [ qw<get set len clear free copy dup local fetch store exists delete> ],
+        'code';
 
 my $x = 0;
-my $n = sub { ++$x };
-my $a = $n;
+sub hlagh { ++$x };
 
-cast $a, $wiz;
-ok(check(), 'code : cast');
+watch { cast &hlagh, $wiz } { }, 'cast';
+is $x, 0, 'code: cast didn\'t called code';
 
-my $b = $a;
-++$x[0];
-ok(check(), 'code : assign to');
+watch { hlagh() } { }, 'call without arguments';
+is $x, 1, 'code: call without arguments succeeded';
 
-$b = "X${a}Y";
-++$x[0];
-ok(check(), 'code : interpolate');
+watch { hlagh(1, 2, 3) } { }, 'call with arguments';
+is $x, 2, 'code: call with arguments succeeded';
 
-$b = \$a;
-ok(check(), 'code : reference');
+watch { undef *hlagh } { free => 1 }, 'undef symbol table entry';
+is $x, 2, 'code: undef symbol table entry didn\'t call code';
 
-$a = $n;
-++$x[1];
-ok(check(), 'code : assign');
+my $y = 0;
+watch { *hlagh = sub { ++$y } } { }, 'redefining sub';
 
-$a->();
-ok(check(), 'code : call');
+watch { cast &hlagh, $wiz } { }, 're-cast';
+is $y, 0, 'code: re-cast didn\'t called code';
 
-{
- my $b = $n;
- cast $b, $wiz;
-}
-++$x[4];
-ok(check(), 'code : scope end');
+my ($r) = watch { \&hlagh } { }, 'reference';
+is $y, 0, 'code: reference didn\'t called code';
 
-undef $a;
-++$x[1];
-ok(check(), 'code : undef');
+watch { $r->() } { }, 'call reference';
+is $y, 1, 'code: call reference succeeded';
+is $x, 2, 'code: call reference didn\'t called the previous code';
 
-dispell $a, $wiz;
-ok(check(), 'code : dispell');
+my $z = 0;
+watch {
+ no warnings 'redefine';
+ *hlagh = sub { ++$z }
+} { }, 'redefining sub 2';
+
+watch { hlagh() } { }, 'call without arguments 2';
+is $z, 1, 'code: call without arguments 2 succeeded';
+is $y, 1, 'code: call without arguments 2 didn\'t called the previous code';
+
+watch { dispell &hlagh, $wiz } { }, 'dispell';
+is $z, 1, 'code: dispell didn\'t called code';
+
+$Variable::Magic::TestWatcher::mg_end = { free => 1 };