]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blob - t/30-scalar.t
Importing Variable-Magic-0.08.tar.gz
[perl/modules/Variable-Magic.git] / t / 30-scalar.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 13;
7
8 use Variable::Magic qw/wizard cast dispell/;
9
10 my @c = (0) x 12;
11 my @x = (0) x 12;
12
13 sub check {
14  for (0 .. 11) { return 0 unless $c[$_] == $x[$_]; }
15  return 1;
16 }
17
18 my $i = -1;
19 my $wiz = wizard get   => sub { ++$c[0] },
20                  set   => sub { ++$c[1] },
21                  len   => sub { ++$c[2] },
22                  clear => sub { ++$c[3] },
23                  free  => sub { ++$c[4] },
24                  copy  => sub { ++$c[5] },
25                  dup   => sub { ++$c[6] },
26                  local => sub { ++$c[7] },
27                  fetch => sub { ++$c[8] },
28                  store => sub { ++$c[9] },
29                  'exists' => sub { ++$c[10] },
30                  'delete' => sub { ++$c[11] };
31 ok(check(), 'scalar : create wizard');
32
33 my $n = int rand 1000;
34 my $a = $n;
35
36 cast $a, $wiz;
37 ok(check(), 'scalar : cast');
38
39 my $b = $a;
40 ++$x[0];
41 ok(check(), 'scalar : assign to');
42
43 $b = "X${a}Y";
44 ++$x[0];
45 ok(check(), 'scalar : interpolate');
46
47 $b = \$a;
48 ok(check(), 'scalar : reference');
49
50 $a = 123;
51 ++$x[1];
52 ok(check(), 'scalar : assign');
53
54 ++$a;
55 ++$x[0]; ++$x[1];
56 ok(check(), 'scalar : increment');
57
58 --$a;
59 ++$x[0]; ++$x[1];
60 ok(check(), 'scalar : decrement');
61
62 $a *= 1.5;
63 ++$x[0]; ++$x[1];
64 ok(check(), 'scalar : multiply');
65
66 $a /= 1.5;
67 ++$x[0]; ++$x[1];
68 ok(check(), 'scalar : divide');
69
70 {
71  my $b = $n;
72  cast $b, $wiz;
73 }
74 ++$x[4];
75 ok(check(), 'scalar : scope end');
76
77 undef $a;
78 ++$x[1];
79 ok(check(), 'scalar : undef');
80
81 dispell $a, $wiz;
82 ok(check(), 'scalar : dispell');