]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blob - t/34-glob.t
Importing Variable-Magic-0.04.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 5;
18 my @x = (0) x 5;
19
20 sub check {
21  for (0 .. 4) { 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 ok(check(), 'glob : create wizard');
32
33 local *a = gensym();
34
35 cast *a, $wiz;
36 ok(check(), 'glob : cast');
37
38 local *b = *a;
39 ok(check(), 'glob : assign to');
40
41 *a = gensym();
42 ++$x[1];
43 ok(check(), 'glob : assign');
44
45 {
46  local *b = gensym();
47  cast *b, $wiz;
48 }
49 ok(check(), 'glob : scope end');
50
51 undef *a;
52 ok(check(), 'glob : undef');
53
54 dispell *a, $wiz;
55 ok(check(), 'glob : dispell');