This is a live mirror of the Perl 5 development currently hosted at
https://github.com/perl/perl5
https://perl5.git.perl.org
/
perl5.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
7245301
)
t/op/each_array.t: Provide descriptions for all tests.
author
James E Keenan
<jkeenan@cpan.org>
Sun, 9 Dec 2012 03:18:03 +0000
(22:18 -0500)
committer
James E Keenan
<jkeenan@cpan.org>
Sat, 15 Dec 2012 01:50:17 +0000
(20:50 -0500)
t/op/each_array.t
patch
|
blob
|
blame
|
history
diff --git
a/t/op/each_array.t
b/t/op/each_array.t
index
0c1e080
..
1055d6c
100644
(file)
--- a/
t/op/each_array.t
+++ b/
t/op/each_array.t
@@
-14,89
+14,102
@@
plan tests => 63;
@array = qw(crunch zam bloop);
(@r) = each @array;
@array = qw(crunch zam bloop);
(@r) = each @array;
-is (scalar @r, 2);
-is ($r[0], 0);
-is ($r[1], 'crunch');
+is (scalar @r, 2
, "'each' on array returns index and value of next element"
);
+is ($r[0], 0
, "got expected index"
);
+is ($r[1], 'crunch'
, "got expected value"
);
($k, $v) = each @array;
($k, $v) = each @array;
-is ($k, 1);
-is ($v, 'zam');
+is ($k, 1
, "got expected index of next element"
);
+is ($v, 'zam'
, "got expected value of next element"
);
($k, $v) = each @array;
($k, $v) = each @array;
-is ($k, 2);
-is ($v, 'bloop');
+is ($k, 2
, "got expected index of remaining element"
);
+is ($v, 'bloop'
, "got expected value of remaining element"
);
(@r) = each @array;
(@r) = each @array;
-is (scalar @r, 0);
+is (scalar @r, 0,
+ "no elements remaining to be iterated over in original array");
(@r) = each @array;
(@r) = each @array;
-is (scalar @r, 2);
-is ($r[0], 0);
-is ($r[1], 'crunch');
+is (scalar @r, 2
, "start second iteration over original array"
);
+is ($r[0], 0
, "got expected index"
);
+is ($r[1], 'crunch'
, "got expected value"
);
($k) = each @array;
($k) = each @array;
-is ($k, 1);
+is ($k, 1
, "got index when only index was assigned to variable"
);
my @lex_array = qw(PLOP SKLIZZORCH RATTLE);
(@r) = each @lex_array;
my @lex_array = qw(PLOP SKLIZZORCH RATTLE);
(@r) = each @lex_array;
-is (scalar @r, 2);
-is ($r[0], 0);
-is ($r[1], 'PLOP');
+is (scalar @r, 2
, "'each' on array returns index and value of next element"
);
+is ($r[0], 0
, "got expected index"
);
+is ($r[1], 'PLOP'
, "got expected value"
);
($k, $v) = each @lex_array;
($k, $v) = each @lex_array;
-is ($k, 1);
-is ($v, 'SKLIZZORCH');
+is ($k, 1
, "got expected index of next element"
);
+is ($v, 'SKLIZZORCH'
, "got expected value of next element"
);
($k) = each @lex_array;
($k) = each @lex_array;
-is ($k, 2);
+is ($k, 2
, "got expected index of remaining element"
);
(@r) = each @lex_array;
(@r) = each @lex_array;
-is (scalar @r, 0);
+is (scalar @r, 0,
+ "no elements remaining to be iterated over in original array");
my $ar = ['bacon'];
(@r) = each @$ar;
my $ar = ['bacon'];
(@r) = each @$ar;
-is (scalar @r, 2);
-is ($r[0], 0);
-is ($r[1], 'bacon');
+is (scalar @r, 2,
+ "'each' on array inside reference returns index and value of next element");
+is ($r[0], 0, "got expected index");
+is ($r[1], 'bacon', "got expected value of array element inside reference");
(@r) = each @$ar;
(@r) = each @$ar;
-is (scalar @r, 0);
+is (scalar @r, 0,
+ "no elements remaining to be iterated over in array inside reference");
-is (each @$ar, 0);
-is (scalar each @$ar, undef);
+is (each @$ar, 0, "scalar context 'each' on array returns expected index");
+is (scalar each @$ar, undef,
+ "no elements remaining to be iterated over; array reference case");
my @keys;
@keys = keys @array;
my @keys;
@keys = keys @array;
-is ("@keys", "0 1 2");
+is ("@keys", "0 1 2",
+ "'keys' on array in list context returns list of indices");
@keys = keys @lex_array;
@keys = keys @lex_array;
-is ("@keys", "0 1 2");
+is ("@keys", "0 1 2",
+ "'keys' on another array in list context returns list of indices");
($k, $v) = each @array;
($k, $v) = each @array;
-is ($k, 0);
-is ($v, 'crunch');
+is ($k, 0
, "got expected index"
);
+is ($v, 'crunch'
, "got expected value"
);
@keys = keys @array;
@keys = keys @array;
-is ("@keys", "0 1 2");
+is ("@keys", "0 1 2",
+ "'keys' on array in list context returns list of indices");
($k, $v) = each @array;
($k, $v) = each @array;
-is ($k, 0);
-is ($v, 'crunch');
+is ($k, 0
, "following 'keys', got expected index"
);
+is ($v, 'crunch'
, "following 'keys', got expected value"
);
my @values;
@values = values @array;
my @values;
@values = values @array;
-is ("@values", "@array");
+is ("@values", "@array",
+ "'values' on array returns list of values");
@values = values @lex_array;
@values = values @lex_array;
-is ("@values", "@lex_array");
+is ("@values", "@lex_array",
+ "'values' on another array returns list of values");
($k, $v) = each @array;
($k, $v) = each @array;
-is ($k, 0);
-is ($v, 'crunch');
+is ($k, 0
, "following 'values', got expected index"
);
+is ($v, 'crunch'
, "following 'values', got expected index"
);
@values = values @array;
@values = values @array;
-is ("@values", "@array");
+is ("@values", "@array",
+ "following 'values' and 'each', 'values' continues to return expected list of values");
($k, $v) = each @array;
($k, $v) = each @array;
-is ($k, 0);
-is ($v, 'crunch');
+is ($k, 0,
+ "following 'values', 'each' and 'values', 'each' continues to return expected index");
+is ($v, 'crunch',
+ "following 'values', 'each' and 'values', 'each' continues to return expected value");
# reset
while (each @array) { }
# reset
while (each @array) { }
@@
-104,8
+117,9
@@
while (each @array) { }
# each(ARRAY) in the conditional loop
$c = 0;
while (($k, $v) = each @array) {
# each(ARRAY) in the conditional loop
$c = 0;
while (($k, $v) = each @array) {
- is ($k, $c);
- is ($v, $array[$k]);
+ is ($k, $c, "'each' on array in loop returns expected index '$c'");
+ is ($v, $array[$k],
+ "'each' on array in loop returns expected value '$array[$k]'");
$c++;
}
$c++;
}
@@
-116,15
+130,18
@@
$c = 0;
$k = 0;
$v = 0;
while ($k = each @array) {
$k = 0;
$v = 0;
while ($k = each @array) {
- is ($k, $v);
+ is ($k, $v,
+ "'each' on array in scalar context in loop returns expected index '$v'");
$v++;
}
# each(ARRAY) in the conditional loop
$c = 0;
for (; ($k, $v) = each @array ;) {
$v++;
}
# each(ARRAY) in the conditional loop
$c = 0;
for (; ($k, $v) = each @array ;) {
- is ($k, $c);
- is ($v, $array[$k]);
+ is ($k, $c,
+ "'each' on array in list context in loop returns expected index '$c'");
+ is ($v, $array[$k],
+ "'each' on array in list context in loop returns expected value '$array[$k]'");
$c++;
}
$c++;
}
@@
-134,7
+151,8
@@
$c = 0;
$k = 0;
$v = 0;
for (; $k = each(@array) ;) {
$k = 0;
$v = 0;
for (; $k = each(@array) ;) {
- is ($k, $v);
+ is ($k, $v,
+ "'each' on array in scalar context in loop returns expected index '$v'");
$v++;
}
$v++;
}
@@
-142,26
+160,30
@@
for (; $k = each(@array) ;) {
{
my @a = 'a' .. 'c';
my ($i, $v) = each @a;
{
my @a = 'a' .. 'c';
my ($i, $v) = each @a;
- is ("$i-$v", '0-a');
+ is ("$i-$v", '0-a'
, "got expected index and value"
);
@a = 'A' .. 'C';
($i, $v) = each @a;
@a = 'A' .. 'C';
($i, $v) = each @a;
- is ("$i-$v", '0-A');
+ is ("$i-$v", '0-A',
+ "got expected new index and value after array gets new content");
}
# Check that the iterator is reset when localization ends
{
@array = 'a' .. 'c';
my ($i, $v) = each @array;
}
# Check that the iterator is reset when localization ends
{
@array = 'a' .. 'c';
my ($i, $v) = each @array;
- is ("$i-$v", '0-a');
+ is ("$i-$v", '0-a'
, "got expected index and value"
);
{
local @array = 'A' .. 'C';
my ($i, $v) = each @array;
{
local @array = 'A' .. 'C';
my ($i, $v) = each @array;
- is ("$i-$v", '0-A');
+ is ("$i-$v", '0-A',
+ "got expected new index and value after array is localized and gets new content");
($i, $v) = each @array;
($i, $v) = each @array;
- is ("$i-$v", '1-B');
+ is ("$i-$v", '1-B',
+ "got expected next index and value after array is localized and gets new content");
}
($i, $v) = each @array;
}
($i, $v) = each @array;
- is ("$i-$v", '1-b');
+ is ("$i-$v", '1-b',
+ "got expected next index and value upon return to pre-localized array");
# Explicit reset
while (each @array) { }
}
# Explicit reset
while (each @array) { }
}