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