]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blob - t/10-simple.t
This is 0.64
[perl/modules/Variable-Magic.git] / t / 10-simple.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 43;
7
8 use Variable::Magic qw<wizard cast dispell MGf_LOCAL VMG_UVAR>;
9
10 my $inv_wiz_obj = qr/Invalid\s+wizard\s+object\s+at\s+\Q$0\E/;
11
12 my $args = 9;
13 ++$args if MGf_LOCAL;
14 $args += 5 if VMG_UVAR;
15 for (0 .. 20) {
16  next if $_ == $args;
17  eval { Variable::Magic::_wizard(('hlagh') x $_) };
18  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');
19 }
20
21 for (0 .. 3) {
22  eval { wizard(('dong') x (2 * $_ + 1)) };
23  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');
24 }
25
26 my $wiz = eval { wizard };
27 is($@, '',             'wizard doesn\'t croak');
28 ok(defined $wiz,       'wizard is defined');
29 is(ref $wiz, 'SCALAR', 'wizard is a scalar ref');
30
31 my $res = eval { cast $a, $wiz };
32 is($@, '', 'cast doesn\'t croak');
33 ok($res,   'cast is valid');
34
35 $res = eval { dispell $a, $wiz };
36 is($@, '', 'dispell from wizard doesn\'t croak');
37 ok($res,   'dispell from wizard is valid');
38
39 $res = eval { cast $a, $wiz };
40 is($@, '', 're-cast doesn\'t croak');
41 ok($res,   're-cast is valid');
42
43 $res = eval { dispell $a, \"blargh" };
44 like($@, $inv_wiz_obj, 're-dispell from wrong wizard croaks');
45 is($res, undef,        're-dispell from wrong wizard doesn\'t return anything');
46
47 $res = eval { dispell $a, undef };
48 like($@, $inv_wiz_obj, 're-dispell from undef croaks');
49 is($res, undef,        're-dispell from undef doesn\'t return anything');
50
51 $res = eval { dispell $a, $wiz };
52 is($@, '', 're-dispell from good wizard doesn\'t croak');
53 ok($res,   're-dispell from good wizard is valid');
54
55 $res = eval { dispell my $b, $wiz };
56 is($@, '',  'dispell non-magic object doesn\'t croak');
57 is($res, 0, 'dispell non-magic object returns 0');
58
59 my $c = 3;
60 $res = eval { cast $c, undef };
61 like($@, $inv_wiz_obj, 'cast from undef croaks');
62 is($res, undef,        'cast from undef doesn\'t return anything');