]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blob - t/34-glob.t
Add more glob tests
[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 => 2 * 12 + 1;
13  diag "Using Symbol $Symbol::VERSION" if defined $Symbol::VERSION;
14 }
15
16 use Variable::Magic qw/cast dispell VMG_COMPAT_GLOB_GET/;
17
18 my %get = VMG_COMPAT_GLOB_GET ? (get => 1) : ();
19
20 use lib 't/lib';
21 use Variable::Magic::TestWatcher;
22
23 my $wiz = init_watcher
24         [ qw/get set len clear free copy dup local fetch store exists delete/ ],
25         'glob';
26
27 local *a = gensym();
28
29 watch { cast *a, $wiz } +{ }, 'cast';
30
31 watch { local *b = *a } +{ %get }, 'assign to';
32
33 watch { *a = \1 }          +{ %get, set => 1 }, 'assign scalar slot';
34 watch { *a = [ qw/x y/ ] } +{ %get, set => 1 }, 'assign array slot';
35 watch { *a = { u => 1 } }  +{ %get, set => 1 }, 'assign hash slot';
36 watch { *a = sub { } }     +{ %get, set => 1 }, 'assign code slot';
37
38 watch { *a = gensym() }    +{ %get, set => 1 }, 'assign glob';
39
40 watch {
41  local *b = gensym();
42  watch { cast *b, $wiz } +{ }, 'cast 2';
43 } +{ }, 'scope end';
44
45 watch { undef *a } +{ %get }, 'undef';
46
47 watch { dispell *a, $wiz } +{ %get }, 'dispell';