This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
opt.t: Test split-to-array optimisation
authorFather Chrysostomos <sprout@cpan.org>
Sun, 12 Oct 2014 13:58:11 +0000 (06:58 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 12 Oct 2014 17:48:21 +0000 (10:48 -0700)
t/op/opt.t

index 3090e35..c95272a 100644 (file)
@@ -9,7 +9,7 @@ BEGIN {
     @INC = '../lib';
 }
 
-plan 12;
+plan 17;
 
 use B qw 'svref_2object OPpASSIGN_COMMON';
 
@@ -50,3 +50,18 @@ for (['CONSTANT', sub {          join "foo", "bar"    }, 0, "bar"    ],
     is $last_expr->name, 'const', "$tn optimised to constant";
     is $sub->(), $expect, "$tn folded correctly";
 }
+
+
+# split to array
+
+for(['@pkgary'      , '@_'       ],
+    ['@lexary'      , 'my @a; @a'],
+    ['my(@array)'   , 'my(@a)'   ],
+    ['local(@array)', 'local(@_)'],
+    ['@{...}'       , '@{\@_}'   ],
+){
+    my($tn,$code) = @$_;
+    my $sub = eval "sub { $code = split }";
+    my $split = svref_2object($sub)->ROOT->first->last;
+    is $split->name, 'split', "$tn = split swallows up the assignment";
+}