diff options
author | Nicholas Clark <nick@ccl4.org> | 2007-12-20 21:15:57 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2007-12-20 21:15:57 +0000 |
commit | 878d132a73f5d089e821fedd49aa4835a2786d1d (patch) | |
tree | 5f489d4e731a9809ef0261bfb731eee600f3911a /t/op/each_array.t | |
parent | 3bdcbd26ea8ce137a02a61d6364dbbb1afb63c19 (diff) | |
download | perl-878d132a73f5d089e821fedd49aa4835a2786d1d.tar.gz |
Implement each @array.
Documentation needed, FIXME for proper 64 bit support of arrays longer
than 2**32, re-order the new ops at the end if merging to 5.10.x.
p4raw-id: //depot/perl@32680
Diffstat (limited to 't/op/each_array.t')
-rw-r--r-- | t/op/each_array.t | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/t/op/each_array.t b/t/op/each_array.t new file mode 100644 index 0000000000..b0665e1a07 --- /dev/null +++ b/t/op/each_array.t @@ -0,0 +1,132 @@ +#!./perl -w + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; + require './test.pl'; +} +use strict; +use vars qw(@array @r $k $v); + +plan tests => 48; + +@array = qw(crunch zam bloop); + +(@r) = each @array; +is (scalar @r, 2); +is ($r[0], 0); +is ($r[1], 'crunch'); +($k, $v) = each @array; +is ($k, 1); +is ($v, 'zam'); +($k, $v) = each @array; +is ($k, 2); +is ($v, 'bloop'); +(@r) = each @array; +is (scalar @r, 0); + +(@r) = each @array; +is (scalar @r, 2); +is ($r[0], 0); +is ($r[1], 'crunch'); +($k) = each @array; +is ($k, 1); +{ + $[ = 2; + my ($k, $v) = each @array; + is ($k, 4); + is ($v, 'bloop'); + (@r) = each @array; + is (scalar @r, 0); +} + +my @lex_array = qw(PLOP SKLIZZORCH RATTLE PBLRBLPSFT); + +(@r) = each @lex_array; +is (scalar @r, 2); +is ($r[0], 0); +is ($r[1], 'PLOP'); +($k, $v) = each @lex_array; +is ($k, 1); +is ($v, 'SKLIZZORCH'); +($k) = each @lex_array; +is ($k, 2); +{ + $[ = -42; + my ($k, $v) = each @lex_array; + is ($k, -39); + is ($v, 'PBLRBLPSFT'); +} +(@r) = each @lex_array; +is (scalar @r, 0); + +my $ar = ['bacon']; + +(@r) = each @$ar; +is (scalar @r, 2); +is ($r[0], 0); +is ($r[1], 'bacon'); + +(@r) = each @$ar; +is (scalar @r, 0); + +is (each @$ar, 0); +is (scalar each @$ar, undef); + +my @keys; +@keys = keys @array; +is ("@keys", "0 1 2"); + +@keys = keys @lex_array; +is ("@keys", "0 1 2 3"); + +{ + $[ = 1; + + @keys = keys @array; + is ("@keys", "1 2 3"); + + @keys = keys @lex_array; + is ("@keys", "1 2 3 4"); +} + +($k, $v) = each @array; +is ($k, 0); +is ($v, 'crunch'); + +@keys = keys @array; +is ("@keys", "0 1 2"); + +($k, $v) = each @array; +is ($k, 0); +is ($v, 'crunch'); + + + +my @values; +@values = values @array; +is ("@values", "@array"); + +@values = values @lex_array; +is ("@values", "@lex_array"); + +{ + $[ = 1; + + @values = values @array; + is ("@values", "@array"); + + @values = values @lex_array; + is ("@values", "@lex_array"); +} + +($k, $v) = each @array; +is ($k, 0); +is ($v, 'crunch'); + +@values = values @array; +is ("@values", "@array"); + +($k, $v) = each @array; +is ($k, 0); +is ($v, 'crunch'); |