6 use Test::More tests => 30;
8 use Variable::Magic qw/wizard getsig cast dispell SIG_MIN SIG_MAX/;
12 my ($a, $b, $c, $d) = 1 .. 4;
15 my $wiz = eval { wizard sig => $sig };
16 is($@, '', '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 is($@, '', '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');
27 my $wiz3 = eval { wizard sig => [ ] };
28 like($@, qr/Invalid\s+numeric\s+signature\s+at\s+\Q$0\E/, 'non numeric signature croaks');
29 is($wiz3, undef, 'non numeric signature doesn\'t return anything');
31 $wiz3 = eval { wizard sig => SIG_MIN - 1 };
32 like($@, qr/Invalid\s+numeric\s+signature\s+at\s+\Q$0\E/, 'numeric signature too small croaks');
33 is($wiz3, undef, 'numeric signature too small doesn\'t return anything');
35 $wiz3 = eval { wizard sig => SIG_MAX + 1 };
36 like($@, qr/Invalid\s+numeric\s+signature\s+at\s+\Q$0\E/, 'numeric signature too big croaks');
37 is($wiz3, undef, 'numeric signature too big doesn\'t return anything');
40 my $res = eval { cast $a, $wiz };
41 is($@, '', 'cast from wizard doesn\'t croak');
42 ok($res, 'cast from wizard invalid');
44 $res = eval { dispell $a, $wiz2 };
45 is($@, '', 'dispell from retrieved wizard doesn\'t croak');
46 ok($res, 'dispell from retrieved wizard invalid');
48 $res = eval { cast $b, $sig };
49 is($@, '', 'cast from integer doesn\'t croak');
50 ok($res, 'cast from integer invalid');
53 my $res = eval { cast $c, $sig + 0.1 };
54 is($@, '', 'cast from float doesn\'t croak');
55 ok($res, 'cast from float invalid');
57 $res = eval { cast $d, sprintf "%u", $sig };
58 is($@, '', 'cast from string doesn\'t croak');
59 ok($res, 'cast from string invalid');
61 $res = eval { dispell $b, $sig };
62 is($@, '', 'dispell from integer doesn\'t croak');
63 ok($res, 'dispell from integer invalid');
65 $res = eval { dispell $c, $sig + 0.1 };
66 is($@, '', 'dispell from float doesn\'t croak');
67 ok($res, 'dispell from float invalid');
69 $res = eval { dispell $d, sprintf "%u", $sig };
70 is($@, '', 'dispell from string doesn\'t croak');
71 ok($res, 'dispell from string invalid');