]> git.vpit.fr Git - perl/modules/Variable-Temp.git/blobdiff - t/20-lvalue.t
Test temp() in t/20-lvalue.t
[perl/modules/Variable-Temp.git] / t / 20-lvalue.t
diff --git a/t/20-lvalue.t b/t/20-lvalue.t
new file mode 100644 (file)
index 0000000..90da2a9
--- /dev/null
@@ -0,0 +1,67 @@
+#!perl -T
+
+use strict;
+use warnings;
+
+use Variable::Temp 'temp';
+
+use Test::More;
+
+BEGIN {
+ if ("$]" >= 5.014) {
+  plan tests => 7 + 13;
+ } else {
+  plan skip_all => 'perl 5.14 required to lvalue assignment with prototype \[$@%]';
+ }
+}
+
+my $x = 1;
+is $x, 1;
+{
+ temp $x = 2;
+ is $x, 2;
+ $x = 3;
+ is $x, 3;
+ {
+  temp $x = 4;
+  is $x, 4;
+  temp $x = 5;
+  is $x, 5;
+ }
+ is $x, 3;
+}
+is $x, 1;
+
+our $y = 1;
+is $y, 1;
+{
+ temp $y = 2;
+ is $y, 2;
+ $y = 3;
+ is $y, 3;
+ {
+  temp $y = 4;
+  is $y, 4;
+  temp $y = 5;
+  is $y, 5;
+ }
+ is $y, 3;
+ {
+  local $y = 6;
+  is $y, 6;
+ }
+ is $y, 3;
+ {
+  local $y = 7;
+  temp $y = 8;
+  is $y, 8;
+ }
+ is $y, 3;
+ {
+  temp $y = 9;
+  local $y = 10;
+  is $y, 10;
+ }
+ is $y, 3;
+}
+is $y, 1;