From: Vincent Pit Date: Mon, 9 Mar 2015 15:36:20 +0000 (-0300) Subject: Test set/free magic X-Git-Tag: v0.02~18 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=d69521b1f9cf9817ad62ff3f765a8e907c2d1fce;p=perl%2Fmodules%2FVariable-Temp.git Test set/free magic --- diff --git a/MANIFEST b/MANIFEST index 5104b35..d6d63d8 100644 --- a/MANIFEST +++ b/MANIFEST @@ -10,4 +10,5 @@ t/01-import.t t/10-lexical.t t/11-global.t t/12-destroy.t +t/13-magic.t t/lib/VPIT/TestHelpers.pm diff --git a/t/13-magic.t b/t/13-magic.t new file mode 100644 index 0000000..883088b --- /dev/null +++ b/t/13-magic.t @@ -0,0 +1,48 @@ +#!perl + +use strict; +use warnings; + +use Variable::Temp 'temp'; + +use Test::More tests => 14; + +use lib 't/lib'; +use VPIT::TestHelpers; + +load_or_skip_all('Variable::Magic', '0.55', undef); + +my $replaced = 0; +my $freed = 0; + +my $wiz = Variable::Magic::wizard( + set => sub { ++$replaced; () }, + free => sub { ++$freed; () }, +); + +{ + my $y = 1; + &Variable::Magic::cast(\$y, $wiz); + is $y, 1; + is $replaced, 0; + is $freed, 0; + + { + temp $y = 2; + is $y, 2; + is $replaced, 1; + is $freed, 0; + + $y = 3; + is $y, 3; + is $replaced, 2; + is $freed, 0; + } + + is $y, 1; + is $replaced, 3; + is $freed, 0; +} + +is $replaced, 3; +is $freed, 1;