X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F21-set.t;h=70af0e41fc2bfcf173867d243589e112ceeb8d96;hb=9ad970e109ea4caa9767db1bda9d475444920c7a;hp=095b482c6499d8b4e28fcf0c24fb20f821e36ade;hpb=a86e3e47a167afadf7de1231d6401a1139330ad0;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/t/21-set.t b/t/21-set.t index 095b482..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 }; -is($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; -is($c, 0, 'get : cast'); + +watch { cast $a, $wiz } { }, 'cast'; my $n = int rand 1000; -$a = $n; -is($c, 1, 'set : assign'); -is($a, $n, 'set : assign correctly'); -++$a; -is($c, 2, 'set : increment'); -is($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; -is($c, 3, 'set : decrement'); -is($a, $n, 'set : decrement correctly'); + value { $val = 1 } \1; +}