use strict;
use warnings;
-use Test::More tests => 2 * 21 + 7 + 1;
+use Test::More tests => (2 * 21 + 7) + (2 * 5 + 4) + 1;
use Variable::Magic qw/cast dispell MGf_COPY VMG_UVAR/;
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 + 4;
+ }
+
+ 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';
+}