6 use Test::More tests => 43;
8 use Variable::Magic qw/wizard 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');
28 my $wiz = eval { wizard };
29 is($@, '', 'wizard doesn\'t croak');
30 ok(defined $wiz, 'wizard is defined');
31 is(ref $wiz, 'SCALAR', 'wizard is a scalar ref');
33 my $res = eval { cast $a, $wiz };
34 is($@, '', 'cast doesn\'t croak');
35 ok($res, 'cast is valid');
37 $res = eval { dispell $a, $wiz };
38 is($@, '', 'dispell from wizard doesn\'t croak');
39 ok($res, 'dispell from wizard is valid');
41 $res = eval { cast $a, $wiz };
42 is($@, '', 're-cast doesn\'t croak');
43 ok($res, 're-cast is valid');
45 $res = eval { dispell $a, \"blargh" };
46 like($@, $inv_wiz_obj, 're-dispell from wrong wizard croaks');
47 is($res, undef, 're-dispell from wrong wizard doesn\'t return anything');
49 $res = eval { dispell $a, undef };
50 like($@, $inv_wiz_obj, 're-dispell from undef croaks');
51 is($res, undef, 're-dispell from undef doesn\'t return anything');
53 $res = eval { dispell $a, $wiz };
54 is($@, '', 're-dispell from good wizard doesn\'t croak');
55 ok($res, 're-dispell from good wizard is valid');
57 $res = eval { dispell my $b, $wiz };
58 is($@, '', 'dispell non-magic object doesn\'t croak');
59 is($res, 0, 'dispell non-magic object returns 0');
62 $res = eval { cast $c, undef };
63 like($@, $inv_wiz_obj, 'cast from undef croaks');
64 is($res, undef, 'cast from undef doesn\'t return anything');