# grep() and map() tests
#
-print "1..3\n";
+print "1..32\n";
$test = 1;
$test++;
}
+{
+ print map({$_} ("ok $test\n"));
+ $test++;
+ print map
+ ({$_} ("ok $test\n"));
+ $test++;
+ print((map({a => $_}, ("ok $test\n")))[0]->{a});
+ $test++;
+ print((map
+ ({a=>$_},
+ ("ok $test\n")))[0]->{a});
+ $test++;
+ print map { $_ } ("ok $test\n");
+ $test++;
+ print map
+ { $_ } ("ok $test\n");
+ $test++;
+ print((map {a => $_}, ("ok $test\n"))[0]->{a});
+ $test++;
+ print((map
+ {a=>$_},
+ ("ok $test\n"))[0]->{a});
+ $test++;
+ my $x = "ok \xFF\xFF\n";
+ print map($_&$x,("ok $test\n"));
+ $test++;
+ print map
+ ($_ & $x, ("ok $test\n"));
+ $test++;
+ print map { $_ & $x } ("ok $test\n");
+ $test++;
+ print map
+ { $_&$x } ("ok $test\n");
+ $test++;
+
+ print grep({$_} ("ok $test\n"));
+ $test++;
+ print grep
+ ({$_} ("ok $test\n"));
+ $test++;
+ print grep({a => $_}->{a}, ("ok $test\n"));
+ $test++;
+ print grep
+ ({a => $_}->{a},
+ ("ok $test\n"));
+ $test++;
+ print grep { $_ } ("ok $test\n");
+ $test++;
+ print grep
+ { $_ } ("ok $test\n");
+ $test++;
+ print grep {a => $_}->{a}, ("ok $test\n");
+ $test++;
+ print grep
+ {a => $_}->{a},
+ ("ok $test\n");
+ $test++;
+ print grep($_&"X",("ok $test\n"));
+ $test++;
+ print grep
+ ($_&"X", ("ok $test\n"));
+ $test++;
+ print grep { $_ & "X" } ("ok $test\n");
+ $test++;
+ print grep
+ { $_ & "X" } ("ok $test\n");
+ $test++;
+}
+
+# Tests for "for" in "map" and "grep"
+# Used to dump core, bug [perl #17771]
+
+{
+ my @x;
+ my $y = '';
+ @x = map { $y .= $_ for 1..2; 1 } 3..4;
+ print "# @x,$y\n";
+ print "@x,$y" eq "1 1,1212" ? "ok $test\n" : "not ok $test\n";
+ $test++;
+ $y = '';
+ @x = map { $y .= $_ for 1..2; $y .= $_ } 3..4;
+ print "# @x,$y\n";
+ print "@x,$y" eq "123 123124,123124" ? "ok $test\n" : "not ok $test\n";
+ $test++;
+ $y = '';
+ @x = map { for (1..2) { $y .= $_ } $y .= $_ } 3..4;
+ print "# @x,$y\n";
+ print "@x,$y" eq "123 123124,123124" ? "ok $test\n" : "not ok $test\n";
+ $test++;
+ $y = '';
+ @x = grep { $y .= $_ for 1..2; 1 } 3..4;
+ print "# @x,$y\n";
+ print "@x,$y" eq "3 4,1212" ? "ok $test\n" : "not ok $test\n";
+ $test++;
+ $y = '';
+ @x = grep { for (1..2) { $y .= $_ } 1 } 3..4;
+ print "# @x,$y\n";
+ print "@x,$y" eq "3 4,1212" ? "ok $test\n" : "not ok $test\n";
+ $test++;
+}