6 use Test::More tests => 48;
8 use Variable::Magic qw/wizard gensig getsig cast dispell MGf_COPY MGf_DUP MGf_LOCAL VMG_UVAR/;
10 my $inv_wiz_obj = qr/Invalid\s+wizard\s+object\s+at\s+\Q$0\E/;
16 $args += 5 if VMG_UVAR;
19 eval { Variable::Magic::_wizard(('hlagh') x $_) };
20 like($@, qr/Wrong\s+number\s+of\s+arguments\s+at\s+\Q$0\E/, '_wizard called directly with a wrong number of arguments croaks');
24 eval { wizard(('dong') x (2 * $_ + 1)) };
25 like($@, qr/Wrong\s+number\s+of\s+arguments\s+for\s+&?wizard\(\)\s+at\s+\Q$0\E/, 'wizard called with an odd number of arguments croaks');
31 my $res = eval { cast $a, $sig };
32 like($@, $inv_wiz_obj, 'cast from wrong sig croaks');
33 is($res, undef, 'cast from wrong sig doesn\'t return anything');
35 my $wiz = eval { wizard sig => $sig };
36 is($@, '', 'wizard doesn\'t croak');
37 ok(defined $wiz, 'wizard is defined');
38 is(ref $wiz, 'SCALAR', 'wizard is a scalar ref');
39 is($sig, getsig $wiz, 'wizard signature is correct');
41 $res = eval { cast $a, $wiz };
42 is($@, '', 'cast doesn\'t croak');
43 ok($res, 'cast is valid');
45 $res = eval { dispell $a, $wiz };
46 is($@, '', 'dispell from wizard doesn\'t croak');
47 ok($res, 'dispell from wizard is valid');
49 $res = eval { cast $a, $wiz };
50 is($@, '', 're-cast doesn\'t croak');
51 ok($res, 're-cast is valid');
53 $res = eval { dispell $a, gensig };
54 like($@, $inv_wiz_obj, 're-dispell from wrong sig croaks');
55 is($res, undef, 're-dispell from wrong sig doesn\'t return anything');
57 $res = eval { dispell $a, undef };
58 like($@, $inv_wiz_obj, 're-dispell from undef croaks');
59 is($res, undef, 're-dispell from undef doesn\'t return anything');
61 $res = eval { dispell $a, $sig };
62 is($@, '', 're-dispell from good sig doesn\'t croak');
63 ok($res, 're-dispell from good sig is valid');
65 $res = eval { dispell my $b, $wiz };
66 is($@, '', 'dispell non-magic object doesn\'t croak');
67 is($res, 0, 'dispell non-magic object returns 0');
71 my $wiz = wizard sig => $sig;
73 my $res = cast $b, $wiz;
76 $res = eval { cast $c, $sig };
77 like($@, $inv_wiz_obj, 'cast from obsolete signature croaks');
78 is($res, undef, 'cast from obsolete signature returns undef');
80 $res = eval { cast $c, undef };
81 like($@, $inv_wiz_obj, 'cast from undef croaks');
82 is($res, undef, 'cast from undef doesn\'t return anything');