Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added test for for. Found an off-by-one bug, fixed it

  • Loading branch information...
commit 06d4a2755b51e7a000829b55facedff5b25f5f53 1 parent de990db
@brunoV brunoV authored
Showing with 13 additions and 1 deletion.
  1. +1 −1  Core.pm
  2. +12 −0 t/for.t
View
2  Core.pm
@@ -1110,7 +1110,7 @@ sub foreach {
sub for {
my $arr = CORE::shift; my $sub = CORE::shift;
- for(my $i = 0; $i < $#$arr; $i++) {
+ for(my $i = 0; $i <= $#$arr; $i++) {
$sub->($i, $arr->[$i], $arr);
}
}
View
12 t/for.t
@@ -0,0 +1,12 @@
+use Test::More qw(no_plan);
+use strict;
+use warnings;
+
+use autobox::Core;
+
+my @array = qw(1 2 3);
+
+my @added;
+@array->for( sub { my ($i, $v, $arr) = @_; push @added, $i + $v + @$arr } );
+
+is_deeply [ @added ], [ qw(4 6 8) ];
Please sign in to comment.
Something went wrong with that request. Please try again.