X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F25-copy.t;h=04ed1c95fbd65d64a904c26a6498fc8c3ef7d7d0;hb=4591803a480417f70ed1f166ea4433facfddefd4;hp=5ebcbe03406b17a61f63ecba11f7dc00738e3077;hpb=da422089a9a5dfbf84e72ec3ba867063471ff41c;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/t/25-copy.t b/t/25-copy.t index 5ebcbe0..04ed1c9 100644 --- a/t/25-copy.t +++ b/t/25-copy.t @@ -5,23 +5,21 @@ use warnings; use Test::More; -use Variable::Magic qw/cast MGf_COPY/; +use Variable::Magic qw; -if (MGf_COPY) { - plan tests => 2 + (2 * 5 + 3) + (2 * 9 + 6) + 1; -} else { - plan skip_all => 'No copy magic for this perl'; -} +plan tests => 2 + ((2 * 5 + 3) + (2 * 2 + 1)) + (2 * 9 + 6) + 1; use lib 't/lib'; use Variable::Magic::TestWatcher; +use Variable::Magic::TestValue; my $wiz = init_watcher 'copy', 'copy'; SKIP: { - eval "use Tie::Array"; - skip 'Tie::Array required to test copy magic on arrays', 2 * 5 + 3 if $@; - diag "Using Tie::Array $Tie::Array::VERSION" if defined $Tie::Array::VERSION; + my $has_tie_array = do { local $@; eval { require Tie::Array; 1 } }; + skip 'Tie::Array required to test copy magic on arrays' + => (2 * 5 + 3) + (2 * 2 + 1) unless $has_tie_array; + defined and diag "Using Tie::Array $_" for $Tie::Array::VERSION; tie my @a, 'Tie::StdArray'; @a = (1 .. 10); @@ -38,12 +36,25 @@ SKIP: { ok $s, 'copy: tied array exists correctly'; watch { undef @a } { }, 'tied array undef'; + + { + tie my @val, 'Tie::StdArray'; + @val = (4 .. 6); + + my $wv = init_value @val, 'copy', 'copy'; + + value { $val[3] = 8 } [ 4 .. 6 ]; + + dispell @val, $wv; + is_deeply \@val, [ 4 .. 6, 8 ], 'copy: value after'; + } } SKIP: { - eval "use Tie::Hash"; - skip 'Tie::Hash required to test copy magic on hashes' => 2 * 9 + 6 if $@; - diag "Using Tie::Hash $Tie::Hash::VERSION" if defined $Tie::Hash::VERSION; + my $has_tie_hash = do { local $@; eval { require Tie::Hash; 1 } }; + skip 'Tie::Hash required to test copy magic on hashes' + => 2 * 9 + 6 unless $has_tie_hash; + defined and diag "Using Tie::Hash $_" for $Tie::Hash::VERSION; tie my %h, 'Tie::StdHash'; %h = (a => 1, b => 2, c => 3); @@ -65,7 +76,7 @@ SKIP: { watch { my ($k, $v) = each %h } { copy => 1 }, 'tied hash each'; my @k = watch { keys %h } { }, 'tied hash keys'; - is_deeply [ sort @k ], [ qw/a c/ ], 'copy: tied hash keys correctly'; + is_deeply [ sort @k ], [ qw ], 'copy: tied hash keys correctly'; my @v = watch { values %h } { copy => 2 }, 'tied hash values'; is_deeply [ sort { $a <=> $b } @v ], [ 1, 3 ], 'copy: tied hash values correctly';