X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F20-get.t;h=3411417dfb57116f9b05a63e8cbf219efd840f13;hb=HEAD;hp=b79edc8e13bc91abd62ad77d191974e6160b4e51;hpb=14f66d40970bef63105be046a109c1a32859a8a0;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/t/20-get.t b/t/20-get.t index b79edc8..3411417 100644 --- a/t/20-get.t +++ b/t/20-get.t @@ -3,24 +3,33 @@ use strict; use warnings; -use Test::More tests => 6; +use Test::More tests => (2 * 4 + 2) + (2 * 2) + 1; -use Variable::Magic qw/wizard cast/; +use Variable::Magic qw; -my $c = 0; -my $wiz = wizard get => sub { ++$c }; -ok($c == 0, 'get : create wizard'); +use lib 't/lib'; +use Variable::Magic::TestWatcher; +use Variable::Magic::TestValue; + +my $wiz = init_watcher 'get', 'get'; my $n = int rand 1000; my $a = $n; -cast $a, $wiz; -ok($c == 0, 'get : cast'); +watch { cast $a, $wiz } { }, 'cast'; + +my $b; +# $b has to be set inside the block for the test to pass on 5.8.3 and lower +watch { $b = $a } { get => 1 }, 'assign to'; +is $b, $n, 'get: assign to correctly'; + +$b = watch { "X${a}Y" } { get => 1 }, 'interpolate'; +is $b, "X${n}Y", 'get: interpolate correctly'; + +{ + my $val = 0; -my $b = $a; -ok($c == 1, 'get : assign to'); -ok($b == $n, 'get : assign to correctly'); + init_value $val, 'get', 'get'; -$b = "X${a}Y"; -ok($c == 2, 'get : interpolate'); -ok($b eq "X${n}Y", 'get : interpolate correctly'); + value { my $x = $val } \0; +}