]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blob - t/34-glob.t
Importing Variable-Magic-0.02.tar.gz
[perl/modules/Variable-Magic.git] / t / 34-glob.t
1 #!perl -T
2
3 use Test::More;
4
5 eval "use Symbol qw/gensym/";
6 if ($@) {
7  plan skip_all => "Symbol::gensym required for testing magic for globs";
8 } else {
9  plan tests => 7;
10 }
11
12 use Variable::Magic qw/wizard cast dispell/;
13
14 my @c = (0) x 5;
15 my @x = (0) x 5;
16
17 sub check {
18  for (0 .. 4) { return 0 unless $c[$_] == $x[$_]; }
19  return 1;
20 }
21
22 my $i = -1;
23 my $wiz = wizard get   => sub { ++$c[0] },
24                  set   => sub { ++$c[1] },
25                  len   => sub { ++$c[2] },
26                  clear => sub { ++$c[3] },
27                  free  => sub { ++$c[4] };
28 ok(check(), 'glob : create wizard');
29
30 local *a = gensym();
31
32 cast *a, $wiz;
33 ok(check(), 'glob : cast');
34
35 local *b = *a;
36 ok(check(), 'glob : assign to');
37
38 *a = gensym();
39 ++$x[1];
40 ok(check(), 'glob : assign');
41
42 {
43  local *b = gensym();
44  cast *b, $wiz;
45 }
46 ok(check(), 'glob : scope end');
47
48 undef *a;
49 ok(check(), 'glob : undef');
50
51 dispell *a, $wiz;
52 ok(check(), 'glob : dispell');