6 use Test::More tests => 46;
8 use Variable::Magic qw/wizard gensig getsig cast dispell MGf_COPY MGf_DUP MGf_LOCAL VMG_UVAR/;
14 $args += 4 if VMG_UVAR;
17 eval { Variable::Magic::_wizard(('hlagh') x $_) };
18 ok($@, "_wizard called directly with a wrong number of arguments croaks ($@)");
22 eval { wizard(('dong') x (2 * $_ + 1)) };
23 ok($@, "wizard called with an odd number of arguments croaks ($@)");
28 my $wiz = eval { wizard sig => $sig };
29 ok(!$@, "wizard doesn't croak ($@)");
30 ok(defined $wiz, 'wizard is defined');
31 is(ref $wiz, 'SCALAR', 'wizard is a scalar ref');
32 is($sig, getsig $wiz, 'wizard signature is correct');
35 my $res = eval { cast $a, $wiz };
36 ok(!$@, "cast doesn't croak ($@)");
37 ok($res, 'cast is valid');
39 $res = eval { dispell $a, $wiz };
40 ok(!$@, "dispell from wizard doesn't croak ($@)");
41 ok($res, 'dispell from wizard is valid');
43 $res = eval { cast $a, $wiz };
44 ok(!$@, "re-cast doesn't croak ($@)");
45 ok($res, 're-cast is valid');
47 $res = eval { dispell $a, gensig };
48 ok(!$@, "re-dispell from wrong sig doesn't croak ($@)");
49 ok(!defined($res), 're-dispell from wrong sig returns undef');
51 $res = eval { dispell $a, undef };
52 ok($@, "re-dispell from undef croaks ($@)");
53 ok(!defined($res), 're-dispell from undef returns undef');
55 $res = eval { dispell $a, $sig };
56 ok(!$@, "re-dispell from good sig doesn't croak ($@)");
57 ok($res, 're-dispell from good sig is valid');
59 $res = eval { dispell my $b, $wiz };
60 ok(!$@, "dispell non-magic object doesn't croak ($@)");
61 is($res, 0, 'dispell non-magic object returns 0');
65 my $wiz = wizard sig => $sig;
67 my $res = cast $b, $wiz;
70 $res = eval { cast $c, $sig };
71 ok(!$@, "cast from obsolete signature doesn't croak ($@)");
72 ok(!defined($res), 'cast from obsolete signature returns undef');
74 $res = eval { cast $c, undef };
75 ok($@, "cast from undef croaks ($@)");
76 ok(!defined($res), 'cast from undef returns undef');