]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blob - t/10-simple.t
37d348e9f0b56a0c0b5b6cec9bab4bee3302e530
[perl/modules/Variable-Magic.git] / t / 10-simple.t
1 #!perl -T
2
3 use Test::More tests => 14;
4
5 use Variable::Magic qw/wizard gensig getsig cast dispell/;
6
7 my $sig = gensig;
8
9 my $wiz = eval { wizard sig => $sig };
10 ok(!$@, "wizard creation error ($@)");
11 ok(defined $wiz, 'wizard is defined');
12 ok(ref $wiz eq 'SCALAR', 'wizard is a scalar ref');
13 ok($sig == getsig $wiz, 'wizard signature is correct');
14
15 my $a = 1;
16 my $res = eval { cast $a, $wiz };
17 ok(!$@, "cast croaks ($@)");
18 ok($res, 'cast invalid');
19
20 $res = eval { dispell $a, $wiz };
21 ok(!$@, "dispell from wizard croaks ($@)");
22 ok($res, 'dispell from wizard invalid');
23
24 $res = eval { cast $a, $wiz };
25 ok(!$@, "re-cast croaks ($@)");
26 ok($res, 're-cast invalid');
27
28 $res = eval { dispell $a, $wiz };
29 ok(!$@, "re-dispell croaks ($@)");
30 ok($res, 're-dispell invalid');
31
32 $sig = gensig;
33 {
34  my $wiz = wizard sig => $sig;
35  my $b = 2;
36  my $res = cast $b, $wiz;
37 }
38 my $c = 3;
39 $res = eval { cast $c, $sig };
40 ok(!$@, "cast from obsolete signature croaks ($@)");
41 ok(!defined($res), 'cast from obsolete signature returns undef');