From: Vincent Pit Date: Fri, 5 Sep 2008 17:17:32 +0000 (+0200) Subject: Test how arguments are passed to the data callback X-Git-Tag: v0.20~19 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=2eff3964bde4659b291a8d944cabbaef604f40c2;p=perl%2Fmodules%2FVariable-Magic.git Test how arguments are passed to the data callback --- diff --git a/t/13-data.t b/t/13-data.t index 512290b..d1dc440 100644 --- a/t/13-data.t +++ b/t/13-data.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 32; +use Test::More tests => 38; use Variable::Magic qw/wizard getdata cast dispell SIG_MIN/; @@ -81,3 +81,20 @@ ok($res, 'cast non-data wizard returns true'); $data = eval { getdata $a, $wiz }; is($@, '', 'getdata from non-data wizard doesn\'t croak'); is($data, undef, 'getdata from non-data wizard invalid returns undef'); + +$wiz = wizard data => sub { ++$_[1] }; +my ($di, $ei) = (1, 10); +my ($d, $e); +cast $d, $wiz, $di; +cast $e, $wiz, $ei; +my $dd = getdata $d, $wiz; +my $ed = getdata $e, $wiz; +is($dd, 2, 'data from d is what we expected'); +is($di, 2, 'cast arguments from d were passed by alias'); +is($ed, 11, 'data from e is what we expected'); +is($ei, 11, 'cast arguments from e were passed by alias'); +$di *= 2; +$dd = getdata $d, $wiz; +$ed = getdata $e, $wiz; +is($dd, 2, 'data from d wasn\'t changed'); +is($ed, 11, 'data from e wasn\'t changed');