6 use Test::More tests => 24;
8 use Variable::Magic qw/wizard getsig cast dispell SIG_MIN/;
12 my ($a, $b, $c, $d) = 1 .. 4;
15 my $wiz = eval { wizard sig => $sig };
16 ok(!$@, "wizard creation doesn't croak ($@)");
17 ok(defined $wiz, 'wizard is defined');
18 is(ref $wiz, 'SCALAR', 'wizard is a scalar ref');
19 is($sig, getsig $wiz, 'wizard signature is correct');
21 my $wiz2 = eval { wizard sig => $sig };
22 ok(!$@, "wizard retreive doesn't croak ($@)");
23 ok(defined $wiz2, 'retrieved wizard is defined');
24 is(ref $wiz2, 'SCALAR', 'retrieved wizard is a scalar ref');
25 is($sig, getsig $wiz2, 'retrieved wizard signature is correct');
28 my $res = eval { cast $a, $wiz };
29 ok(!$@, "cast from wizard croaks ($@)");
30 ok($res, 'cast from wizard invalid');
32 $res = eval { dispell $a, $wiz2 };
33 ok(!$@, "dispell from retrieved wizard croaks ($@)");
34 ok($res, 'dispell from retrieved wizard invalid');
36 $res = eval { cast $b, $sig };
37 ok(!$@, "cast from integer croaks ($@)");
38 ok($res, 'cast from integer invalid');
41 my $res = eval { cast $c, $sig + 0.1 };
42 ok(!$@, "cast from float croaks ($@)");
43 ok($res, 'cast from float invalid');
45 $res = eval { cast $d, sprintf "%u", $sig };
46 ok(!$@, "cast from string croaks ($@)");
47 ok($res, 'cast from string invalid');
49 $res = eval { dispell $b, $sig };
50 ok(!$@, "dispell from integer croaks ($@)");
51 ok($res, 'dispell from integer invalid');
53 $res = eval { dispell $c, $sig + 0.1 };
54 ok(!$@, "dispell from float croaks ($@)");
55 ok($res, 'dispell from float invalid');
57 $res = eval { dispell $d, sprintf "%u", $sig };
58 ok(!$@, "dispell from string croaks ($@)");
59 ok($res, 'dispell from string invalid');