X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F28-uvar.t;h=8333ca042cd48d88ece4598dd3ad04279d090585;hb=c78c1790ebe43372ca405385d4cc053121b53ba0;hp=30d7f525e20b5d4e9651d88759d3148bd4067af4;hpb=1b88e230428d6cc4f3ff364fbcfd7f5c1a40fedc;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/t/28-uvar.t b/t/28-uvar.t index 30d7f52..8333ca0 100644 --- a/t/28-uvar.t +++ b/t/28-uvar.t @@ -23,41 +23,39 @@ my %h = (a => 1, b => 2, c => 3); my $res = check { cast %h, $wiz } { }, 'cast'; ok $res, 'uvar: cast succeeded'; -my $x; - -check { $x = $h{a} } { fetch => 1 }, 'fetch directly'; +my $x = check { $h{a} } { fetch => 1 }, 'fetch directly'; is $x, 1, 'uvar: fetch directly correctly'; -check { $x = "$h{b}" } { fetch => 1 }, 'fetch by interpolation'; +$x = check { "$h{b}" } { fetch => 1 }, 'fetch by interpolation'; is $x, 2, 'uvar: fetch by interpolation correctly'; check { $h{c} = 4 } { store => 1 }, 'store directly'; -check { $x = $h{c} = 5 } { store => 1 }, 'fetch and store'; +$x = check { $h{c} = 5 } { store => 1 }, 'fetch and store'; is $x, 5, 'uvar: fetch and store correctly'; -check { $x = exists $h{c} } { exists => 1 }, 'exists'; +$x = check { exists $h{c} } { exists => 1 }, 'exists'; ok $x, 'uvar: exists correctly'; -check { $x = delete $h{c} } { delete => 1 }, 'delete existing key'; +$x = check { delete $h{c} } { delete => 1 }, 'delete existing key'; is $x, 5, 'uvar: delete existing key correctly'; -check { $x = delete $h{z} } { delete => 1 }, 'delete non-existing key'; +$x = check { delete $h{z} } { delete => 1 }, 'delete non-existing key'; ok !defined $x, 'uvar: delete non-existing key correctly'; my $wiz2 = wizard get => sub { 0 }; cast %h, $wiz2; -check { $x = $h{a} } { fetch => 1 }, 'fetch directly with also non uvar magic'; +$x = check { $h{a} } { fetch => 1 }, 'fetch directly with also non uvar magic'; is $x, 1, 'uvar: fetch directly with also non uvar magic correctly'; $wiz2 = wizard fetch => sub { 0 }; my %h2 = (a => 37, b => 2, c => 3); cast %h2, $wiz2; -eval { +$x = eval { local $SIG{__WARN__} = sub { die }; - $x = $h2{a}; + $h2{a}; }; is $@, '', 'uvar: fetch with incomplete magic doesn\'t croak'; is $x, 37, 'uvar: fetch with incomplete magic correctly';