summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/perl/t/op/array.t
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/usr.bin/perl/t/op/array.t')
-rw-r--r--gnu/usr.bin/perl/t/op/array.t29
1 files changed, 27 insertions, 2 deletions
diff --git a/gnu/usr.bin/perl/t/op/array.t b/gnu/usr.bin/perl/t/op/array.t
index 8f2f1a9510c..77ea646a93b 100644
--- a/gnu/usr.bin/perl/t/op/array.t
+++ b/gnu/usr.bin/perl/t/op/array.t
@@ -1,12 +1,11 @@
#!./perl
-
BEGIN {
chdir 't' if -d 't';
@INC = '../lib';
}
-print "1..73\n";
+print "1..82\n";
#
# @foo, @bar, and @ary are also used from tie-stdarray after tie-ing them
@@ -272,3 +271,29 @@ my $got = runperl (
$got =~ s/\n/ /g;
print "# $got\nnot " unless $got eq '';
print "ok 73\n";
+
+# Test negative and funky indices.
+
+{
+ my @a = 0..4;
+ print $a[-1] == 4 ? "ok 74\n" : "not ok 74\n";
+ print $a[-2] == 3 ? "ok 75\n" : "not ok 75\n";
+ print $a[-5] == 0 ? "ok 76\n" : "not ok 76\n";
+ print defined $a[-6] ? "not ok 77\n" : "ok 77\n";
+
+ print $a[2.1] == 2 ? "ok 78\n" : "not ok 78\n";
+ print $a[2.9] == 2 ? "ok 79\n" : "not ok 79\n";
+ print $a[undef] == 0 ? "ok 80\n" : "not ok 80\n";
+ print $a["3rd"] == 3 ? "ok 81\n" : "not ok 81\n";
+}
+
+sub kindalike { # TODO: test.pl-ize the array.t.
+ my ($s, $r, $m, $n) = @_;
+ print $s =~ /$r/ ? "ok $n - $m\n" : "not ok $n - $m ($s)\n";
+}
+
+{
+ my @a;
+ eval '$a[-1] = 0';
+ kindalike($@, qr/Modification of non-creatable array value attempted, subscript -1/, "\$a[-1] = 0", 82);
+}