X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F23-clear.t;h=3af5545755e7e3e1585a10c04c4a280be1b7197e;hb=HEAD;hp=7836d3a2e219a90b78b13d3942a126731eed9665;hpb=77a84f75f33e3ee44e61182dec76699e23025375;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/t/23-clear.t b/t/23-clear.t index 7836d3a..3af5545 100644 --- a/t/23-clear.t +++ b/t/23-clear.t @@ -1,27 +1,39 @@ #!perl -T -use Test::More tests => 7; +use strict; +use warnings; -use Variable::Magic qw/wizard cast/; +use Test::More tests => (2 * 5 + 2) + (2 * 2 + 1) + 1; -my $c = 0; -my $wiz = wizard clear => sub { ++$c }; -ok($c == 0, 'clear : create wizard'); +use Variable::Magic qw; -my @a = qw/a b c/; +use lib 't/lib'; +use Variable::Magic::TestWatcher; +use Variable::Magic::TestValue; -cast @a, $wiz; -ok($c == 0, 'clear : cast array'); +my $wiz = init_watcher 'clear', 'clear'; -@a = (); -ok($c == 1, 'clear : clear array'); -ok(!defined $a[0], 'clear : clear array correctly'); +my @a = qw; + +watch { cast @a, $wiz } { }, 'cast array'; + +watch { @a = () } { clear => 1 }, 'clear array'; +is_deeply \@a, [ ], 'clear: clear array correctly'; my %h = (foo => 1, bar => 2); -cast %h, $wiz; -ok($c == 1, 'clear : cast hash'); +watch { cast %h, $wiz } { }, 'cast hash'; + +watch { %h = () } { clear => 1 }, 'clear hash'; +is_deeply \%h, { }, 'clear: clear hash correctly'; + +{ + my @val = (4 .. 6); + + my $wv = init_value @val, 'clear', 'clear'; + + value { @val = () } [ 4 .. 6 ]; -%h = (); -ok($c == 2, 'clear : clear hash'); -ok(!(keys %h), 'clear : clear hash correctly'); + dispell @val, $wv; + is_deeply \@val, [ ], 'clear: value after'; +}