]> git.vpit.fr Git - perl/modules/Variable-Temp.git/blobdiff - t/13-magic.t
Test set/free magic
[perl/modules/Variable-Temp.git] / t / 13-magic.t
diff --git a/t/13-magic.t b/t/13-magic.t
new file mode 100644 (file)
index 0000000..883088b
--- /dev/null
@@ -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;