Debian Codegraph @

t/23-clear.t

raw
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => (2 * 5 + 2) + (2 * 2 + 1) + 1;
7
8 use Variable::Magic qw<cast dispell>;
9
10 use lib 't/lib';
11 use Variable::Magic::TestWatcher;
12 use Variable::Magic::TestValue;
13
14 my $wiz = init_watcher 'clear', 'clear';
15
16 my @a = qw<a b c>;
17
18 watch { cast @a, $wiz } { }, 'cast array';
19
20 watch { @a = () } { clear => 1 }, 'clear array';
21 is_deeply \@a, [ ], 'clear: clear array correctly';
22
23 my %h = (foo => 1, bar => 2);
24
25 watch { cast %h, $wiz } { }, 'cast hash';
26
27 watch { %h = () } { clear => 1 }, 'clear hash';
28 is_deeply \%h, { }, 'clear: clear hash correctly';
29
30 {
31 my @val = (4 .. 6);
32
33 my $wv = init_value @val, 'clear', 'clear';
34
35 value { @val = () } [ 4 .. 6 ];
36
37 dispell @val, $wv;
38 is_deeply \@val, [ ], 'clear: value after';
39 }