]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blob - t/10-simple.t
Importing Variable-Magic-0.05.tar.gz
[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 => 16;
7
8 use Variable::Magic qw/wizard gensig getsig cast dispell/;
9
10 my $sig = gensig;
11
12 my $wiz = eval { wizard sig => $sig };
13 ok(!$@, "wizard creation error ($@)");
14 ok(defined $wiz, 'wizard is defined');
15 ok(ref $wiz eq 'SCALAR', 'wizard is a scalar ref');
16 ok($sig == getsig $wiz, 'wizard signature is correct');
17
18 my $a = 1;
19 my $res = eval { cast $a, $wiz };
20 ok(!$@, "cast croaks ($@)");
21 ok($res, 'cast invalid');
22
23 $res = eval { dispell $a, $wiz };
24 ok(!$@, "dispell from wizard croaks ($@)");
25 ok($res, 'dispell from wizard invalid');
26
27 $res = eval { cast $a, $wiz };
28 ok(!$@, "re-cast croaks ($@)");
29 ok($res, 're-cast invalid');
30
31 $res = eval { dispell $a, $wiz };
32 ok(!$@, "re-dispell croaks ($@)");
33 ok($res, 're-dispell invalid');
34
35 $res = eval { dispell my $b, $wiz };
36 ok(!$@, "dispell non-magic object fails ($@)");
37 ok($res == 0, 'dispell non-magic object doesn\'t return 0');
38
39 $sig = gensig;
40 {
41  my $wiz = wizard sig => $sig;
42  my $b = 2;
43  my $res = cast $b, $wiz;
44 }
45 my $c = 3;
46 $res = eval { cast $c, $sig };
47 ok(!$@, "cast from obsolete signature croaks ($@)");
48 ok(!defined($res), 'cast from obsolete signature returns undef');