]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - t/32-hash.t
Update magical flags after dispelling magic
[perl/modules/Variable-Magic.git] / t / 32-hash.t
index e12b810a4ee39e625355561a0dfa168a77f16ee6..0ad2e96413adb937e21f6d1d6bb8acb3b7f44c4c 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 2 * 21 + 7 + 1;
+use Test::More tests => (2 * 21 + 7) + (2 * 5 + 5) + 1;
 
 use Variable::Magic qw/cast dispell MGf_COPY VMG_UVAR/;
 
@@ -72,3 +72,46 @@ watch {
 watch { undef %h } { clear => 1 }, 'undef';
 
 watch { dispell %h, $wiz } { }, 'dispell';
+
+SKIP: {
+ my $SKIP;
+
+ unless (VMG_UVAR) {
+  $SKIP = 'uvar magic';
+ } else {
+  eval "use B::Deparse";
+  $SKIP = 'B::Deparse' if $@;
+ }
+ if ($SKIP) {
+  $SKIP .= ' required to test uvar/clear interaction fix';
+  skip $SKIP => 2 * 5 + 5;
+ }
+
+ my $bd = B::Deparse->new;
+
+ my %h = (a => 13, b => 15);
+ watch { cast %h, $wiz } { }, 'cast clear/uvar';
+
+ my $code   = sub { my $x = $h{$_[0]}; ++$x; $x };
+ my $before = $bd->coderef2text($code);
+ my $res;
+
+ watch { $res = $code->('a') } { fetch => 1 }, 'fixed fetch "a"';
+ is $res, 14, 'uvar: fixed fetch "a" returned the right thing';
+
+ my $after = $bd->coderef2text($code);
+ is $before, $after, 'uvar: fixed fetch deparse correctly';
+
+ watch { $res = $code->('b') } { fetch => 1 }, 'fixed fetch "b"';
+ is $res, 16, 'uvar: fixed fetch "b" returned the right thing';
+
+ $after = $bd->coderef2text($code);
+ is $before, $after, 'uvar: fixed fetch deparse correctly';
+
+ watch { %h = () } { clear => 1 }, 'fixed clear';
+
+ watch { dispell %h, $wiz } { }, 'dispell clear/uvar';
+
+ require B;
+ ok(!(B::svref_2object(\%h)->FLAGS & B::SVs_RMG()), '%h no longer has the RMG flag set');
+}