X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FVariable-Temp.git;a=blobdiff_plain;f=t%2F13-magic.t;fp=t%2F13-magic.t;h=883088b8ceec702bb81bbefd6c2bcef5f33bc41b;hp=0000000000000000000000000000000000000000;hb=d69521b1f9cf9817ad62ff3f765a8e907c2d1fce;hpb=01ee034648a5f1116ca1233b7f987607f0b4576c 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;