X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F21-set.t;h=70af0e41fc2bfcf173867d243589e112ceeb8d96;hb=ae89b589d2187cf0ed57bbb6132b9d4a8da29abb;hp=f731c0d02161111149bd216308e0dc873e06b18d;hpb=14f66d40970bef63105be046a109c1a32859a8a0;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/t/21-set.t b/t/21-set.t index f731c0d..70af0e4 100644 --- a/t/21-set.t +++ b/t/21-set.t @@ -3,27 +3,35 @@ use strict; use warnings; -use Test::More tests => 8; +use Test::More tests => (2 * 5 + 3) + (2 * 2 + 1); -use Variable::Magic qw/wizard cast/; +use Variable::Magic qw; -my $c = 0; -my $wiz = wizard set => sub { ++$c }; -ok($c == 0, 'get : create wizard'); +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; +}