]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - t/21-set.t
This is 0.64
[perl/modules/Variable-Magic.git] / t / 21-set.t
index f731c0d02161111149bd216308e0dc873e06b18d..70af0e41fc2bfcf173867d243589e112ceeb8d96 100644 (file)
@@ -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<cast>;
 
-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;
+}