]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blob - t/16-huf.t
0f9215c689a217f38af86d135a516ae8ed3bc179
[perl/modules/Variable-Magic.git] / t / 16-huf.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 use Variable::Magic qw<wizard cast dispell VMG_UVAR>;
9
10 use lib 't/lib';
11 use VPIT::TestHelpers;
12
13 if (VMG_UVAR) {
14  load_or_skip('Hash::Util::FieldHash', undef, [ ],
15               'required for testing uvar interaction');
16  plan tests => 2 * 5 + 7 + 1;
17 } else {
18  skip_all 'No nice uvar magic for this perl';
19 }
20
21 use Variable::Magic::TestWatcher;
22
23 my $wiz = init_watcher [ qw<fetch store> ], 'huf';
24 ok defined($wiz),       'huf: wizard with uvar is defined';
25 is ref($wiz), 'SCALAR', 'huf: wizard with uvar is a scalar ref';
26
27 Hash::Util::FieldHash::fieldhash(\my %h);
28
29 my $obj = { };
30 bless $obj, 'Variable::Magic::Test::Mock';
31 $h{$obj} = 5;
32
33 my ($res) = watch { cast %h, $wiz } { }, 'cast uvar magic on fieldhash';
34 ok $res, 'huf: cast uvar magic on fieldhash succeeded';
35
36 my ($s) = watch { $h{$obj} } { fetch => 1 }, 'fetch on magical fieldhash';
37 is $s, 5, 'huf: fetch on magical fieldhash succeeded';
38
39 watch { $h{$obj} = 7 } { store => 1 }, 'store on magical fieldhash';
40 is $h{$obj}, 7, 'huf: store on magical fieldhash succeeded';
41
42 ($res) = watch { dispell %h, $wiz } { }, 'dispell uvar magic on fieldhash';
43 ok $res, 'huf: dispell uvar magic on fieldhash succeeded';
44
45 $h{$obj} = 11;
46 $s = $h{$obj};
47 is $s, 11, 'huf: store/fetch on fieldhash after dispell still ok';
48
49 $Variable::Magic::TestWatcher::mg_end = { fetch => 1 };