diff options
author | Mark-Jason Dominus <mjd@plover.com> | 2002-04-14 19:38:55 -0400 |
---|---|---|
committer | hv <hv@crypt.org> | 2002-08-17 01:20:05 +0000 |
commit | 6f12eb6d2a1dfaf441504d869b27d2e40ef4966a (patch) | |
tree | 33a62e71b7b14eaed1eb3674c22f3056c892a6f8 /t/op/tiearray.t | |
parent | af288a606d0d98092d972aa99e1ea87fbb35d29e (diff) | |
download | perl-6f12eb6d2a1dfaf441504d869b27d2e40ef4966a.tar.gz |
Negative subscripts optionally passed to tied array methods
Message-id: <20020415033855.6343.qmail@plover.com>
p4raw-id: //depot/perl@17727
Diffstat (limited to 't/op/tiearray.t')
-rwxr-xr-x | t/op/tiearray.t | 89 |
1 files changed, 86 insertions, 3 deletions
diff --git a/t/op/tiearray.t b/t/op/tiearray.t index 337aff689a..e7b547bcd9 100755 --- a/t/op/tiearray.t +++ b/t/op/tiearray.t @@ -99,9 +99,44 @@ sub SPLICE return splice(@$ob,$off,$len,@_); } -package main; +package NegIndex; # 20020220 MJD +@ISA = 'Implement'; + +# simulate indices -2 .. 2 +my $offset = 2; +$NegIndex::NEGATIVE_INDICES = 1; + +sub FETCH { + my ($ob,$id) = @_; +# print "# FETCH @_\n"; + $id += $offset; + $ob->[$id]; +} + +sub STORE { + my ($ob,$id,$value) = @_; +# print "# STORE @_\n"; + $id += $offset; + $ob->[$id] = $value; +} + +sub DELETE { + my ($ob,$id) = @_; +# print "# DELETE @_\n"; + $id += $offset; + delete $ob->[$id]; +} + +sub EXISTS { + my ($ob,$id) = @_; +# print "# EXISTS @_\n"; + $id += $offset; + exists $ob->[$id]; +} -print "1..36\n"; +package main; + +print "1..61\n"; my $test = 1; {my @ary; @@ -240,7 +275,55 @@ untie @ary; # If we survived this far. print "ok ", $test++, "\n"; } + + +{ # 20020220 mjd-perl-patch+@plover.com + my @n; + tie @n => 'NegIndex', ('A' .. 'E'); + + # FETCH + print "not " unless $n[0] eq 'C'; + print "ok ", $test++,"\n"; + print "not " unless $n[1] eq 'D'; + print "ok ", $test++,"\n"; + print "not " unless $n[2] eq 'E'; + print "ok ", $test++,"\n"; + print "not " unless $n[-1] eq 'B'; + print "ok ", $test++,"\n"; + print "not " unless $n[-2] eq 'A'; + print "ok ", $test++,"\n"; + + # STORE + $n[-2] = 'a'; + print "not " unless $n[-2] eq 'a'; + print "ok ", $test++,"\n"; + $n[-1] = 'b'; + print "not " unless $n[-1] eq 'b'; + print "ok ", $test++,"\n"; + $n[0] = 'c'; + print "not " unless $n[0] eq 'c'; + print "ok ", $test++,"\n"; + $n[1] = 'd'; + print "not " unless $n[1] eq 'd'; + print "ok ", $test++,"\n"; + $n[2] = 'e'; + print "not " unless $n[2] eq 'e'; + print "ok ", $test++,"\n"; + + # DELETE and EXISTS + for (-2 .. 2) { + print exists($n[$_]) ? "ok $test\n" : "not ok $test\n"; + $test++; + delete $n[$_]; + print defined($n[$_]) ? "not ok $test\n" : "ok $test\n"; + $test++; + print exists($n[$_]) ? "not ok $test\n" : "ok $test\n"; + $test++; + } +} + + -print "not " unless $seen{'DESTROY'} == 2; +print "not " unless $seen{'DESTROY'} == 3; print "ok ", $test++,"\n"; |