X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fop%2Farray.t;h=77ea646a93b9022f5064a831e63cc14b2a19c06c;hb=3ab3c9b49fb213f2b1d4cda8797de17be82b2b15;hp=1108f494f84449a69c49dc33e5004b3465b43642;hpb=1d7c184104c076988718a01b77c8706aae05b092;p=p5sagit%2Fp5-mst-13.2.git diff --git a/t/op/array.t b/t/op/array.t index 1108f49..77ea646 100755 --- a/t/op/array.t +++ b/t/op/array.t @@ -1,6 +1,11 @@ #!./perl -print "1..66\n"; +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; +} + +print "1..82\n"; # # @foo, @bar, and @ary are also used from tie-stdarray after tie-ing them @@ -139,8 +144,8 @@ t("@foo" eq "bar burbl blah"); # 39 @foo = ('XXX',@foo, 'YYY'); t("@foo" eq "XXX bar burbl blah YYY"); # 40 -@foo = @foo = qw(foo bar burbl blah); -t("@foo" eq "foo bar burbl blah"); # 41 +@foo = @foo = qw(foo b\a\r bu\\rbl blah); +t("@foo" eq 'foo b\a\r bu\\rbl blah'); # 41 @bar = @foo = qw(foo bar); # 42 t("@foo" eq "foo bar"); @@ -216,3 +221,79 @@ reify('ok'); print "not " unless qw(foo bar snorfle)[2] eq 'snorfle'; print "ok 66\n"; +@ary = (12,23,34,45,56); + +print "not " unless shift(@ary) == 12; +print "ok 67\n"; + +print "not " unless pop(@ary) == 56; +print "ok 68\n"; + +print "not " unless push(@ary,56) == 4; +print "ok 69\n"; + +print "not " unless unshift(@ary,12) == 5; +print "ok 70\n"; + +sub foo { "a" } +@foo=(foo())[0,0]; +$foo[1] eq "a" or print "not "; +print "ok 71\n"; + +# $[ should have the same effect regardless of whether the aelem +# op is optimized to aelemfast. + +sub tary { + local $[ = 10; + my $five = 5; + print "not " unless $tary[5] == $tary[$five]; + print "ok 72\n"; +} + +@tary = (0..50); +tary(); + + +require './test.pl'; + +# bugid #15439 - clearing an array calls destructors which may try +# to modify the array - caused 'Attempt to free unreferenced scalar' + +my $got = runperl ( + prog => q{ + sub X::DESTROY { @a = () } + @a = (bless {}, 'X'); + @a = (); + }, + stderr => 1 + ); + +$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); +}