use strict;
use warnings;
-use Test::More tests => 10;
+use Test::More tests => 2 * 10 + 9 + 1;
-use Variable::Magic qw/wizard cast dispell/;
+use Variable::Magic qw/cast dispell/;
-my @c = (0) x 5;
-my @x = (0) x 5;
+use lib 't/lib';
+use Variable::Magic::TestWatcher;
-sub check {
- for (0 .. 4) { return 0 unless $c[$_] == $x[$_]; }
- return 1;
-}
-
-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
+ [ 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');
+check { cast &hlagh, $wiz } { }, 'cast';
+is $x, 0, 'code: cast didn\'t called code';
-my $b = $a;
-++$x[0];
-ok(check(), 'code : assign to');
+check { hlagh() } { }, 'call without arguments';
+is $x, 1, 'code: call without arguments succeeded';
-$b = "X${a}Y";
-++$x[0];
-ok(check(), 'code : interpolate');
+check { hlagh(1, 2, 3) } { }, 'call with arguments';
+is $x, 2, 'code: call with arguments succeeded';
-$b = \$a;
-ok(check(), 'code : reference');
+check { 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;
+check { *hlagh = sub { ++$y } } { }, 'redefining sub';
-$a->();
-ok(check(), 'code : call');
+check { 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) = check { \&hlagh } { }, 'reference';
+is $y, 0, 'code: reference didn\'t called code';
-undef $a;
-++$x[1];
-ok(check(), 'code : undef');
+check { $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');
+check { dispell &hlagh, $wiz } { }, 'dispell';
+is $y, 1, 'code: dispell didn\'t called code';