summaryrefslogtreecommitdiff
path: root/t/op/closure.t
diff options
context:
space:
mode:
Diffstat (limited to 't/op/closure.t')
-rwxr-xr-xt/op/closure.t30
1 files changed, 29 insertions, 1 deletions
diff --git a/t/op/closure.t b/t/op/closure.t
index 1220998b6b..95d44f51e3 100755
--- a/t/op/closure.t
+++ b/t/op/closure.t
@@ -12,7 +12,7 @@ BEGIN {
use Config;
-print "1..167\n";
+print "1..169\n";
my $test = 1;
sub test (&) {
@@ -130,6 +130,33 @@ test {
&{$foo[4]}() == 0
};
+# test if closures get created in optimized for loops
+
+my %foo;
+for my $n ('A'..'E') {
+ $foo{$n} = sub { $n eq $_[0] };
+}
+
+test {
+ &{$foo{A}}('A') and
+ &{$foo{B}}('B') and
+ &{$foo{C}}('C') and
+ &{$foo{D}}('D') and
+ &{$foo{E}}('E')
+};
+
+for my $n (0..4) {
+ $foo[$n] = sub { $n == $_[0] };
+}
+
+test {
+ &{$foo[0]}(0) and
+ &{$foo[1]}(1) and
+ &{$foo[2]}(2) and
+ &{$foo[3]}(3) and
+ &{$foo[4]}(4)
+};
+
# Additional tests by Tom Phoenix <rootbeer@teleport.com>.
{
@@ -452,3 +479,4 @@ END
} # End of foreach $inner_type
}
+