X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F12-data.t;h=1e8b9eb0f340b5ca53f3037530f22fc91f255268;hb=d8122850f4c201c5b849cebb1f9b7f2630ae4c15;hp=b80fc8908cb4ef54a0d32ece9e08eed3f964d0c4;hpb=77a84f75f33e3ee44e61182dec76699e23025375;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/t/12-data.t b/t/12-data.t index b80fc89..1e8b9eb 100644 --- a/t/12-data.t +++ b/t/12-data.t @@ -1,13 +1,16 @@ #!perl -T -use Test::More tests => 14; +use strict; +use warnings; + +use Test::More tests => 19; use Variable::Magic qw/wizard getdata cast dispell/; my $c = 1; my $wiz = eval { - wizard data => sub { return { foo => 12, bar => 27 } }, + wizard data => sub { return { foo => $_[1] || 12, bar => $_[3] || 27 } }, get => sub { $c += $_[1]->{foo}; $_[1]->{foo} = $c }, set => sub { $c += $_[1]->{bar}; $_[1]->{bar} = $c } }; @@ -17,15 +20,15 @@ ok(ref $wiz eq 'SCALAR', 'wizard is a scalar ref'); my $a = 75; my $res = eval { cast $a, $wiz }; -ok(!$@, "cast error 1 ($@)"); -ok($res, 'cast error 2'); +ok(!$@, "cast croaks ($@)"); +ok($res, 'cast invalid'); my $data = eval { getdata $a, $wiz }; -ok(!$@, "getdata error 1 ($@)"); -ok($res, 'getdata error 2'); +ok(!$@, "getdata croaks ($@)"); +ok($res, 'getdata invalid'); ok($data && ref($data) eq 'HASH' - && exists $data->{foo} && $data->{foo} eq 12 - && exists $data->{bar} && $data->{bar} eq 27, + && exists $data->{foo} && $data->{foo} == 12 + && exists $data->{bar} && $data->{bar} == 27, 'private data creation ok'); my $b = $a; @@ -37,5 +40,17 @@ ok($c == 40, 'set magic : pass data'); ok($data->{bar} == 40, 'set magic : pass data'); $res = eval { dispell $a, $wiz }; -ok(!$@, "dispell error 1 ($@)"); -ok($res, 'dispell error 2'); +ok(!$@, "dispell croaks ($@)"); +ok($res, 'dispell invalid'); + +$res = eval { cast $a, $wiz, qw/z j t/ }; +ok(!$@, "cast with arguments croaks ($@)"); +ok($res, 'cast with arguments invalid'); + +$data = eval { getdata $a, $wiz }; +ok(!$@, "getdata croaks ($@)"); +ok($res, 'getdata invalid'); +ok($data && ref($data) eq 'HASH' + && exists $data->{foo} && $data->{foo} eq 'z' + && exists $data->{bar} && $data->{bar} eq 't', + 'private data creation with arguments ok');