X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F33-code.t;h=4b9cd207ee1c801feb41e28b766057fdc2f1964d;hb=47fcdae90d7af36c40b950c1154fa2dd306b5edb;hp=21d900ff20bc1ae4e9fdfd7ecbeade20bc847ed6;hpb=14f66d40970bef63105be046a109c1a32859a8a0;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/t/33-code.t b/t/33-code.t index 21d900f..4b9cd20 100644 --- a/t/33-code.t +++ b/t/33-code.t @@ -3,16 +3,17 @@ use strict; use warnings; -use Test::More tests => 10; +use Test::More tests => 14; use Variable::Magic qw/wizard cast dispell/; -my @c = (0) x 5; -my @x = (0) x 5; +my @c = (0) x 12; +my @x = (0) x 12; sub check { - for (0 .. 4) { return 0 unless $c[$_] == $x[$_]; } - return 1; + is join(':', map { (defined) ? $_ : 'u' } @c[0 .. 11]), + join(':', map { (defined) ? $_ : 'u' } @x[0 .. 11]), + $_[0]; } my $i = -1; @@ -20,44 +21,48 @@ 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'); + free => sub { ++$c[4] }, + copy => sub { ++$c[5] }, + dup => sub { ++$c[6] }, + local => sub { ++$c[7] }, + fetch => sub { ++$c[8] }, + store => sub { ++$c[9] }, + 'exists' => sub { ++$c[10] }, + 'delete' => sub { ++$c[11] }; +check('code : create wizard'); my $x = 0; -my $n = sub { ++$x }; -my $a = $n; +sub hlagh { ++$x }; -cast $a, $wiz; -ok(check(), 'code : cast'); +cast &hlagh, $wiz; +check('code : cast'); -my $b = $a; -++$x[0]; -ok(check(), 'code : assign to'); +hlagh(); +check('code : call without arguments'); +is($x, 1, 'code : call without arguments succeeded'); -$b = "X${a}Y"; -++$x[0]; -ok(check(), 'code : interpolate'); +hlagh(1, 2, 3); +check('code : call with arguments'); +is($x, 2, 'code : call with arguments succeeded'); -$b = \$a; -ok(check(), 'code : reference'); +undef *hlagh; +++$x[4]; +check('code : undef symbol table'); +is($x, 2, 'code : undef symbol table didn\'t call'); -$a = $n; -++$x[1]; -ok(check(), 'code : assign'); +my $y = 0; +*hlagh = sub { ++$y }; -$a->(); -ok(check(), 'code : call'); +cast &hlagh, $wiz; +check('code : re-cast'); -{ - my $b = $n; - cast $b, $wiz; -} -++$x[4]; -ok(check(), 'code : scope end'); +my $r = \&hlagh; +check('code : take reference'); -undef $a; -++$x[1]; -ok(check(), 'code : undef'); +$r->(); +check('code : call reference'); +is($y, 1, 'code : call reference succeeded'); +is($x, 2, 'code : call reference didn\'t triggered the previous code'); -dispell $a, $wiz; -ok(check(), 'code : dispell'); +dispell &hlagh, $wiz; +check('code : dispell');