X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F21-set.t;h=70af0e41fc2bfcf173867d243589e112ceeb8d96;hb=2a7199760cc1080be8e62e425d74a85f4eebcdfc;hp=591514235b6f2ae916f08c3297fa1f6af4b84992;hpb=77a84f75f33e3ee44e61182dec76699e23025375;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/t/21-set.t b/t/21-set.t index 5915142..70af0e4 100644 --- a/t/21-set.t +++ b/t/21-set.t @@ -1,26 +1,37 @@ #!perl -T -use Test::More tests => 8; +use strict; +use warnings; -use Variable::Magic qw/wizard cast/; +use Test::More tests => (2 * 5 + 3) + (2 * 2 + 1); -my $c = 0; -my $wiz = wizard set => sub { ++$c }; -ok($c == 0, 'get : create wizard'); +use Variable::Magic qw; + +use lib 't/lib'; +use Variable::Magic::TestWatcher; +use Variable::Magic::TestValue; + +my $wiz = init_watcher 'set', 'set'; my $a = 0; -cast $a, $wiz; -ok($c == 0, 'get : cast'); + +watch { cast $a, $wiz } { }, 'cast'; my $n = int rand 1000; -$a = $n; -ok($c == 1, 'set : assign'); -ok($a == $n, 'set : assign correctly'); -++$a; -ok($c == 2, 'set : increment'); -ok($a == $n + 1, 'set : increment correctly'); +watch { $a = $n } { set => 1 }, 'assign'; +is $a, $n, 'set: assign correctly'; + +watch { ++$a } { set => 1 }, 'increment'; +is $a, $n + 1, 'set: increment correctly'; + +watch { --$a } { set => 1 }, 'decrement'; +is $a, $n, 'set: decrement correctly'; + +{ + my $val = 0; + + init_value $val, 'set', 'set'; ---$a; -ok($c == 3, 'set : decrement'); -ok($a == $n, 'set : decrement correctly'); + value { $val = 1 } \1; +}