More memory lane.
[p5sagit/p5-mst-13.2.git] / t / op / array.t
index 0fd6952..8f2f1a9 100755 (executable)
@@ -1,6 +1,16 @@
 #!./perl
 
-print "1..63\n";
+
+BEGIN {
+    chdir 't' if -d 't';
+    @INC = '../lib';
+}
+
+print "1..73\n";
+
+#
+# @foo, @bar, and @ary are also used from tie-stdarray after tie-ing them
+#
 
 @ary = (1,2,3,4,5);
 if (join('',@ary) eq '12345') {print "ok 1\n";} else {print "not ok 1\n";}
@@ -135,67 +145,130 @@ 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");
 t("@bar" eq "foo bar");                                                # 43
 
 # try the same with local
-@foo = ( 'foo', 'bar', 'burbl', 'blah');
+# XXX tie-stdarray fails the tests involving local, so we use
+# different variable names to escape the 'tie'
+
+@bee = ( 'foo', 'bar', 'burbl', 'blah');
 {
 
-    local @foo = @foo;
-    t("@foo" eq "foo bar burbl blah");                         # 44
+    local @bee = @bee;
+    t("@bee" eq "foo bar burbl blah");                         # 44
     {
-       local (undef,@foo) = @foo;
-       t("@foo" eq "bar burbl blah");                          # 45
+       local (undef,@bee) = @bee;
+       t("@bee" eq "bar burbl blah");                          # 45
        {
-           local @foo = ('XXX',@foo,'YYY');
-           t("@foo" eq "XXX bar burbl blah YYY");              # 46
+           local @bee = ('XXX',@bee,'YYY');
+           t("@bee" eq "XXX bar burbl blah YYY");              # 46
            {
-               local @foo = local(@foo) = qw(foo bar burbl blah);
-               t("@foo" eq "foo bar burbl blah");              # 47
+               local @bee = local(@bee) = qw(foo bar burbl blah);
+               t("@bee" eq "foo bar burbl blah");              # 47
                {
-                   local (@bar) = local(@foo) = qw(foo bar);
-                   t("@foo" eq "foo bar");                     # 48
-                   t("@bar" eq "foo bar");                     # 49
+                   local (@bim) = local(@bee) = qw(foo bar);
+                   t("@bee" eq "foo bar");                     # 48
+                   t("@bim" eq "foo bar");                     # 49
                }
-               t("@foo" eq "foo bar burbl blah");              # 50
+               t("@bee" eq "foo bar burbl blah");              # 50
            }
-           t("@foo" eq "XXX bar burbl blah YYY");              # 51
+           t("@bee" eq "XXX bar burbl blah YYY");              # 51
        }
-       t("@foo" eq "bar burbl blah");                          # 52
+       t("@bee" eq "bar burbl blah");                          # 52
     }
-    t("@foo" eq "foo bar burbl blah");                         # 53
+    t("@bee" eq "foo bar burbl blah");                         # 53
 }
 
 # try the same with my
 {
 
-    my @foo = @foo;
-    t("@foo" eq "foo bar burbl blah");                         # 54
+    my @bee = @bee;
+    t("@bee" eq "foo bar burbl blah");                         # 54
     {
-       my (undef,@foo) = @foo;
-       t("@foo" eq "bar burbl blah");                          # 55
+       my (undef,@bee) = @bee;
+       t("@bee" eq "bar burbl blah");                          # 55
        {
-           my @foo = ('XXX',@foo,'YYY');
-           t("@foo" eq "XXX bar burbl blah YYY");              # 56
+           my @bee = ('XXX',@bee,'YYY');
+           t("@bee" eq "XXX bar burbl blah YYY");              # 56
            {
-               my @foo = my @foo = qw(foo bar burbl blah);
-               t("@foo" eq "foo bar burbl blah");              # 57
+               my @bee = my @bee = qw(foo bar burbl blah);
+               t("@bee" eq "foo bar burbl blah");              # 57
                {
-                   my (@bar) = my(@foo) = qw(foo bar);
-                   t("@foo" eq "foo bar");                     # 58
-                   t("@bar" eq "foo bar");                     # 59
+                   my (@bim) = my(@bee) = qw(foo bar);
+                   t("@bee" eq "foo bar");                     # 58
+                   t("@bim" eq "foo bar");                     # 59
                }
-               t("@foo" eq "foo bar burbl blah");              # 60
+               t("@bee" eq "foo bar burbl blah");              # 60
            }
-           t("@foo" eq "XXX bar burbl blah YYY");              # 61
+           t("@bee" eq "XXX bar burbl blah YYY");              # 61
        }
-       t("@foo" eq "bar burbl blah");                          # 62
+       t("@bee" eq "bar burbl blah");                          # 62
     }
-    t("@foo" eq "foo bar burbl blah");                         # 63
+    t("@bee" eq "foo bar burbl blah");                         # 63
 }
 
+# make sure reification behaves
+my $t = 63;
+sub reify { $_[1] = ++$t; print "@_\n"; }
+reify('ok');
+reify('ok');
+
+# qw() is no more a runtime split, it's compiletime.
+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";